rangeThemeLayer.html 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <!DOCTYPE html>
  5. <html lang="en-US">
  6. <head>
  7. <meta charset="UTF-8">
  8. <meta http-equiv="X-UA-Compatible" content="IE=Edge">
  9. <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
  10. <title data-i18n="resources.title_popDensityRange"></title>
  11. <style>
  12. body, #map {
  13. position: absolute;
  14. width: 100%;
  15. height: 100%
  16. }
  17. .legendItemHeader,
  18. .legendItemValue {
  19. width: 120px;
  20. height: 18px;
  21. font-size: 14px;
  22. }
  23. </style>
  24. </head>
  25. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  26. <div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
  27. <div style="width: 272px;float:right">
  28. <div id="infoBox" class="panel panel-primary infoPane"
  29. style="width:272px;margin-top: 250px;position: absolute;fontSize:14px;display: none;float:right">
  30. <div class="panel-heading">
  31. <h5 class='panel-title text-center' data-i18n="resources.text_attributeTable"></h5>
  32. </div>
  33. <div id="infoContent" class="panel-body content">
  34. </div>
  35. </div>
  36. <div class="panel panel-primary legend" style="width:272px;margin-top: 400px;position: absolute;float:right">
  37. <div id="mapLegend" class="panel-heading">
  38. <h5 class='panel-title text-center'>
  39. <span data-i18n="resources.text_legend"></span>
  40. </h5>
  41. </div>
  42. <div class="panel-body text-center">
  43. <table>
  44. <tr>
  45. <td class="legendItemHeader" data-i18n="resources.text_populationDensity"></td>
  46. <td class="legendItemValue" data-i18n="resources.text_color"></td>
  47. </tr>
  48. <tr>
  49. <td class="legendItemHeader">0 - 0.02</td>
  50. <td class="legendItemValue" style="background: #FDE2CA"></td>
  51. </tr>
  52. <tr>
  53. <td class="legendItemHeader">0.02 - 0.04</td>
  54. <td class="legendItemValue" style="background: #FACE9C"></td>
  55. </tr>
  56. <tr>
  57. <td class="legendItemHeader">0.04 - 0.06</td>
  58. <td class="legendItemValue" style="background: #F09C42"></td>
  59. </tr>
  60. <tr>
  61. <td class="legendItemHeader">0.06 - 0.1</td>
  62. <td class="legendItemValue" style="background: #D0770B"></td>
  63. </tr>
  64. <tr>
  65. <td class="legendItemHeader">0.1 - 0.2</td>
  66. <td class="legendItemValue" style="background: #945305"></td>
  67. </tr>
  68. </table>
  69. </div>
  70. </div>
  71. </div>
  72. <script type="text/javascript" include="bootstrap" src="../js/include-web.js"></script>
  73. <script type="text/javascript" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
  74. <script type="text/javascript">
  75. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  76. var themeLayer,
  77. baseUrl = host + "/iserver/services/map-jingjin/rest/maps/京津地区地图",
  78. dataUrl = host + "/iserver/services/data-jingjin/rest/data";
  79. var attribution = "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
  80. " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
  81. " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ";
  82. var map = new mapboxgl.Map({
  83. container: 'map',
  84. style: {
  85. "version": 8,
  86. "sources": {
  87. "raster-tiles": {
  88. "attribution": attribution,
  89. "type": "raster",
  90. "tiles": [baseUrl + '/zxyTileImage.png?z={z}&x={x}&y={y}'],
  91. "tileSize": 256,
  92. },
  93. },
  94. "layers": [{
  95. "id": "simple-tiles",
  96. "type": "raster",
  97. "source": "raster-tiles",
  98. "minzoom": 0,
  99. "maxzoom": 22
  100. }]
  101. },
  102. center: [116.85, 39.79],
  103. zoom: 7
  104. });
  105. map.addControl(new mapboxgl.NavigationControl(), 'top-left');
  106. map.addControl(new mapboxgl.supermap.LogoControl(), 'bottom-right');
  107. var getFeatureParam, getFeatureBySQLService, getFeatureBySQLParams;
  108. getFeatureParam = new SuperMap.FilterParameter({
  109. name: "Jingjin",
  110. attributeFilter: "SMID > -1"
  111. });
  112. getFeatureBySQLParams = new SuperMap.GetFeaturesBySQLParameters({
  113. queryParameter: getFeatureParam,
  114. toIndex: 500,
  115. datasetNames: ["Jingjin:BaseMap_R"]
  116. });
  117. getFeatureBySQLService = new SuperMap.GetFeaturesBySQLService(dataUrl, {
  118. format: SuperMap.DataFormat.ISERVER,
  119. eventListeners: {"processCompleted": processCompleted}
  120. });
  121. getFeatureBySQLService.processAsync(getFeatureBySQLParams);
  122. function processCompleted(getFeaturesEventArgs) {
  123. var result = getFeaturesEventArgs.result;
  124. if (result && result.features) {
  125. addThemeLayer();
  126. themeLayer.addFeatures(result.features);
  127. //显示图例
  128. document.getElementById("mapLegend").style.display = "block";
  129. }
  130. }
  131. function addThemeLayer() {
  132. themeLayer = new mapboxgl.supermap.RangeThemeLayer("ThemeLayer",
  133. {
  134. // map: map,//该可选参数将在下个版本遗弃
  135. attributions: " ",
  136. opacity: 0.8,
  137. style: {
  138. shadowBlur: 16,
  139. shadowColor: "#000000",
  140. fillColor: "#FFFFFF"
  141. },
  142. isHoverAble: true,
  143. highlightStyle: {
  144. stroke: true,
  145. strokeWidth: 4,
  146. strokeColor: 'blue',
  147. fillColor: "#00EEEE",
  148. fillOpacity: 0.8
  149. },
  150. themeField: "POP_DENSITY99",
  151. styleGroups: [
  152. {
  153. start: 0,
  154. end: 0.02,
  155. style: {
  156. color: '#FDE2CA'
  157. }
  158. },
  159. {
  160. start: 0.02,
  161. end: 0.04,
  162. style: {
  163. color: '#FACE9C'
  164. }
  165. },
  166. {
  167. start: 0.04,
  168. end: 0.06,
  169. style: {
  170. color: '#F09C42'
  171. }
  172. },
  173. {
  174. start: 0.06,
  175. end: 0.1,
  176. style: {
  177. color: '#D0770B'
  178. }
  179. },
  180. {
  181. start: 0.1,
  182. end: 0.2,
  183. style: {
  184. color: '#945305'
  185. }
  186. }]
  187. });
  188. map.addLayer(themeLayer);
  189. //专题图层 mousemove 事件
  190. themeLayer.on('mousemove', function (e) {
  191. if (e.target && e.target.refDataID) {
  192. document.getElementById("infoBox").style.display = "block";
  193. var fid = e.target.refDataID;
  194. var fea = themeLayer.getFeatureById(fid);
  195. if (fea) {
  196. document.getElementById("infoContent").innerHTML = "";
  197. document.getElementById("infoContent").innerHTML += "ID: " + fea.attributes.SMID + "<br/>";
  198. document.getElementById("infoContent").innerHTML += resources.text_districtName + fea.attributes.NAME + "<br/>";
  199. document.getElementById("infoContent").innerHTML += resources.text_populationDensity + parseFloat(fea.attributes.POP_DENSITY99).toFixed(5) + "<br/>";
  200. }
  201. }
  202. else {
  203. document.getElementById("infoContent").innerHTML = "";
  204. document.getElementById("infoBox").style.display = "none";
  205. }
  206. });
  207. }
  208. </script>
  209. </body>
  210. </html>