03_themeUnique.html 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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_themeUnique"></title>
  9. <script type="text/javascript" src="../js/include-web.js"></script>
  10. </head>
  11. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  12. <div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
  13. <script type="text/javascript" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
  14. <span id="show"></span>
  15. <script type="text/javascript">
  16. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  17. var attribution = "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
  18. "with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
  19. " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ";
  20. var dataUrl = host + "/iserver/services/map-china400/rest/maps/China";
  21. var map = new mapboxgl.Map({
  22. container: 'map',
  23. style: {
  24. "version": 8,
  25. "sources": {
  26. "raster-tiles": {
  27. "attribution": attribution,
  28. "type": "raster",
  29. "tiles": [host + '/iserver/services/map-china400/rest/maps/China/zxyTileImage.png?prjCoordSys='+encodeURIComponent('{"epsgCode":3857}')+'&z={z}&x={x}&y={y}'],
  30. "tileSize": 256,
  31. },
  32. },
  33. "layers": [{
  34. "id": "simple-tiles",
  35. "type": "raster",
  36. "source": "raster-tiles",
  37. "minzoom": 0,
  38. "maxzoom": 22
  39. }]
  40. },
  41. center: [110, 37],
  42. zoom: 3
  43. });
  44. map.addControl(new mapboxgl.NavigationControl(), 'top-left');
  45. map.addControl(new mapboxgl.supermap.LogoControl(), 'bottom-right');
  46. function createTheme() {
  47. var style1, style2, style3, style4, style5, style6;
  48. style1 = new SuperMap.ServerStyle({
  49. fillForeColor: new SuperMap.ServerColor(248, 203, 249),
  50. lineColor: new SuperMap.ServerColor(255, 255, 255),
  51. lineWidth: 0.1
  52. });
  53. style2 = new SuperMap.ServerStyle({
  54. fillForeColor: new SuperMap.ServerColor(196, 255, 189),
  55. lineColor: new SuperMap.ServerColor(255, 255, 255),
  56. lineWidth: 0.1
  57. });
  58. style3 = new SuperMap.ServerStyle({
  59. fillForeColor: new SuperMap.ServerColor(255, 173, 173),
  60. lineColor: new SuperMap.ServerColor(255, 255, 255),
  61. lineWidth: 0.1
  62. });
  63. style4 = new SuperMap.ServerStyle({
  64. fillForeColor: new SuperMap.ServerColor(255, 239, 168),
  65. lineColor: new SuperMap.ServerColor(255, 255, 255),
  66. lineWidth: 0.1
  67. });
  68. style5 = new SuperMap.ServerStyle({
  69. fillForeColor: new SuperMap.ServerColor(173, 209, 255),
  70. lineColor: new SuperMap.ServerColor(255, 255, 255),
  71. lineWidth: 0.1
  72. });
  73. style6 = new SuperMap.ServerStyle({
  74. fillForeColor: new SuperMap.ServerColor(132, 164, 232),
  75. lineColor: new SuperMap.ServerColor(255, 255, 255),
  76. lineWidth: 0.1
  77. });
  78. var themeUniqueIteme1 = new SuperMap.ThemeUniqueItem({
  79. unique: "黑龙江省",
  80. style: style1
  81. }),
  82. themeUniqueIteme2 = new SuperMap.ThemeUniqueItem({
  83. unique: "湖北省",
  84. style: style2
  85. }),
  86. themeUniqueIteme3 = new SuperMap.ThemeUniqueItem({
  87. unique: "吉林省",
  88. style: style3
  89. }),
  90. themeUniqueIteme4 = new SuperMap.ThemeUniqueItem({
  91. unique: "内蒙古自治区",
  92. style: style4
  93. }),
  94. themeUniqueIteme5 = new SuperMap.ThemeUniqueItem({
  95. unique: "青海省",
  96. style: style5
  97. }),
  98. themeUniqueIteme6 = new SuperMap.ThemeUniqueItem({
  99. unique: "新疆维吾尔自治区",
  100. style: style6
  101. }),
  102. themeUniqueIteme7 = new SuperMap.ThemeUniqueItem({
  103. unique: "云南省",
  104. style: style1
  105. }),
  106. themeUniqueIteme8 = new SuperMap.ThemeUniqueItem({
  107. unique: "四川省",
  108. style: style4
  109. }),
  110. themeUniqueIteme9 = new SuperMap.ThemeUniqueItem({
  111. unique: "贵州省",
  112. style: style3
  113. }),
  114. themeUniqueIteme10 = new SuperMap.ThemeUniqueItem({
  115. unique: "甘肃省",
  116. style: style3
  117. }),
  118. themeUniqueIteme11 = new SuperMap.ThemeUniqueItem({
  119. unique: "宁夏回族自治区",
  120. style: style5
  121. }),
  122. themeUniqueIteme12 = new SuperMap.ThemeUniqueItem({
  123. unique: "重庆市",
  124. style: style6
  125. }),
  126. themeUniqueIteme13 = new SuperMap.ThemeUniqueItem({
  127. unique: "山东省",
  128. style: style1
  129. }),
  130. themeUniqueIteme14 = new SuperMap.ThemeUniqueItem({
  131. unique: "安徽省",
  132. style: style2
  133. }),
  134. themeUniqueIteme15 = new SuperMap.ThemeUniqueItem({
  135. unique: "江西省",
  136. style: style3
  137. }),
  138. themeUniqueIteme16 = new SuperMap.ThemeUniqueItem({
  139. unique: "浙江省",
  140. style: style4
  141. }),
  142. themeUniqueIteme17 = new SuperMap.ThemeUniqueItem({
  143. unique: "台湾省",
  144. style: style2
  145. }),
  146. themeUniqueIteme18 = new SuperMap.ThemeUniqueItem({
  147. unique: "江苏省",
  148. style: style6
  149. }),
  150. themeUniqueIteme19 = new SuperMap.ThemeUniqueItem({
  151. unique: "湖南省",
  152. style: style5
  153. }),
  154. themeUniqueIteme20 = new SuperMap.ThemeUniqueItem({
  155. unique: "河南省",
  156. style: style4
  157. }),
  158. themeUniqueIteme21 = new SuperMap.ThemeUniqueItem({
  159. unique: "河北省",
  160. style: style3
  161. }),
  162. themeUniqueIteme22 = new SuperMap.ThemeUniqueItem({
  163. unique: "福建省",
  164. style: style5
  165. }),
  166. themeUniqueIteme23 = new SuperMap.ThemeUniqueItem({
  167. unique: "广西壮族自治区",
  168. style: style6
  169. }),
  170. themeUniqueIteme24 = new SuperMap.ThemeUniqueItem({
  171. unique: "西藏自治区",
  172. style: style2
  173. }),
  174. themeUniqueIteme25 = new SuperMap.ThemeUniqueItem({
  175. unique: "广东省",
  176. style: style4
  177. }),
  178. themeUniqueIteme26 = new SuperMap.ThemeUniqueItem({
  179. unique: "山西省",
  180. style: style2
  181. }),
  182. themeUniqueIteme27 = new SuperMap.ThemeUniqueItem({
  183. unique: "陕西省",
  184. style: style1
  185. }),
  186. themeUniqueIteme28 = new SuperMap.ThemeUniqueItem({
  187. unique: "天津市",
  188. style: style5
  189. }),
  190. themeUniqueIteme29 = new SuperMap.ThemeUniqueItem({
  191. unique: "北京市",
  192. style: style2
  193. }),
  194. themeUniqueIteme30 = new SuperMap.ThemeUniqueItem({
  195. unique: "辽宁省",
  196. style: style1
  197. });
  198. var themeUniqueItemes = [
  199. themeUniqueIteme1, themeUniqueIteme2, themeUniqueIteme3, themeUniqueIteme4, themeUniqueIteme5,
  200. themeUniqueIteme6, themeUniqueIteme7, themeUniqueIteme8, themeUniqueIteme9, themeUniqueIteme10,
  201. themeUniqueIteme11, themeUniqueIteme12, themeUniqueIteme13, themeUniqueIteme14, themeUniqueIteme15,
  202. themeUniqueIteme16, themeUniqueIteme17, themeUniqueIteme18, themeUniqueIteme19, themeUniqueIteme20,
  203. themeUniqueIteme21, themeUniqueIteme22, themeUniqueIteme23, themeUniqueIteme24, themeUniqueIteme25,
  204. themeUniqueIteme26, themeUniqueIteme27, themeUniqueIteme28, themeUniqueIteme29, themeUniqueIteme30
  205. ];
  206. var themeUnique = new SuperMap.ThemeUnique({
  207. uniqueExpression: "Name",
  208. items: themeUniqueItemes,
  209. defaultStyle: style1
  210. });
  211. var themeParameters = new SuperMap.ThemeParameters({
  212. datasetNames: ["China_Province_pg"],
  213. dataSourceNames: ["China"],
  214. themes: [themeUnique]
  215. });
  216. new mapboxgl.supermap.ThemeService(dataUrl).getThemeInfo(themeParameters, function (serviceResult) {
  217. var result = serviceResult.result;
  218. if (result && result.newResourceID) {
  219. map.addSource("theme", {
  220. "type": 'raster',
  221. "tiles": [host + '/iserver/services/map-china400/rest/maps/China/zxyTileImage.png?z={z}&x={x}&y={y}&noWrap=true&transparent=true&cacheEnabled=false&layersID=' + result.newResourceID],
  222. "tileSize": 256,
  223. });
  224. map.addLayer({
  225. "id": "themeLayer",
  226. "type": "raster",
  227. "source": "theme",
  228. });
  229. }
  230. })
  231. }
  232. map.on('load', function () {
  233. createTheme();
  234. });
  235. </script>
  236. </body>
  237. </html>