components_ncp_world.html 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport" />
  9. <title>国家紧急状态</title>
  10. </head>
  11. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  12. <div id="main">
  13. <sm-web-map style="background: #081f30;" :map-options="mapOptions" @load="mapLoaded"></sm-web-map>
  14. <div id="group"></div>
  15. </div>
  16. <script type="text/javascript" include="vue" src="../js/include-web.js"></script>
  17. <script
  18. include="iclient-mapboxgl-vue,mapbox-gl-enhance"
  19. src="../../dist/mapboxgl/include-mapboxgl.js"
  20. ></script>
  21. <script src="../data/ncp//world_4326.js"></script>
  22. <script src="../data/ncp/Country_Center.js"></script>
  23. <style>
  24. #main {
  25. margin: 0 auto;
  26. width: 100%;
  27. height: 100%;
  28. }
  29. </style>
  30. <script>
  31. //数据截止时间为2020-03-26
  32. var nationalEmergencyArea = [
  33. '意大利',
  34. '西班牙',
  35. '美国',
  36. '法国',
  37. '韩国',
  38. '瑞士',
  39. '南非',
  40. '格鲁吉亚',
  41. '多米尼加',
  42. '葡萄牙',
  43. '芬兰',
  44. '澳大利亚',
  45. '萨尔瓦多',
  46. '洪都拉斯',
  47. '卢森堡',
  48. '津巴布韦',
  49. '哥伦比亚',
  50. '约旦',
  51. '纳米比亚',
  52. '斯威士兰',
  53. '苏丹',
  54. '亚美尼亚',
  55. '厄瓜多尔',
  56. '摩尔多瓦',
  57. '哥斯达黎加',
  58. '波黑',
  59. '奥地利',
  60. '塞浦路斯',
  61. '黎巴嫩',
  62. '塞尔维亚',
  63. '秘鲁',
  64. '哈萨克斯坦',
  65. '罗马尼亚',
  66. '利比亚',
  67. '保加利亚',
  68. '爱沙尼亚',
  69. '波兰',
  70. '巴拿马',
  71. '委内瑞拉',
  72. '斯洛伐克',
  73. '拉脱维亚',
  74. '阿根廷',
  75. '捷克',
  76. '匈牙利',
  77. '菲律宾',
  78. '巴勒斯坦',
  79. '危地马拉',
  80. '立陶宛',
  81. '巴布亚新几内亚',
  82. '吉尔吉斯斯坦',
  83. '摩洛哥',
  84. '萨摩亚',
  85. '汤加',
  86. '以色列',
  87. '新西兰',
  88. '安哥拉',
  89. '刚果(金)',
  90. '泰国',
  91. '科特迪瓦',
  92. '乌克兰'
  93. ];
  94. var styles = { emergencyColor: '#ef6548', defaultColor: '#002F4E' };
  95. new Vue({
  96. el: '#main',
  97. data() {
  98. var attribution =
  99. "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
  100. " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
  101. " Map Data <span>© <a href='https://www.supermapol.com/' target='_blank'>SuperMap Online</a></span> ";
  102. return {
  103. mapOptions: {
  104. container: 'map', // container id
  105. style: {
  106. version: 8,
  107. glyphs: 'https://ncov.supermapol.com/statichtml/font/{fontstack}/{range}.pbf',
  108. sources: {
  109. 'raster-tiles': {
  110. attribution: attribution,
  111. type: 'raster',
  112. tiles: [
  113. 'https://maptiles.supermapol.com/iserver/services/map-China-2/rest/maps/China_DarkBlue_Nolable'
  114. ],
  115. prjCoordSys: { epsgCode: 4326 },
  116. rasterSource: 'iserver',
  117. tileSize: 256
  118. }
  119. },
  120. layers: [
  121. {
  122. id: 'simple-tiles',
  123. type: 'raster',
  124. source: 'raster-tiles',
  125. minzoom: 0,
  126. maxzoom: 22
  127. }
  128. ]
  129. },
  130. center: [101.58, 33.11],
  131. maxZoom: 5,
  132. zoom: 2,
  133. crs: 'EPSG:4326'
  134. }
  135. };
  136. },
  137. methods: {
  138. mapLoaded(e) {
  139. this.map = e.map;
  140. this.initWorldData();
  141. this.map.addSource('world', {
  142. type: 'geojson',
  143. data: CountryData
  144. });
  145. this.map.addLayer({
  146. id: 'world',
  147. type: 'fill',
  148. source: 'world',
  149. layout: {},
  150. paint: {
  151. 'fill-color': [
  152. 'case',
  153. ['has', 'nationalEmergency'],
  154. [
  155. 'case',
  156. ['==', ['get', 'nationalEmergency'], true],
  157. styles.emergencyColor,
  158. styles.defaultColor
  159. ],
  160. styles.defaultColor
  161. ]
  162. }
  163. });
  164. this.map.addLayer({
  165. id: 'world-strokeLine',
  166. type: 'line',
  167. source: 'world',
  168. layout: {},
  169. paint: {
  170. 'line-width': 0.5,
  171. 'line-color': '#83838D',
  172. 'line-opacity': 1
  173. }
  174. });
  175. this.map.addSource('world-label', {
  176. type: 'geojson',
  177. data: CountryCenterData
  178. });
  179. this.map.addLayer({
  180. id: 'world-label',
  181. type: 'symbol',
  182. source: 'world-label',
  183. filter: ['has', 'nationalEmergency'],
  184. layout: {
  185. 'text-field': ['get', 'Country'],
  186. 'text-font': ['Microsoft YaHei Regular'],
  187. 'text-size': 12,
  188. 'text-allow-overlap': false,
  189. 'text-letter-spacing': 0
  190. },
  191. paint: {
  192. 'text-color': 'white',
  193. 'text-opacity': 1,
  194. 'text-halo-color': '#696868',
  195. 'text-halo-width': 1.5
  196. }
  197. });
  198. },
  199. initWorldData() {
  200. nationalEmergencyArea.forEach(element => {
  201. var country = CountryData.features.find(function(item) {
  202. if (
  203. findCNName(item.properties.NAME_0) === element ||
  204. findCNName(item.properties.GID_0) === element
  205. ) {
  206. item.zhName = element;
  207. return true;
  208. }
  209. return false;
  210. });
  211. if (country) {
  212. country.properties.nationalEmergency = true;
  213. }
  214. var countryCenter = CountryCenterData.features.find(function(item) {
  215. return item.properties.Country === element;
  216. });
  217. if (countryCenter) {
  218. countryCenter.properties.nationalEmergency = true;
  219. }
  220. });
  221. }
  222. }
  223. });
  224. function findCNName(enName) {
  225. for (const key in CountriesNameEn) {
  226. if (CountriesNameEn[key] === enName) return key;
  227. }
  228. return null;
  229. }
  230. </script>
  231. </body>
  232. </html>