01_tiledMapLayer_4326.html 5.0 KB

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