|
27 | 27 | <script type="text/javascript" src="./js/ThreeApplication.js"></script> |
28 | 28 | <script> |
29 | 29 |
|
30 | | - mapboxgl.accessToken = 'pk.eyJ1IjoibW9ua2VyIiwiYSI6ImNpd2Z6aTE5YTAwdHEyb2tpOWs2ZzRydmoifQ.LwQMRArUP8Q9P7QApuOIHg'; |
| 30 | + |
| 31 | + var attribution = "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" + |
| 32 | + "| Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> " + |
| 33 | + " with <span>© <a href='http://iclient.supermap.io' target='_blank'>SuperMap iClient</a></span>"; |
| 34 | + |
| 35 | + var host = window.isLocal ? window.server : "http://support.supermap.com.cn:8090", |
| 36 | + url = host + "/iserver/services/map-china400/rest/maps/ChinaDark"; |
31 | 37 |
|
32 | 38 | var map, threeLayer; |
33 | 39 |
|
34 | 40 | map = new mapboxgl.Map({ |
35 | 41 | container: 'map', |
36 | | - style: 'mapbox://styles/mapbox/streets-v9', |
37 | | - center: [104.0712824591451, 30.560567575197524], |
38 | | - zoom: 17.42, |
| 42 | + style: { |
| 43 | + "version": 8, |
| 44 | + "sources": { |
| 45 | + "raster-tiles": { |
| 46 | + "attribution": attribution, |
| 47 | + "type": "raster", |
| 48 | + "tiles": [url + '/zxyTileImage.png?z={z}&x={x}&y={y}'], |
| 49 | + "tileSize": 256, |
| 50 | + }, |
| 51 | + }, |
| 52 | + "layers": [{ |
| 53 | + "id": "simple-tiles", |
| 54 | + "type": "raster", |
| 55 | + "source": "raster-tiles", |
| 56 | + "minzoom": 0, |
| 57 | + "maxzoom": 22 |
| 58 | + }] |
| 59 | + }, |
| 60 | + center: [104.07099170795755, 30.560115990796447], |
| 61 | + zoom: 19.54, |
39 | 62 | pitch: 60, |
40 | | - bearing: 28 |
| 63 | + bearing: 36 |
41 | 64 | }); |
42 | 65 |
|
43 | 66 | addThreeLayer(); |
|
47 | 70 | //gl参数表示使用webgl渲染,forceRefresh强制不断刷新three的场景 |
48 | 71 | threeLayer = new mapboxgl.supermap.ThreeLayer('three'); |
49 | 72 | threeLayer.on("initialized", render); |
| 73 | + threeLayer.addTo(map); |
50 | 74 |
|
51 | 75 | function render() { |
52 | 76 | var renderer = threeLayer.getThreeRenderer(), |
53 | 77 | scene = threeLayer.getScene(), |
54 | 78 | camera = threeLayer.getCamera(); |
55 | 79 |
|
56 | | - this.light = new THREE.PointLight(0xeeeeee, 0.8); |
| 80 | + this.light = new THREE.PointLight(0xffffff, 0.8); |
57 | 81 | this.light.position.copy(camera.position); |
58 | 82 | scene.add(this.light); |
59 | | - scene.add(new THREE.AmbientLight(0x333333)); |
60 | | - |
| 83 | + scene.add(new THREE.AmbientLight(0x04589e)); |
| 84 | + var directionalLight = new THREE.DirectionalLight(0xffffff, 1); |
| 85 | + directionalLight.position.set(0, 0, 0); |
| 86 | + scene.add(directionalLight); |
61 | 87 | ThreeApplication |
62 | 88 | .register(renderer, scene, camera) |
63 | 89 | .setTargetLayer(threeLayer) |
|
67 | 93 |
|
68 | 94 | //均匀光照,与相机位置同步 |
69 | 95 | threeLayer.on("render", function () { |
70 | | - threeLayer.light.position.copy(threeLayer.renderer.camera.position); |
| 96 | + // threeLayer.light.position.copy(threeLayer.renderer.camera.position); |
| 97 | + threeLayer.light.position.set(0, 0, 0); |
71 | 98 | }); |
72 | 99 |
|
73 | | - threeLayer.addTo(map); |
74 | 100 | } |
75 | 101 |
|
76 | 102 | </script> |
|
0 commit comments