theme_themePM2_5.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  8. <title data-i18n="resources.title_themePM2_5"></title>
  9. <style type="text/css">
  10. .editPane {
  11. position: absolute;
  12. right: 60px;
  13. top: 50px;
  14. text-align: center;
  15. background: #FFF;
  16. z-index: 1000;
  17. }
  18. </style>
  19. </head>
  20. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  21. <div class='panel panel-primary editPane' id='editPane' style="z-index: 99999">
  22. <div class='panel-heading'>
  23. <h5 class='panel-title text-center' data-i18n="resources.title_themePM2_5"></h5>
  24. </div>
  25. <div class='panel-body' id='params'>
  26. <p></p>
  27. <div align='right' class='button-group'>
  28. <input type='button' id='btn1' class='btn btn-primary' data-i18n="[value]resources.btn_addLabel"
  29. onclick="addLabel()"/>
  30. <input type='button' id='btn2' class='btn btn-primary' data-i18n="[value]resources.text_input_value_clear"
  31. onclick="clearLabels()"/>
  32. </div>
  33. </div>
  34. </div>
  35. <div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
  36. <script type="text/javascript" include="bootstrap" src="../js/include-web.js"></script>
  37. <script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
  38. <script src="../data/themeLableData.js"></script>
  39. <script type="text/javascript">
  40. var map, layer, vectorLayer, selectFeature, popup, strategy,
  41. host = window.isLocal ? window.server : "https://iserver.supermap.io",
  42. url = host + "/iserver/services/map-china400/rest/maps/China_4326";
  43. map = new SuperMap.Map("map", {
  44. controls: [
  45. new SuperMap.Control.LayerSwitcher(),
  46. new SuperMap.Control.ScaleLine(),
  47. new SuperMap.Control.Zoom(),
  48. new SuperMap.Control.Navigation({
  49. dragPanOptions: {
  50. enableKinetic: true
  51. }
  52. })]
  53. });
  54. layer = new SuperMap.Layer.TiledDynamicRESTLayer("世界地图", url, {
  55. transparent: true,
  56. cacheEnabled: true
  57. }, {maxResolution: "auto"});
  58. layer.events.on({"layerInitialized": addLayer});
  59. //新建一个策略
  60. strategy = new SuperMap.Strategy.GeoText();
  61. //新建一个标签专题图层
  62. vectorLayer = new SuperMap.Layer.Vector("Label", {strategies: [strategy]});
  63. //设置标签的样式
  64. strategy.style = {
  65. fontColor: "#FF7F00",
  66. fontWeight: "bolder",
  67. fontSize: "14px",
  68. fill: true,
  69. fillColor: "#FFFFFF",
  70. fillOpacity: 1,
  71. stroke: true,
  72. strokeColor: "#8B7B8B"
  73. };
  74. //用于标签分组的属性字段名称
  75. strategy.groupField = "aqi";
  76. //标签分组数组,根据每个城市的空气指数来设置分段。
  77. strategy.styleGroups = [
  78. {
  79. start: 0,
  80. end: 51,
  81. style: {
  82. fontColor: "#000",
  83. fillColor: "#6ACD06",
  84. fontWeight: "bolder",
  85. fontSize: "17px"
  86. }
  87. },
  88. {
  89. start: 51,
  90. end: 101,
  91. style: {
  92. fontColor: "#000",
  93. fillColor: "#FBD12A",
  94. fontWeight: "bolder",
  95. fontSize: "19px"
  96. }
  97. },
  98. {
  99. start: 101,
  100. end: 151,
  101. style: {
  102. fontColor: "#000",
  103. fillColor: "#FE8800",
  104. fontWeight: "bolder",
  105. fontSize: "22px"
  106. }
  107. },
  108. {
  109. start: 151,
  110. end: 201,
  111. style: {
  112. fontColor: "#000",
  113. fillColor: "#FF0000",
  114. fontWeight: "bolder",
  115. fontSize: "24px"
  116. }
  117. },
  118. {
  119. start: 201,
  120. end: 301,
  121. style: {
  122. fontColor: "#000",
  123. fillColor: "#CC0000",
  124. fontWeight: "bolder",
  125. fontSize: "26px"
  126. }
  127. },
  128. {
  129. start: 301,
  130. end: 601,
  131. style: {
  132. fontColor: "#000",
  133. fillColor: "#960453",
  134. fontWeight: "bolder",
  135. fontSize: "28px"
  136. }
  137. }
  138. ];
  139. function addLayer() {
  140. map.addLayers([layer, vectorLayer]);
  141. map.setCenter(new SuperMap.LonLat(104.067923, 34.679943), 2);
  142. //兼容PC与移动端
  143. var broz = SuperMap.Util.getBrowser();
  144. var callbacks = {};
  145. if (broz.device === 'android' || broz.device === 'apple') {
  146. callbacks = {
  147. click: openInfoWin,
  148. clickout: closeInfoWin
  149. };
  150. }
  151. else {
  152. callbacks = {
  153. over: openInfoWin,
  154. out: closeInfoWin
  155. };
  156. }
  157. //实例化 selectFeature 控件
  158. // selectFeature = new SuperMap.Control.SelectFeature(vectorLayer,{callbacks:callbacks,hover:true});
  159. selectFeature = new SuperMap.Control.SelectFeature(vectorLayer, {callbacks: callbacks, hover: false});
  160. //map上添加控件
  161. map.addControl(selectFeature);
  162. //激活控件
  163. selectFeature.activate();
  164. }
  165. //打弹窗,显示具体信息
  166. function openInfoWin(feature) {
  167. closeInfoWin();
  168. var pm25 = [];
  169. var pm10s = [];
  170. var o3s = [];
  171. var so2s = [];
  172. var no2s = [];
  173. //遍历数组,获取单个属性。组成新的数组
  174. for (var i = 0; i < themeData.length; i++) {
  175. var pm2_5 = themeData[i].pm2_5;
  176. var pm10 = themeData[i].pm10;
  177. var o3 = themeData[i].o3;
  178. var so2 = themeData[i].so2;
  179. var no2 = themeData[i].no2;
  180. pm10s.push(pm10);
  181. pm25.push(pm2_5);
  182. o3s.push(o3);
  183. so2s.push(so2);
  184. no2s.push(no2);
  185. }
  186. //获取单个属性的最大最小值
  187. var maxNum = Math.max.apply(Math, pm25);
  188. var minNum = Math.min.apply(Math, pm25);
  189. var maxpm10 = Math.max.apply(Math, pm10s);
  190. var minpm10 = Math.min.apply(Math, pm10s);
  191. var maxO3 = Math.max.apply(Math, o3s);
  192. var minO3 = Math.min.apply(Math, o3s);
  193. var maxSO2 = Math.max.apply(Math, so2s);
  194. var minSO2 = Math.min.apply(Math, so2s);
  195. var maxNO2 = Math.max.apply(Math, no2s);
  196. var minNO2 = Math.min.apply(Math, no2s);
  197. //组织弹窗内容
  198. var contentHTML = "<table><tbody><tr>";
  199. contentHTML += " <td><div>";
  200. contentHTML += "<table><tbody><tr><td>";
  201. contentHTML += "<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>";
  202. contentHTML += "<td style='padding-right: 1px;'></td>";
  203. contentHTML += "<td> <div id='textID'style='text-align: left;font-size: 19px;text-shadow: 1px 1px 0 #ffffff;'>" + feature.attributes.quality + "</div>";
  204. contentHTML += " <div style='font-size:9px;width:200px;float:left;'>" + feature.attributes.time_point + "</div>";
  205. contentHTML += "<div style=' font-weight:lighter; font-size:12px;'>" + resources.text_city+": " + feature.attributes.area + "</div>";
  206. contentHTML += " </td></tr> </tbody></table>";
  207. contentHTML += " <table style='font-size: 10px;border: 0px solid black;padding: 0px;margin: 0px;border-spacing: 0px;'>";
  208. contentHTML += " <tbody><tr> <td style='font-weight:bold;width:45px;'></td><td style='font-weight:bold;width:51px;' align='center' nowrap='true'>Current</td>";
  209. contentHTML += " <td style=' font-weight:bold;width:49px;' align='center' nowrap='true'>Min</td><td style='font-weight:bold;width:49px;' align='center' nowrap='true'>Max</td> </tr>";
  210. contentHTML += "<tr style='height: 23px;'><td style='padding-left: 0px;padding-right: 0px'><div style='width:46px;'><span style='font-weight:bold;'>PM2.5</span></div></td>";
  211. contentHTML += " <td style='font-size:11px;'align='center'>" + feature.attributes.pm2_5 + "</td>";
  212. contentHTML += " <td style='color:#0086c8;font-size:11px;' align='center'>" + minNum + "</td><td style='color:#ce3c3a;font-size:11px;' align='center'>" + maxNum + "</td>";
  213. contentHTML += "</tr><tr style='height: 23px;'><td style='padding-left: 0px;padding-right: 0px'><div style='width:46px;'>";
  214. contentHTML += "<span style='font-weight:bold;'>PM10</span>";
  215. contentHTML += "</div></td><td style='font-size:11px;'align='center'>" + feature.attributes.pm10 + "</td><td style='color:#0086c8;font-size:11px;' align='center'>" + minpm10 + "</td>";
  216. contentHTML += "<td style='color:#ce3c3a;font-size:11px;' align='center'>" + maxpm10 + "</td>";
  217. contentHTML += "</tr><tr style='height:23px;'><td style='padding-left: 0px;padding-right: 0px'><div style='width:46px;'><span style='font-weight:bold;'>O3</span></div></td><td style='font-size:11px;'align='center'>" + feature.attributes.o3 + "</td>";
  218. contentHTML += "<td style='color:#0086c8;font-size:11px;' align='center'>" + minO3 + "</td><td style='color:#ce3c3a;font-size:11px;' align='center'>" + maxO3 + "</td></td></tr>";
  219. contentHTML += "<tr style='height: 23px;'><td style='padding-left: 0px;padding-right: 0px'><div style='width:46px;'><span style='font-weight:bold;'>SO2</span></div></td>";
  220. contentHTML += "<td style='font-size:11px;'align='center'>" + feature.attributes.so2 + "</td><td style='color:#0086c8;font-size:11px;' align='center'>" + minSO2 + "</td><td style='color:#ce3c3a;font-size:11px;' align='center'>" + maxSO2 + "</td></td></tr>";
  221. contentHTML += "<tr style='height: 23px;'><td style='padding-left: 0px;padding-right: 0px'><div style='width:46px;'><span style='font-weight:bold;'>NO2</span></div></td>";
  222. contentHTML += "<td style='font-size:11px;'align='center'>" + feature.attributes.no2 + "</td><td style='color:#0086c8;font-size:11px;' align='center'>" + minNO2 + "</td><td style='color:#ce3c3a;font-size:11px;' align='center'>" + maxNO2 + "</td></td></tr>";
  223. contentHTML += "</tbody> </table></div></td></tr></tbody> </table>";
  224. //新建一个弹窗并加入地图
  225. var lonlat = feature.attributes.lonLat.split(",");
  226. var x = parseFloat(lonlat[0]);
  227. var y = parseFloat(lonlat[1]);
  228. var xy = map.getPixelFromLonLat(new SuperMap.LonLat(x, y));
  229. xy.x += 10;
  230. var postion = map.getLonLatFromPixel(new SuperMap.Pixel(xy.x, xy.y));
  231. //新建popup
  232. popup = new SuperMap.Popup("popwin", new SuperMap.LonLat(postion.lon, postion.lat), null, contentHTML, null, true, function () {
  233. closeInfoWin();
  234. });
  235. map.addPopup(popup);
  236. //设置div的背景颜色
  237. var groups = strategy.styleGroups;
  238. for (var i = 0; i < groups.length; i++) {
  239. if (feature.attributes.aqi >= groups[0].start && feature.attributes.aqi < groups[0].end) {
  240. popup.setBorder("2px solid #6ACD06");
  241. document.getElementById("contentID").style.backgroundColor = "#6ACD06";
  242. document.getElementById("textID").style.color = "#6ACD06";
  243. }
  244. else if (feature.attributes.aqi >= groups[1].start && feature.attributes.aqi < groups[1].end) {
  245. popup.setBorder("2px solid #FBD12A");
  246. document.getElementById("contentID").style.backgroundColor = "#FBD12A";
  247. document.getElementById("textID").style.color = "#FBD12A";
  248. }
  249. else if (feature.attributes.aqi >= groups[2].start && feature.attributes.aqi < groups[2].end) {
  250. popup.setBorder("2px solid #FE8800");
  251. document.getElementById("contentID").style.backgroundColor = "#FE8800";
  252. document.getElementById("textID").style.color = "#FE8800";
  253. }
  254. else if (feature.attributes.aqi >= groups[3].start && feature.attributes.aqi < groups[3].end) {
  255. popup.setBorder("2px solid #FF0000");
  256. document.getElementById("contentID").style.backgroundColor = "#FF0000";
  257. document.getElementById("textID").style.color = "#FF0000";
  258. }
  259. else if (feature.attributes.aqi >= groups[4].start && feature.attributes.aqi < groups[4].end) {
  260. popup.setBorder("2px solid #CC0000");
  261. document.getElementById("contentID").style.backgroundColor = "#CC0000";
  262. document.getElementById("textID").style.color = "#CC0000";
  263. }
  264. else if (feature.attributes.aqi >= groups[5].start && feature.attributes.aqi < groups[5].end) {
  265. popup.setBorder("2px solid #960453");
  266. document.getElementById("contentID").style.backgroundColor = "#960453";
  267. document.getElementById("textID").style.color = "#960453";
  268. }
  269. }
  270. }
  271. //关闭弹窗
  272. function closeInfoWin() {
  273. if (popup) {
  274. try {
  275. map.removePopup(popup);
  276. }
  277. catch (e) {
  278. }
  279. }
  280. }
  281. function addLabel() {
  282. clearLabels();
  283. var labelFeas = [];
  284. var label, labelVector;
  285. for (var i = 0; i < themeData.length; i++) {
  286. var lonlat = themeData[i].lonLat.split(",");
  287. var x = parseFloat(lonlat[0]);
  288. var y = parseFloat(lonlat[1]);
  289. var text = themeData[i].aqi;
  290. label = new SuperMap.Geometry.GeoText(x, y, text);
  291. labelVector = new SuperMap.Feature.Vector(label, themeData[i]);
  292. labelFeas.push(labelVector);
  293. }
  294. vectorLayer.addFeatures(labelFeas);
  295. }
  296. //清楚标签专题图层
  297. function clearLabels() {
  298. closeInfoWin();
  299. vectorLayer.removeAllFeatures();
  300. }
  301. </script>
  302. </body>
  303. </html>