graticuleLayer_4326.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
  6. <title data-i18n="resources.title_graticuleLayer_4326"></title>
  7. <script type="text/javascript" src="../js/include-web.js"></script>
  8. <script
  9. type="text/javascript"
  10. include="mapbox-gl-enhance"
  11. src="../../dist/mapboxgl/include-mapboxgl.js"
  12. ></script>
  13. <style>
  14. body {
  15. margin: 0;
  16. padding: 0;
  17. }
  18. #map {
  19. position: absolute;
  20. top: 0;
  21. bottom: 0;
  22. width: 100%;
  23. }
  24. </style>
  25. </head>
  26. <body>
  27. <div id="map"></div>
  28. <script type="text/javascript">
  29. var host = window.isLocal ? window.server : 'https://iserver.supermap.io';
  30. var map = new mapboxgl.Map({
  31. container: 'map', // container id
  32. style: {
  33. version: 8,
  34. sources: {
  35. 'raster-tiles': {
  36. type: 'raster',
  37. tileSize: 256,
  38. tiles: [host + '/iserver/services/map-world/rest/maps/World'],
  39. rasterSource: 'iserver'
  40. }
  41. },
  42. layers: [
  43. {
  44. id: 'simple-tiles',
  45. type: 'raster',
  46. source: 'raster-tiles',
  47. minzoom: 0,
  48. maxzoom: 22
  49. }
  50. ]
  51. },
  52. crs: 'EPSG:4326',
  53. center: [0, 0],
  54. zoom: 2
  55. });
  56. map.on('load', function() {
  57. //从 iServer 查询
  58. var idsParam = new SuperMap.GetFeaturesByIDsParameters({
  59. IDs: [247],
  60. datasetNames: ['World:Countries']
  61. });
  62. var service = new mapboxgl.supermap.FeatureService(host + '/iserver/services/data-world/rest/data');
  63. service.getFeaturesByIDs(idsParam, function(serviceResult) {
  64. map.addSource('queryDatas', {
  65. type: 'geojson',
  66. data: serviceResult.result.features
  67. });
  68. map.addLayer({
  69. id: 'queryDatas',
  70. type: 'fill',
  71. source: 'queryDatas',
  72. paint: {
  73. 'fill-color': '#008080',
  74. 'fill-opacity': 0.4
  75. },
  76. filter: ['==', '$type', 'Polygon']
  77. });
  78. });
  79. // 设置经纬网
  80. var graticuleLayer = new mapboxgl.supermap.GraticuleLayer();
  81. map.addLayer(graticuleLayer);
  82. });
  83. </script>
  84. </body>
  85. </html>