|
7 | 7 | *********************************************************************-->
|
8 | 8 | <!DOCTYPE html>
|
9 | 9 | <html>
|
| 10 | + <head> |
| 11 | + <meta charset="utf-8" /> |
| 12 | + <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" /> |
| 13 | + <title data-i18n="resources.title_tiledMapLayer_4326WGS84"></title> |
| 14 | + <script type="text/javascript" src="../js/include-web.js"></script> |
| 15 | + <script |
| 16 | + type="text/javascript" |
| 17 | + include="mapbox-gl-enhance" |
| 18 | + src="../../dist/mapboxgl/include-mapboxgl.js" |
| 19 | + ></script> |
| 20 | + <style> |
| 21 | + body { |
| 22 | + margin: 0; |
| 23 | + padding: 0; |
| 24 | + } |
10 | 25 |
|
11 |
| -<head> |
12 |
| - <meta charset="utf-8" /> |
13 |
| - <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" /> |
14 |
| - <title data-i18n="resources.title_tiledMapLayer_4326WGS84"></title> |
15 |
| - <script type="text/javascript" src="../js/include-web.js"></script> |
16 |
| - <script type="text/javascript" include="mapbox-gl-enhance" src="../../dist/mapboxgl/include-mapboxgl.js"></script> |
17 |
| - <style> |
18 |
| - body { |
19 |
| - margin: 0; |
20 |
| - padding: 0; |
21 |
| - } |
| 26 | + #map { |
| 27 | + position: absolute; |
| 28 | + top: 0; |
| 29 | + bottom: 0; |
| 30 | + width: 100%; |
| 31 | + } |
| 32 | + </style> |
| 33 | + </head> |
22 | 34 |
|
23 |
| - #map { |
24 |
| - position: absolute; |
25 |
| - top: 0; |
26 |
| - bottom: 0; |
27 |
| - width: 100%; |
28 |
| - } |
29 |
| - </style> |
30 |
| -</head> |
| 35 | + <body> |
| 36 | + <div id="map"></div> |
| 37 | + <script type="text/javascript"> |
| 38 | + var host = window.isLocal ? window.server : 'https://iserver.supermap.io'; |
| 39 | + var map = new mapboxgl.Map({ |
| 40 | + container: 'map', // container id |
| 41 | + style: { |
| 42 | + version: 8, |
| 43 | + sources: { |
| 44 | + 'raster-tiles': { |
| 45 | + type: 'raster', |
| 46 | + tileSize: 256, |
| 47 | + //xyz形式,原生支持 |
| 48 | + //"tiles": ['https://t0.tianditu.gov.cn/DataServer?T=vec_c&x={x}&y={y}&l={z}'], |
31 | 49 |
|
32 |
| -<body> |
33 |
| - <div id="map"></div> |
34 |
| - <script type="text/javascript"> |
35 |
| - var host = window.isLocal ? window.server : 'https://iserver.supermap.io'; |
| 50 | + //iserver image资源模板;扩展支持 |
| 51 | + //"tiles": ['http://localhost:8090/iserver/services/map-World/rest/maps/World/image.png?viewBounds={viewBounds}&width={width}&height={height}'], |
36 | 52 |
|
37 |
| - // 方式一:1.调用 maplibregl.supermap.initMap,根据 SuperMap iServer 地图服务的地图信息,创建地图和底图 |
38 |
| - mapboxgl.supermap.initMap(host + '/iserver/services/map-world/rest/maps/World', { |
39 |
| - mapOptions: { |
40 |
| - zoom: 2 |
41 |
| - } |
42 |
| - }).then(function (dataRes) { |
43 |
| - var map = dataRes.map; |
44 |
| - map.on('load', function () { |
45 |
| - //从 iServer 查询 |
46 |
| - var idsParam = new mapboxgl.supermap.GetFeaturesByIDsParameters({ |
47 |
| - IDs: [234], |
48 |
| - datasetNames: ['World:Countries'] |
49 |
| - }); |
50 |
| - var service = new mapboxgl.supermap.FeatureService(host + '/iserver/services/data-world/rest/data'); |
51 |
| - service.getFeaturesByIDs(idsParam, function (serviceResult) { |
52 |
| - map.addSource('queryDatas', { |
53 |
| - type: 'geojson', |
54 |
| - data: serviceResult.result.features |
55 |
| - }); |
56 |
| - map.addLayer({ |
57 |
| - id: 'queryDatas', |
58 |
| - type: 'fill', |
59 |
| - source: 'queryDatas', |
60 |
| - paint: { |
61 |
| - 'fill-color': '#008080', |
62 |
| - 'fill-opacity': 1 |
63 |
| - }, |
64 |
| - filter: ['==', '$type', 'Polygon'] |
65 |
| - }); |
66 |
| - }); |
67 |
| - map.addControl(new mapboxgl.NavigationControl(), 'top-left'); |
68 |
| - }); |
69 |
| - }); |
| 53 | + //iserver tileimage资源模板;扩展支持 |
| 54 | + //"tiles": ['https://iserver.supermap.io/iserver/services/map-jingjin/rest/maps/%E4%BA%AC%E6%B4%A5%E5%9C%B0%E5%8C%BA%E5%9C%B0%E5%9B%BE/tileimage.png?scale={scale}&x={x}&y={y}&width={width}&height={height}&origin={"x":-180,"y":90}'], |
70 | 55 |
|
71 |
| - // 方法二: 直接用 mapboxgk.Map 初始化 |
72 |
| - // var map = new mapboxgl.Map({ |
73 |
| - // container: 'map', // container id |
74 |
| - // style: { |
75 |
| - // version: 8, |
76 |
| - // sources: { |
77 |
| - // 'raster-tiles': { |
78 |
| - // type: 'raster', |
79 |
| - // tileSize: 256, |
80 |
| - // //xyz形式,原生支持 |
81 |
| - // //"tiles": ['https://t0.tianditu.gov.cn/DataServer?T=vec_c&x={x}&y={y}&l={z}'], |
82 |
| - |
83 |
| - // //iserver image资源模板;扩展支持 |
84 |
| - // //"tiles": ['http://localhost:8090/iserver/services/map-World/rest/maps/World/image.png?viewBounds={viewBounds}&width={width}&height={height}'], |
85 |
| - |
86 |
| - // //iserver tileimage资源模板;扩展支持 |
87 |
| - // //"tiles": ['https://iserver.supermap.io/iserver/services/map-jingjin/rest/maps/%E4%BA%AC%E6%B4%A5%E5%9C%B0%E5%8C%BA%E5%9C%B0%E5%9B%BE/tileimage.png?scale={scale}&x={x}&y={y}&width={width}&height={height}&origin={"x":-180,"y":90}'], |
88 |
| - |
89 |
| - // //推荐; iserver tileimage资源;扩展支持 |
90 |
| - // //参数列表: |
91 |
| - // //地图服务地址(到地图名)必填 ; |
92 |
| - // //rasterSource为"iserver";必填; |
93 |
| - // //transparent:可选,默认为true; |
94 |
| - // //cacheEnabled: 是否使用缓存,默认为true; |
95 |
| - // //redirect: 如果为 true,则将请求重定向到瓦片的真实地址;如果为 false,则响应体中是瓦片的字节流,默认为false; |
96 |
| - // //layersID:要显示的图层id字符串; |
97 |
| - // //tileversion: 切片版本名称,cacheEnabled 为 true 时有效; |
98 |
| - // //rasterfunction: 栅格分析参数,类型为mapboxgl.supermap.NDVIParameter或mapboxgl.supermap.HillshadeParameter; |
99 |
| - // //format:瓦片格式,默认为'png'; |
100 |
| - // tiles: [host + '/iserver/services/map-world/rest/maps/World'], |
101 |
| - // rasterSource: 'iserver' |
102 |
| - // } |
103 |
| - // }, |
104 |
| - |
105 |
| - // layers: [ |
106 |
| - // { |
107 |
| - // id: 'simple-tiles', |
108 |
| - // type: 'raster', |
109 |
| - // source: 'raster-tiles', |
110 |
| - // minzoom: 0, |
111 |
| - // maxzoom: 22 |
112 |
| - // } |
113 |
| - // ] |
114 |
| - // }, |
115 |
| - // crs: 'EPSG:4326', // 或者 mapboxgl.CRS.EPSG4326 或者 new mapboxgl.CRS('EPSG:4326',[-180,-90,180,90]); |
116 |
| - // center: [0, 0], |
117 |
| - // zoom: 2 |
118 |
| - // }); |
119 |
| - </script> |
120 |
| -</body> |
| 56 | + //推荐; iserver tileimage资源;扩展支持 |
| 57 | + //参数列表: |
| 58 | + //地图服务地址(到地图名)必填 ; |
| 59 | + //rasterSource为"iserver";必填; |
| 60 | + //transparent:可选,默认为true; |
| 61 | + //cacheEnabled: 是否使用缓存,默认为true; |
| 62 | + //redirect: 如果为 true,则将请求重定向到瓦片的真实地址;如果为 false,则响应体中是瓦片的字节流,默认为false; |
| 63 | + //layersID:要显示的图层id字符串; |
| 64 | + //tileversion: 切片版本名称,cacheEnabled 为 true 时有效; |
| 65 | + //rasterfunction: 栅格分析参数,类型为mapboxgl.supermap.NDVIParameter或mapboxgl.supermap.HillshadeParameter; |
| 66 | + //format:瓦片格式,默认为'png'; |
| 67 | + tiles: [host + '/iserver/services/map-world/rest/maps/World'], |
| 68 | + rasterSource: 'iserver' |
| 69 | + } |
| 70 | + }, |
121 | 71 |
|
| 72 | + layers: [ |
| 73 | + { |
| 74 | + id: 'simple-tiles', |
| 75 | + type: 'raster', |
| 76 | + source: 'raster-tiles', |
| 77 | + minzoom: 0, |
| 78 | + maxzoom: 22 |
| 79 | + } |
| 80 | + ] |
| 81 | + }, |
| 82 | + crs: 'EPSG:4326', // 或者 mapboxgl.CRS.EPSG4326 或者 new mapboxgl.CRS('EPSG:4326',[-180,-90,180,90]); |
| 83 | + center: [0, 0], |
| 84 | + zoom: 2 |
| 85 | + }); |
| 86 | + map.on('load', function() { |
| 87 | + //从 iServer 查询 |
| 88 | + var idsParam = new mapboxgl.supermap.GetFeaturesByIDsParameters({ |
| 89 | + IDs: [234], |
| 90 | + datasetNames: ['World:Countries'] |
| 91 | + }); |
| 92 | + var service = new mapboxgl.supermap.FeatureService(host + '/iserver/services/data-world/rest/data'); |
| 93 | + service.getFeaturesByIDs(idsParam, function(serviceResult) { |
| 94 | + map.addSource('queryDatas', { |
| 95 | + type: 'geojson', |
| 96 | + data: serviceResult.result.features |
| 97 | + }); |
| 98 | + map.addLayer({ |
| 99 | + id: 'queryDatas', |
| 100 | + type: 'fill', |
| 101 | + source: 'queryDatas', |
| 102 | + paint: { |
| 103 | + 'fill-color': '#008080', |
| 104 | + 'fill-opacity': 0.4 |
| 105 | + }, |
| 106 | + filter: ['==', '$type', 'Polygon'] |
| 107 | + }); |
| 108 | + }); |
| 109 | + map.addControl(new mapboxgl.NavigationControl(), 'top-left'); |
| 110 | + }); |
| 111 | + </script> |
| 112 | + </body> |
122 | 113 | </html>
|
0 commit comments