labelThemeLayer.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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. <style type="text/css">
  10. .legend td {
  11. width: 60px;
  12. height: 12px;
  13. font-size: 12px;
  14. }
  15. .panel {
  16. margin-bottom: 10px;
  17. }
  18. .leaflet-popup-content {
  19. margin: 5px
  20. }
  21. .ol-popup {
  22. position: relative;
  23. background-color: white;
  24. -webkit-filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.2));
  25. filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.2));
  26. padding: 15px;
  27. border-radius: 10px;
  28. border: 1px solid #cccccc;
  29. bottom: 60px;
  30. left: -50px;
  31. font-size: 14px;
  32. z-index: 100;
  33. }
  34. .ol-popup:after, .ol-popup:before {
  35. top: 100%;
  36. border: solid transparent;
  37. content: " ";
  38. height: 0;
  39. width: 0;
  40. position: absolute;
  41. pointer-events: none;
  42. }
  43. .ol-popup:after {
  44. border-top-color: white;
  45. border-width: 10px;
  46. left: 48px;
  47. margin-left: -10px;
  48. }
  49. .ol-popup:before {
  50. border-top-color: #cccccc;
  51. border-width: 11px;
  52. left: 48px;
  53. margin-left: -11px;
  54. }
  55. .ol-popup-closer {
  56. text-decoration: none;
  57. position: absolute;
  58. top: 2px;
  59. right: 8px;
  60. }
  61. .ol-popup-closer:after {
  62. content: "✖";
  63. }
  64. </style>
  65. </head>
  66. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  67. <div id="map" style="width: 100%;height:100%">
  68. <div style="z-index: 100;position: relative;width: 250px;float:right">
  69. <div class="panel legend"
  70. style=" position: fixed !important;position: absolute; left: 0;bottom: 0;width: 400px; margin-left: 10px;">
  71. <div class="panel-body text-center">
  72. <table>
  73. <tr>
  74. <td data-i18n="resources.text_great"></td>
  75. <td data-i18n="resources.text_good"></td>
  76. <td data-i18n="resources.text_mildPollution"></td>
  77. <td data-i18n="resources.text_moderatePollution"></td>
  78. <td data-i18n="resources.text_heavyPollution"></td>
  79. <td data-i18n="resources.text_severePollution"></td>
  80. </tr>
  81. <tr>
  82. <td style='background: #6ACD06'></td>
  83. <td style='background: #FBD12A'></td>
  84. <td style='background: #FE8800'></td>
  85. <td style='background: #FF0000'></td>
  86. <td style='background: #CC0000'></td>
  87. <td style='background: #960453'></td>
  88. </tr>
  89. <tr>
  90. <td>0-51</td>
  91. <td>51-101</td>
  92. <td>101-151</td>
  93. <td>151-201</td>
  94. <td>201-301</td>
  95. <td>301-601</td>
  96. </tr>
  97. </table>
  98. </div>
  99. </div>
  100. </div>
  101. </div>
  102. <div id="popup" class="ol-popup">
  103. <a href="#" id="popup-closer" class="ol-popup-closer"></a>
  104. <div id="popup-content"></div>
  105. </div>
  106. <script type="text/javascript" include="bootstrap-css" src="../js/include-web.js"></script>
  107. <script type="text/javascript" src="../../dist/ol/include-ol.js"></script>
  108. <script type="text/javascript" src="../data/themeLableData.js"></script>
  109. <script type="text/javascript">
  110. var map, themeSource,
  111. host = window.isLocal ? window.server : "https://iserver.supermap.io",
  112. baseUrl = host + "/iserver/services/map-china400/rest/maps/China_4326";
  113. var popupContent = document.getElementById('popup-content');
  114. var closer = document.getElementById('popup-closer');
  115. closer.onClick = function () {
  116. removePopup();
  117. return false;
  118. };
  119. var popup = new ol.Overlay(({
  120. element: document.getElementById('popup'),
  121. autoPan: true,
  122. autoPanAnimation: {
  123. duration: 250
  124. }
  125. }));
  126. new ol.supermap.MapService(baseUrl).getMapInfo(function (serviceResult) {
  127. var mapJSONObj = serviceResult.result;
  128. map = new ol.Map({
  129. target: 'map',
  130. controls: ol.control.defaults({attributionOptions: {collapsed: false}})
  131. .extend([new ol.supermap.control.Logo()]),
  132. view: new ol.View({
  133. center: [110.85, 39.79],
  134. zoom: 4,
  135. projection: "EPSG:4326",
  136. multiWorld: true
  137. }),
  138. overlays: [popup]
  139. });
  140. var options = ol.source.TileSuperMapRest.optionsFromMapJSON(baseUrl, mapJSONObj);
  141. var layer = new ol.layer.Tile({
  142. source: new ol.source.TileSuperMapRest(options),
  143. projection: 'EPSG:4326'
  144. });
  145. map.addLayer(layer);
  146. initThemeLayer();
  147. });
  148. function initThemeLayer() {
  149. themeSource = new ol.source.Label("labelThemeLayer", {
  150. map: map,
  151. attributions: " ",
  152. style: new SuperMap.ThemeStyle({
  153. labelRect: true,
  154. fontColor: "#000000",
  155. fontWeight: "bolder",
  156. fontSize: "18px",
  157. fill: true,
  158. fillColor: "#FFFFFF",
  159. fillOpacity: 1,
  160. stroke: false,
  161. strokeColor: "#8B7B8B"
  162. }),
  163. themeField: "aqi",
  164. styleGroups: [
  165. {
  166. start: 0,
  167. end: 51,
  168. style: {
  169. fillColor: "#6ACD06",
  170. fontSize: "17px"
  171. }
  172. }, {
  173. start: 51,
  174. end: 101,
  175. style: {
  176. fillColor: "#FBD12A",
  177. fontSize: "19px"
  178. }
  179. }, {
  180. start: 101,
  181. end: 151,
  182. style: {
  183. fillColor: "#FE8800",
  184. fontSize: "22px"
  185. }
  186. }, {
  187. start: 151,
  188. end: 201,
  189. style: {
  190. fillColor: "#FF0000",
  191. fontSize: "24px"
  192. }
  193. }, {
  194. start: 201,
  195. end: 301,
  196. style: {
  197. fillColor: "#CC0000",
  198. fontSize: "26px"
  199. }
  200. }, {
  201. start: 301,
  202. end: 601,
  203. style: {
  204. fillColor: "#960453",
  205. fontSize: "28px"
  206. }
  207. }
  208. ]
  209. });
  210. //专题图层 mousemove 事件
  211. themeSource.on('mousemove', handleMouseOver);
  212. //source添加到图层
  213. var pointerInteraction = new ol.interaction.Pointer({
  214. handleMoveEvent: function (event) {
  215. themeSource.fire('mousemove', event);
  216. }
  217. });
  218. map.addInteraction(pointerInteraction);
  219. var themeLayer = new ol.layer.Image({
  220. source: themeSource
  221. });
  222. map.addLayer(themeLayer);
  223. addFeatures();
  224. }
  225. function addFeatures() {
  226. var labelFeatures = [];
  227. var feat;
  228. for (var i = 0; i < themeData.length; i++) {
  229. var lonlat = themeData[i].lonLat.split(",");
  230. var lng = parseFloat(lonlat[0]);
  231. var lat = parseFloat(lonlat[1]);
  232. var text = themeData[i].aqi;
  233. feat = new ol.supermap.ThemeFeature([lng, lat, text], themeData[i]);
  234. labelFeatures.push(feat);
  235. }
  236. themeSource.addFeatures(labelFeatures);
  237. }
  238. //图层信息框
  239. function updateInfoView(feature) {
  240. if (!feature && popup) {
  241. removePopup();
  242. return;
  243. }
  244. var statisticsData = getStatisticsData();
  245. var contentHTML = "<table><tbody><tr>" +
  246. "<td><div style='margin-left: 15px'>" +
  247. "<table><tbody><tr>" +
  248. "<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>" +
  249. "<td style='padding-right: 20px;'></td>" +
  250. "<td>" +
  251. "<div id='textID' style='text-align: left;font-size: 19px;text-shadow: 1px 1px 0 #ffffff;'>" + feature.attributes.quality + "</div>" +
  252. "<div style='font-size:10px;width:150px;'>" + feature.attributes.time_point + "</div>" +
  253. "<div style=' font-weight:lighter; font-size:14px;'>" + resources.text_currentCity + ":" + feature.attributes.area + "</div>" +
  254. "</td>" +
  255. "</tr> </tbody></table>" +
  256. "<table style='width:100%;font-size: 10px;border: 0 solid black;padding: 0;margin: 0;border-spacing: 0;'>" +
  257. "<tbody>" +
  258. "<tr>" +
  259. "<td style='font-weight:bold;width:45px;'></td><td style='font-weight:bold;width:51px;' align='center' nowrap='true'>Current</td>" +
  260. "<td style=' font-weight:bold;width:49px;' align='center' nowrap='true'>Min</td>" +
  261. "<td style='font-weight:bold;width:49px;' align='center' nowrap='true'>Max</td> " +
  262. "</tr>" +
  263. "<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>" +
  264. "<td style='font-size:11px;' align='center'>" + feature.attributes.pm2_5 + "</td>" +
  265. "<td style='color:#0086c8;font-size:11px;' align='center'>" + statisticsData.minNum + "</td>" +
  266. "<td style='color:#ce3c3a;font-size:11px;' align='center'>" + statisticsData.maxNum + "</td>" +
  267. "</tr>" +
  268. "<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>" +
  269. "<td style='font-size:11px;' align='center'>" + feature.attributes.pm10 + "</td>" +
  270. "<td style='color:#0086c8;font-size:11px;' align='center'>" + statisticsData.minpm10 + "</td>" +
  271. "<td style='color:#ce3c3a;font-size:11px;' align='center'>" + statisticsData.maxpm10 + "</td>" +
  272. "</tr>" +
  273. "<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>" +
  274. "<td style='font-size:11px;' align='center'>" + feature.attributes.o3 + "</td>" +
  275. "<td style='color:#0086c8;font-size:11px;' align='center'>" + statisticsData.minO3 + "</td>" +
  276. "<td style='color:#ce3c3a;font-size:11px;' align='center'>" + statisticsData.maxO3 + "</td></td>" +
  277. "</tr>" +
  278. "<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>" +
  279. "<td style='font-size:11px;' align='center'>" + feature.attributes.so2 + "</td>" +
  280. "<td style='color:#0086c8;font-size:11px;' align='center'>" + statisticsData.minSO2 + "</td>" +
  281. "<td style='color:#ce3c3a;font-size:11px;' align='center'>" + statisticsData.maxSO2 + "</td></td>" +
  282. "</tr>" +
  283. "<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>" +
  284. "<td style='font-size:11px;' align='center'>" + feature.attributes.no2 + "</td>" +
  285. "<td style='color:#0086c8;font-size:11px;' align='center'>" + statisticsData.minNO2 + "</td>" +
  286. "<td style='color:#ce3c3a;font-size:11px;' align='center'>" + statisticsData.maxNO2 + "</td></td>" +
  287. "</tr></tbody> </table></div></td></tr></tbody> </table>";
  288. var latLng = getLatLng(feature.attributes.lonLat);
  289. popupContent.innerHTML = contentHTML;
  290. popup.setPosition(latLng);
  291. popup.setOffset([0, -190]);
  292. //设置弹框内容颜色
  293. var groups = themeSource.styleGroups;
  294. for (var i = 0; i < groups.length; i++) {
  295. if (feature.attributes.aqi >= groups[0].start && feature.attributes.aqi < groups[0].end) {
  296. setColor("#6ACD06");
  297. }
  298. else if (feature.attributes.aqi >= groups[1].start && feature.attributes.aqi < groups[1].end) {
  299. setColor("#FBD12A");
  300. }
  301. else if (feature.attributes.aqi >= groups[2].start && feature.attributes.aqi < groups[2].end) {
  302. setColor("#FE8800");
  303. }
  304. else if (feature.attributes.aqi >= groups[3].start && feature.attributes.aqi < groups[3].end) {
  305. setColor("#FF0000");
  306. }
  307. else if (feature.attributes.aqi >= groups[4].start && feature.attributes.aqi < groups[4].end) {
  308. setColor("#CC0000");
  309. }
  310. else if (feature.attributes.aqi >= groups[5].start && feature.attributes.aqi < groups[5].end) {
  311. setColor("#960453");
  312. }
  313. }
  314. function setColor(color) {
  315. document.getElementById("contentID").style.backgroundColor = color;
  316. document.getElementById("textID").style.color = color;
  317. }
  318. function getLatLng(latLng) {
  319. var latLng = latLng.split(",");
  320. return [parseFloat(latLng[0]), parseFloat(latLng[1])]
  321. }
  322. }
  323. function getStatisticsData() {
  324. if (this.statisticsData) {
  325. return this.statisticsData;
  326. }
  327. //遍历数组,获取单个属性。组成新的数组
  328. var pm25 = [], pm10s = [], o3s = [], so2s = [], no2s = [];
  329. for (var i = 0; i < themeData.length; i++) {
  330. pm10s.push(themeData[i].pm2_5);
  331. pm25.push(themeData[i].pm10);
  332. o3s.push(themeData[i].o3);
  333. so2s.push(themeData[i].so2);
  334. no2s.push(themeData[i].no2);
  335. }
  336. //获取单个属性的最大最小值
  337. this.statisticsData = {
  338. maxNum: Math.max.apply(Math, pm25),
  339. minNum: Math.min.apply(Math, pm25),
  340. maxpm10: Math.max.apply(Math, pm10s),
  341. minpm10: Math.min.apply(Math, pm10s),
  342. maxO3: Math.max.apply(Math, o3s),
  343. minO3: Math.min.apply(Math, o3s),
  344. maxSO2: Math.max.apply(Math, so2s),
  345. minSO2: Math.min.apply(Math, so2s),
  346. maxNO2: Math.max.apply(Math, no2s),
  347. minNO2: Math.min.apply(Math, no2s)
  348. };
  349. return this.statisticsData;
  350. }
  351. function handleMouseOver(e) {
  352. if (e.target && e.target.refDataID) {
  353. var fid = e.target.refDataID;
  354. var fea = themeSource.getFeatureById(fid);
  355. if (fea) {
  356. updateInfoView(fea);
  357. }
  358. } else {
  359. removePopup();
  360. }
  361. }
  362. function removePopup() {
  363. popup.setPosition(undefined);
  364. closer.blur();
  365. }
  366. </script>
  367. </body>
  368. </html>