uniqueTheme3DLayer.html 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. <title data-i18n="resources.title_uniqueTheme3DLayer"></title>
  9. <meta name="viewport" content="width=device-width,initial-scale=0.5,maximum-scale=1,user-scalable=no"/>
  10. <script type="text/javascript" src="../js/include-web.js"></script>
  11. <style>
  12. .mapboxgl-popup {
  13. cursor: auto;
  14. }
  15. .mapboxgl-popup-tip {
  16. border-top-color: rgba(0, 0, 0, 0.8) !important;
  17. }
  18. .mapboxgl-popup-content {
  19. color: whitesmoke;
  20. background-color: rgba(0, 0, 0, 0.8) !important;
  21. }
  22. </style>
  23. </head>
  24. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  25. <div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
  26. <script type="text/javascript" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
  27. <script>
  28. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  29. var dataUrl = host + "/iserver/services/data-jingjin/rest/data";
  30. var center = [116.640545, 40.531714], themeField = "LANDTYPE", popup;
  31. var attribution = "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
  32. " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
  33. " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ";
  34. var map = new mapboxgl.Map({
  35. container: 'map',
  36. style: {
  37. "version": 8,
  38. "sources": {
  39. "raster-tiles": {
  40. "attribution": attribution,
  41. "type": "raster",
  42. "tiles": [host + '/iserver/services/map-china400/rest/maps/China/zxyTileImage.png?z={z}&x={x}&y={y}'],
  43. "tileSize": 256
  44. }
  45. },
  46. "layers": [{
  47. "id": "simple-tiles",
  48. "type": "raster",
  49. "source": "raster-tiles",
  50. "minzoom": 0,
  51. "maxzoom": 22
  52. }]
  53. },
  54. center: center,
  55. zoom: 7
  56. });
  57. map.addControl(new mapboxgl.NavigationControl(), 'top-left');
  58. buildThemeLayer();
  59. function buildThemeLayer() {
  60. var getFeatureBySQLParams = new SuperMap.GetFeaturesBySQLParameters({
  61. queryParameter: new SuperMap.FilterParameter({
  62. name: "Jingjin",
  63. attributeFilter: "SMID > -1"
  64. }),
  65. toIndex: 500,
  66. datasetNames: ["Jingjin:Landuse_R"]
  67. });
  68. var queryFeatures = new SuperMap.GetFeaturesBySQLService(dataUrl, {
  69. eventListeners: {
  70. processCompleted: function (serviceResult) {
  71. if (serviceResult.error) {
  72. alert("error:" + JSON.stringify(serviceResult.error));
  73. return;
  74. }
  75. var result = serviceResult.result;
  76. if (result.features) {
  77. createThemeLayer(result.features)
  78. }
  79. }
  80. },
  81. format: SuperMap.DataFormat.GEOJSON
  82. });
  83. queryFeatures.processAsync(getFeatureBySQLParams);
  84. }
  85. //创建专题图图层
  86. function createThemeLayer(data) {
  87. popup = new mapboxgl.Popup({closeOnClick: true}).addTo(map);
  88. var themeLayer = new mapboxgl.supermap.UniqueTheme3DLayer("uniqueThemeLayer", {
  89. height: 6000,
  90. enableHighlight: true,
  91. themeField: themeField,
  92. colorStops: [
  93. ["草地", "#C1FFC1"], ["城市", "#CD7054"], ["灌丛", "#7CCD7C"], ["旱地", "#EE9A49"],
  94. ["湖泊水库", "#8EE5EE"], ["经济林", "#548B54"], ["沙漠", "#DEB887"], ["水浇地", "#E0FFFF"],
  95. ["水田", "#388E8E"], ["用材林", "#556B2F"], ["沼泽", "#2F4F4F"]
  96. ],
  97. // 显示图例
  98. showLegend: true,
  99. legendTitle: resources.text_landUseType,
  100. legendOrientation: 'vertical'
  101. });
  102. themeLayer.setHighlightStyleOptions({callback: highlightCallback}).setData(data).addTo(map);
  103. map.easeTo({
  104. pitch: 60,
  105. bearing: 0
  106. })
  107. }
  108. //设置高亮图层提示
  109. function highlightCallback(features, evt) {
  110. var ft = features && features[0];
  111. if (!ft) {
  112. popup.remove();
  113. }
  114. if (ft && ft.properties) {
  115. var content = "<span>" + resources.text_landType + ": " + ft.properties[themeField] + "</span><br>";
  116. content += "<span>" + resources.text_landArea + ": " + ft.properties["AREA"] + " " + resources.text_squareKilometre + "</span><br>";
  117. popup.addTo(map);
  118. popup.setLngLat(evt.lngLat);
  119. popup.setHTML(content);
  120. }
  121. map.on('mouseout', function () {
  122. popup.remove();
  123. });
  124. }
  125. </script>
  126. </body>
  127. </html>