labelThemeLayer.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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_labelThemeLayer"></title>
  9. <script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
  10. <script type="text/javascript" src="../../dist/leaflet/include-leaflet.js"></script>
  11. <style type="text/css">
  12. .legend td {
  13. width: 60px;
  14. height: 12px;
  15. font-size: 12px;
  16. }
  17. .leaflet-popup-content {
  18. margin: 5px
  19. }
  20. </style>
  21. </head>
  22. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  23. <div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
  24. <script type="text/javascript" src="../data/themeLableData.js"></script>
  25. <script type="text/javascript">
  26. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  27. var map, themeLayer, infoView,
  28. baseUrl = host + "/iserver/services/map-china400/rest/maps/China";
  29. init();
  30. function init() {
  31. // 检测是否支持 Canvas
  32. if (!document.createElement('canvas').getContext) {
  33. widgets.alert.showAlert(resources.msg_supportCanvas, false);
  34. return;
  35. }
  36. map = L.map("map", {
  37. crs: L.CRS.EPSG3857,
  38. center: [35, 106],
  39. maxZoom: 18,
  40. zoom: 3
  41. });
  42. L.supermap.tiledMapLayer(baseUrl).addTo(map);
  43. initThemeLayer();
  44. initLegendView();
  45. }
  46. function initThemeLayer() {
  47. themeLayer = L.supermap.labelThemeLayer("ThemeLayer").addTo(map);
  48. themeLayer.style = new SuperMap.ThemeStyle({
  49. labelRect: true,
  50. fontColor: "#000000",
  51. fontWeight: "bolder",
  52. fontSize: "18px",
  53. fill: true,
  54. fillColor: "#FFFFFF",
  55. fillOpacity: 1,
  56. stroke: false,
  57. strokeColor: "#8B7B8B"
  58. });
  59. //用于专题图的属性字段名称
  60. themeLayer.themeField = "aqi";
  61. //风格数组,设定值对应的样式
  62. themeLayer.styleGroups = [
  63. {
  64. start: 0,
  65. end: 51,
  66. style: {
  67. fillColor: "#6ACD06",
  68. fontSize: "17px"
  69. }
  70. }, {
  71. start: 51,
  72. end: 101,
  73. style: {
  74. fillColor: "#FBD12A",
  75. fontSize: "19px"
  76. }
  77. }, {
  78. start: 101,
  79. end: 151,
  80. style: {
  81. fillColor: "#FE8800",
  82. fontSize: "22px"
  83. }
  84. }, {
  85. start: 151,
  86. end: 201,
  87. style: {
  88. fillColor: "#FF0000",
  89. fontSize: "24px"
  90. }
  91. }, {
  92. start: 201,
  93. end: 301,
  94. style: {
  95. fillColor: "#CC0000",
  96. fontSize: "26px"
  97. }
  98. }, {
  99. start: 301,
  100. end: 601,
  101. style: {
  102. fillColor: "#960453",
  103. fontSize: "28px"
  104. }
  105. }
  106. ];
  107. themeLayer.on("mousemove", handleMouseOver);
  108. addThemeFeatures();
  109. }
  110. function addThemeFeatures() {
  111. var labelFeatures = [];
  112. var feat;
  113. for (var i = 0; i < themeData.length; i++) {
  114. var lonlat = themeData[i].lonLat.split(",");
  115. var lng = parseFloat(lonlat[0]);
  116. var lat = parseFloat(lonlat[1]);
  117. var text = themeData[i].aqi;
  118. feat = L.supermap.themeFeature([lat, lng, text], themeData[i]);
  119. labelFeatures.push(feat);
  120. }
  121. themeLayer.addFeatures(labelFeatures);
  122. }
  123. //图层信息框
  124. function updateInfoView(feature) {
  125. if (!feature && infoView) {
  126. infoView.remove();
  127. return;
  128. }
  129. if (!infoView) {
  130. infoView = L.popup();
  131. }
  132. var statisticsData = getStatisticsData();
  133. var contentHTML = "<table><tbody><tr>" +
  134. "<td><div style='margin-left: 15px'>" +
  135. "<table><tbody><tr>" +
  136. "<td><div id='contentID' style='margin-top: 2px;margin-bottom: 2px;width:65px;text-align: center;font-size:35px;color: #ffffff;'>" + feature.attributes.aqi + "</div></td>" +
  137. "<td style='padding-right: 20px;'></td>" +
  138. "<td>" +
  139. "<div id='textID' style='text-align: left;font-size: 19px;text-shadow: 1px 1px 0 #ffffff;'>" + feature.attributes.quality + "</div>" +
  140. "<div style='font-size:10px;width:150px;'>" + feature.attributes.time_point + "</div>" +
  141. "<div style=' font-weight:lighter; font-size:14px;'>" + resources.text_currentCity + ":" + feature.attributes.area + "</div>" +
  142. "</td>" +
  143. "</tr> </tbody></table>" +
  144. "<table style='width:100%;font-size: 10px;border: 0 solid black;padding: 0;margin: 0;border-spacing: 0;'>" +
  145. "<tbody>" +
  146. "<tr>" +
  147. "<td style='font-weight:bold;width:45px;'></td><td style='font-weight:bold;width:51px;' align='center' nowrap='true'>Current</td>" +
  148. "<td style=' font-weight:bold;width:49px;' align='center' nowrap='true'>Min</td>" +
  149. "<td style='font-weight:bold;width:49px;' align='center' nowrap='true'>Max</td> " +
  150. "</tr>" +
  151. "<tr style='height: 23px;'><td style='padding-left: 0;padding-right: 0'><div style='width:46px;'><span style='font-weight:bold;'>PM2.5</span></div></td>" +
  152. "<td style='font-size:11px;' align='center'>" + feature.attributes.pm2_5 + "</td>" +
  153. "<td style='color:#0086c8;font-size:11px;' align='center'>" + statisticsData.minNum + "</td>" +
  154. "<td style='color:#ce3c3a;font-size:11px;' align='center'>" + statisticsData.maxNum + "</td>" +
  155. "</tr>" +
  156. "<tr style='height: 23px;'><td style='padding-left: 0;padding-right: 0'><div style='width:46px;'><span style='font-weight:bold;'>PM10</span></div></td>" +
  157. "<td style='font-size:11px;' align='center'>" + feature.attributes.pm10 + "</td>" +
  158. "<td style='color:#0086c8;font-size:11px;' align='center'>" + statisticsData.minpm10 + "</td>" +
  159. "<td style='color:#ce3c3a;font-size:11px;' align='center'>" + statisticsData.maxpm10 + "</td>" +
  160. "</tr>" +
  161. "<tr style='height:23px;'><td style='padding-left: 0;padding-right: 0'><div style='width:46px;'><span style='font-weight:bold;'>O3</span></div></td>" +
  162. "<td style='font-size:11px;' align='center'>" + feature.attributes.o3 + "</td>" +
  163. "<td style='color:#0086c8;font-size:11px;' align='center'>" + statisticsData.minO3 + "</td>" +
  164. "<td style='color:#ce3c3a;font-size:11px;' align='center'>" + statisticsData.maxO3 + "</td></td>" +
  165. "</tr>" +
  166. "<tr style='height: 23px;'><td style='padding-left: 0;padding-right: 0'><div style='width:46px;'><span style='font-weight:bold;'>SO2</span></div></td>" +
  167. "<td style='font-size:11px;' align='center'>" + feature.attributes.so2 + "</td>" +
  168. "<td style='color:#0086c8;font-size:11px;' align='center'>" + statisticsData.minSO2 + "</td>" +
  169. "<td style='color:#ce3c3a;font-size:11px;' align='center'>" + statisticsData.maxSO2 + "</td></td>" +
  170. "</tr>" +
  171. "<tr style='height: 23px;'><td style='padding-left: 0;padding-right: 0'><div style='width:46px;'><span style='font-weight:bold;'>NO2</span></div></td>" +
  172. "<td style='font-size:11px;' align='center'>" + feature.attributes.no2 + "</td>" +
  173. "<td style='color:#0086c8;font-size:11px;' align='center'>" + statisticsData.minNO2 + "</td>" +
  174. "<td style='color:#ce3c3a;font-size:11px;' align='center'>" + statisticsData.maxNO2 + "</td></td>" +
  175. "</tr></tbody> </table></div></td></tr></tbody> </table>";
  176. var latLng = getLatLng(feature.attributes.lonLat);
  177. infoView.setLatLng(latLng).setContent(contentHTML).addTo(map);
  178. //设置弹框内容颜色
  179. var groups = themeLayer.styleGroups;
  180. for (var i = 0; i < groups.length; i++) {
  181. if (feature.attributes.aqi >= groups[0].start && feature.attributes.aqi < groups[0].end) {
  182. setColor("#6ACD06");
  183. }
  184. else if (feature.attributes.aqi >= groups[1].start && feature.attributes.aqi < groups[1].end) {
  185. setColor("#FBD12A");
  186. }
  187. else if (feature.attributes.aqi >= groups[2].start && feature.attributes.aqi < groups[2].end) {
  188. setColor("#FE8800");
  189. }
  190. else if (feature.attributes.aqi >= groups[3].start && feature.attributes.aqi < groups[3].end) {
  191. setColor("#FF0000");
  192. }
  193. else if (feature.attributes.aqi >= groups[4].start && feature.attributes.aqi < groups[4].end) {
  194. setColor("#CC0000");
  195. }
  196. else if (feature.attributes.aqi >= groups[5].start && feature.attributes.aqi < groups[5].end) {
  197. setColor("#960453");
  198. }
  199. }
  200. function setColor(color) {
  201. document.getElementById("contentID").style.backgroundColor = color;
  202. document.getElementById("textID").style.color = color;
  203. }
  204. function getLatLng(latLng) {
  205. var latLng = latLng.split(",");
  206. return L.latLng(parseFloat(latLng[1]), parseFloat(latLng[0]));
  207. }
  208. }
  209. //图例控件
  210. function initLegendView() {
  211. var legendView = L.control({position: 'bottomleft'});
  212. legendView.onAdd = function () {
  213. this._div = L.DomUtil.create('div', 'panel legend');
  214. this._div.innerHTML = "<div class='panel-body'><table>" +
  215. "<tr class='text-center'><td>" + resources.text_great + "</td><td >" + resources.text_good + "</td> <td >" + resources.text_mildPollution + "</td><td>" + resources.text_moderatePollution + "</td><td >" + resources.text_heavyPollution + "</td><td >" + resources.text_severePollution + "</td></tr>" +
  216. "<tr class='text-center'>" +
  217. "<td style='background: #6ACD06'></td><td style='background: #FBD12A'></td><td style='background: #FE8800'></td>" +
  218. "<td style='background: #FF0000'></td><td style='background: #CC0000'></td><td style='background: #960453'></td>" +
  219. "</tr>" +
  220. "<tr class='text-center'><td>0-51</td><td >51-101</td><td>101-151</td><td>151-201</td><td>201-301</td><td>301-601</td></tr>" +
  221. "</table></div>";
  222. handleMapEvent(this._div, this._map);
  223. return this._div;
  224. };
  225. legendView.addTo(map);
  226. }
  227. function handleMouseOver(evt) {
  228. if (evt.target && evt.target.refDataID) {
  229. var fea = themeLayer.getFeatureById(evt.target.refDataID);
  230. if (fea) {
  231. updateInfoView(fea);
  232. }
  233. } else if (infoView) {
  234. infoView.remove();
  235. }
  236. }
  237. function getStatisticsData() {
  238. if (this.statisticsData) {
  239. return this.statisticsData;
  240. }
  241. //遍历数组,获取单个属性。组成新的数组
  242. var pm25 = [], pm10s = [], o3s = [], so2s = [], no2s = [];
  243. for (var i = 0; i < themeData.length; i++) {
  244. pm10s.push(themeData[i].pm2_5);
  245. pm25.push(themeData[i].pm10);
  246. o3s.push(themeData[i].o3);
  247. so2s.push(themeData[i].so2);
  248. no2s.push(themeData[i].no2);
  249. }
  250. //获取单个属性的最大最小值
  251. this.statisticsData = {
  252. maxNum: Math.max.apply(Math, pm25),
  253. minNum: Math.min.apply(Math, pm25),
  254. maxpm10: Math.max.apply(Math, pm10s),
  255. minpm10: Math.min.apply(Math, pm10s),
  256. maxO3: Math.max.apply(Math, o3s),
  257. minO3: Math.min.apply(Math, o3s),
  258. maxSO2: Math.max.apply(Math, so2s),
  259. minSO2: Math.min.apply(Math, so2s),
  260. maxNO2: Math.max.apply(Math, no2s),
  261. minNO2: Math.min.apply(Math, no2s)
  262. };
  263. return this.statisticsData;
  264. }
  265. function handleMapEvent(div, map) {
  266. if (!div || !map) {
  267. return;
  268. }
  269. div.addEventListener('mouseover', function () {
  270. map.dragging.disable();
  271. map.scrollWheelZoom.disable();
  272. map.doubleClickZoom.disable();
  273. });
  274. div.addEventListener('mouseout', function () {
  275. map.dragging.enable();
  276. map.scrollWheelZoom.enable();
  277. map.doubleClickZoom.enable();
  278. });
  279. }
  280. </script>
  281. </body>
  282. </html>