components_labeltheme_vue.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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. <title data-i18n="resources.title_componentsLabelTheme_Vue"></title>
  9. <style>
  10. #main {
  11. margin: 0 auto;
  12. width: 100%;
  13. height: 100%;
  14. }
  15. </style>
  16. </head>
  17. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  18. <div id="main">
  19. <sm-web-map :map-options="mapOptions" @load="mapIsLoaded">
  20. <sm-label-theme-layer
  21. :options="themeOptions"
  22. layer-name="LabelThemeLayer"
  23. :data="features"
  24. @load="layerLoaded"
  25. v-show="!!features.length"
  26. >
  27. </sm-label-theme-layer>
  28. </sm-web-map>
  29. </div>
  30. <script type="text/javascript" include="vue,bootstrap" src="../js/include-web.js"></script>
  31. <script
  32. include="iclient-mapboxgl-vue,mapbox-gl-enhance"
  33. src="../../dist/mapboxgl/include-mapboxgl.js"
  34. ></script>
  35. <script type="text/javascript" src="../data/themeLableData.js"></script>
  36. <script>
  37. new Vue({
  38. el: '#main',
  39. data() {
  40. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  41. var attribution =
  42. "<a href='https://www.mapbtyx.com/about/maps/' target='_blank'>© Mapbox </a>" +
  43. " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
  44. " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ";
  45. var features = [];
  46. var feat;
  47. for (var i = 0; i < themeData.length; i++) {
  48. var lonlat = themeData[i].lonLat.split(',');
  49. var lng = parseFloat(lonlat[0]);
  50. var lat = parseFloat(lonlat[1]);
  51. var text = themeData[i].aqi;
  52. feat = new mapboxgl.supermap.ThemeFeature([lng, lat, text], themeData[i]);
  53. features.push(feat);
  54. }
  55. return {
  56. mapOptions: {
  57. container: 'map',
  58. style: {
  59. version: 8,
  60. sources: {
  61. 'raster-tiles': {
  62. attribution: attribution,
  63. type: 'raster',
  64. tiles: [host + '/iserver/services/map-china400/rest/maps/China/zxyTileImage.png?z={z}&x={x}&y={y}'],
  65. tileSize: 256
  66. }
  67. },
  68. layers: [
  69. {
  70. id: 'simple-tiles',
  71. type: 'raster',
  72. source: 'raster-tiles',
  73. minzoom: 0,
  74. maxzoom: 22
  75. }
  76. ]
  77. },
  78. center: [116.4, 39.79],
  79. zoom: 3
  80. },
  81. features,
  82. themeOptions: {
  83. // map: map,//该可选参数将在下个版本遗弃
  84. attributions: ' ',
  85. style: new SuperMap.ThemeStyle({
  86. labelRect: true,
  87. fontColor: '#000000',
  88. fontWeight: 'bolder',
  89. fontSize: '18px',
  90. fill: true,
  91. fillColor: '#FFFFFF',
  92. fillOpacity: 1,
  93. stroke: false,
  94. strokeColor: '#8B7B8B'
  95. }),
  96. themeField: 'aqi',
  97. styleGroups: [
  98. {
  99. start: 0,
  100. end: 51,
  101. style: {
  102. fillColor: '#6ACD06',
  103. fontSize: '17px'
  104. }
  105. },
  106. {
  107. start: 51,
  108. end: 101,
  109. style: {
  110. fillColor: '#FBD12A',
  111. fontSize: '19px'
  112. }
  113. },
  114. {
  115. start: 101,
  116. end: 151,
  117. style: {
  118. fillColor: '#FE8800',
  119. fontSize: '22px'
  120. }
  121. },
  122. {
  123. start: 151,
  124. end: 201,
  125. style: {
  126. fillColor: '#FF0000',
  127. fontSize: '24px'
  128. }
  129. },
  130. {
  131. start: 201,
  132. end: 301,
  133. style: {
  134. fillColor: '#CC0000',
  135. fontSize: '26px'
  136. }
  137. },
  138. {
  139. start: 301,
  140. end: 601,
  141. style: {
  142. fillColor: '#960453',
  143. fontSize: '28px'
  144. }
  145. }
  146. ]
  147. }
  148. };
  149. },
  150. methods: {
  151. mapIsLoaded(e) {
  152. this.map = e.map;
  153. },
  154. updateInfoView(feature, themeLayer) {
  155. if (!feature && this.popup) {
  156. this.removePopup();
  157. return;
  158. }
  159. if (!this.popup) {
  160. this.popup = new mapboxgl.Popup({ maxWidth: 600 });
  161. }
  162. var statisticsData = this.getStatisticsData();
  163. var contentHTML =
  164. '<table><tbody><tr>' +
  165. "<td><div style='margin-left: 15px'>" +
  166. '<table><tbody><tr>' +
  167. "<td><div id='contentID' style='margin-top: 2px;margin-bottom: 2px;width:65px;height:60px;line-height:60px;text-align: center;font-size:35px;color: #ffffff;'>" +
  168. feature.attributes.aqi +
  169. '</div></td>' +
  170. "<td style='padding-right: 20px;'></td>" +
  171. '<td>' +
  172. "<div id='textID' style='text-align: left;font-size: 19px;text-shadow: 1px 1px 0 #ffffff;'>" +
  173. feature.attributes.quality +
  174. '</div>' +
  175. "<div style='font-size:10px;width:150px;'>" +
  176. feature.attributes.time_point +
  177. '</div>' +
  178. "<div style=' font-weight:lighter; font-size:14px;'>" +
  179. resources.text_currentCity +
  180. ':' +
  181. feature.attributes.area +
  182. '</div>' +
  183. '</td>' +
  184. '</tr> </tbody></table>' +
  185. "<table style='width:100%;font-size: 10px;border: 0 solid black;padding: 0;margin: 0;border-spacing: 0;'>" +
  186. '<tbody>' +
  187. '<tr>' +
  188. "<td style='font-weight:bold;width:45px;'></td><td style='font-weight:bold;width:51px;' align='center' nowrap='true'>Current</td>" +
  189. "<td style=' font-weight:bold;width:49px;' align='center' nowrap='true'>Min</td>" +
  190. "<td style='font-weight:bold;width:49px;' align='center' nowrap='true'>Max</td> " +
  191. '</tr>' +
  192. "<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>" +
  193. "<td style='font-size:11px;' align='center'>" +
  194. feature.attributes.pm2_5 +
  195. '</td>' +
  196. "<td style='color:#0086c8;font-size:11px;' align='center'>" +
  197. statisticsData.minNum +
  198. '</td>' +
  199. "<td style='color:#ce3c3a;font-size:11px;' align='center'>" +
  200. statisticsData.maxNum +
  201. '</td>' +
  202. '</tr>' +
  203. "<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>" +
  204. "<td style='font-size:11px;' align='center'>" +
  205. feature.attributes.pm10 +
  206. '</td>' +
  207. "<td style='color:#0086c8;font-size:11px;' align='center'>" +
  208. statisticsData.minpm10 +
  209. '</td>' +
  210. "<td style='color:#ce3c3a;font-size:11px;' align='center'>" +
  211. statisticsData.maxpm10 +
  212. '</td>' +
  213. '</tr>' +
  214. "<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>" +
  215. "<td style='font-size:11px;' align='center'>" +
  216. feature.attributes.o3 +
  217. '</td>' +
  218. "<td style='color:#0086c8;font-size:11px;' align='center'>" +
  219. statisticsData.minO3 +
  220. '</td>' +
  221. "<td style='color:#ce3c3a;font-size:11px;' align='center'>" +
  222. statisticsData.maxO3 +
  223. '</td></td>' +
  224. '</tr>' +
  225. "<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>" +
  226. "<td style='font-size:11px;' align='center'>" +
  227. feature.attributes.so2 +
  228. '</td>' +
  229. "<td style='color:#0086c8;font-size:11px;' align='center'>" +
  230. statisticsData.minSO2 +
  231. '</td>' +
  232. "<td style='color:#ce3c3a;font-size:11px;' align='center'>" +
  233. statisticsData.maxSO2 +
  234. '</td></td>' +
  235. '</tr>' +
  236. "<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>" +
  237. "<td style='font-size:11px;' align='center'>" +
  238. feature.attributes.no2 +
  239. '</td>' +
  240. "<td style='color:#0086c8;font-size:11px;' align='center'>" +
  241. statisticsData.minNO2 +
  242. '</td>' +
  243. "<td style='color:#ce3c3a;font-size:11px;' align='center'>" +
  244. statisticsData.maxNO2 +
  245. '</td></td>' +
  246. '</tr></tbody> </table></div></td></tr></tbody> </table>';
  247. var latLng = this.getLatLng(feature.attributes.lonLat);
  248. this.popup
  249. .setLngLat(latLng)
  250. .setHTML(contentHTML)
  251. .addTo(this.map);
  252. //设置弹框内容颜色
  253. var groups = themeLayer.styleGroups;
  254. for (var i = 0; i < groups.length; i++) {
  255. if (feature.attributes.aqi >= groups[0].start && feature.attributes.aqi < groups[0].end) {
  256. this.setColor('#6ACD06');
  257. } else if (feature.attributes.aqi >= groups[1].start && feature.attributes.aqi < groups[1].end) {
  258. this.setColor('#FBD12A');
  259. } else if (feature.attributes.aqi >= groups[2].start && feature.attributes.aqi < groups[2].end) {
  260. this.setColor('#FE8800');
  261. } else if (feature.attributes.aqi >= groups[3].start && feature.attributes.aqi < groups[3].end) {
  262. this.setColor('#FF0000');
  263. } else if (feature.attributes.aqi >= groups[4].start && feature.attributes.aqi < groups[4].end) {
  264. this.setColor('#CC0000');
  265. } else if (feature.attributes.aqi >= groups[5].start && feature.attributes.aqi < groups[5].end) {
  266. this.setColor('#960453');
  267. }
  268. }
  269. },
  270. getStatisticsData() {
  271. if (this.statisticsData) {
  272. return this.statisticsData;
  273. }
  274. //遍历数组,获取单个属性。组成新的数组
  275. var pm25 = [],
  276. pm10s = [],
  277. o3s = [],
  278. so2s = [],
  279. no2s = [];
  280. for (var i = 0; i < themeData.length; i++) {
  281. pm10s.push(themeData[i].pm2_5);
  282. pm25.push(themeData[i].pm10);
  283. o3s.push(themeData[i].o3);
  284. so2s.push(themeData[i].so2);
  285. no2s.push(themeData[i].no2);
  286. }
  287. //获取单个属性的最大最小值
  288. this.statisticsData = {
  289. maxNum: Math.max.apply(Math, pm25),
  290. minNum: Math.min.apply(Math, pm25),
  291. maxpm10: Math.max.apply(Math, pm10s),
  292. minpm10: Math.min.apply(Math, pm10s),
  293. maxO3: Math.max.apply(Math, o3s),
  294. minO3: Math.min.apply(Math, o3s),
  295. maxSO2: Math.max.apply(Math, so2s),
  296. minSO2: Math.min.apply(Math, so2s),
  297. maxNO2: Math.max.apply(Math, no2s),
  298. minNO2: Math.min.apply(Math, no2s)
  299. };
  300. return this.statisticsData;
  301. },
  302. setColor(color) {
  303. document.getElementById('contentID').style.backgroundColor = color;
  304. document.getElementById('textID').style.color = color;
  305. },
  306. getLatLng(latLng) {
  307. var latLng = latLng.split(',');
  308. return [parseFloat(latLng[0]), parseFloat(latLng[1])];
  309. },
  310. layerLoaded(themeLayer) {
  311. themeLayer.on('mousemove', function(e) {
  312. this.handleMouseOver(themeLayer, e);
  313. }.bind(this));
  314. },
  315. handleMouseOver(themeLayer, e) {
  316. if (e.target && e.target.refDataID) {
  317. var fid = e.target.refDataID;
  318. var fea = themeLayer.getFeatureById(fid);
  319. if (fea) {
  320. this.updateInfoView(fea, themeLayer);
  321. }
  322. } else {
  323. this.removePopup();
  324. }
  325. },
  326. removePopup() {
  327. this.popup && this.popup.remove(this.map);
  328. }
  329. }
  330. });
  331. </script>
  332. </body>
  333. </html>