03_themeLabel.html 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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_themeLabel"></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="title" style="position:absolute;top: 10px;text-align:center;width:100%;z-index: 10;color: #f7931e" data-i18n="resources.text_popThemeLayer"></div>
  13. <div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
  14. <script type="text/javascript" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
  15. <span id="show"></span>
  16. <script type="text/javascript">
  17. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  18. var attribution = "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
  19. "with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
  20. " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ";
  21. var dataUrl = host + "/iserver/services/map-china400/rest/maps/China";
  22. var map = new mapboxgl.Map({
  23. container: 'map',
  24. style: {
  25. "version": 8,
  26. "sources": {
  27. "raster-tiles": {
  28. "attribution": attribution,
  29. "type": "raster",
  30. "tiles": [host + '/iserver/services/map-china400/rest/maps/China/zxyTileImage.png?prjCoordSys='+encodeURIComponent('{"epsgCode":3857}')+'&z={z}&x={x}&y={y}'],
  31. "tileSize": 256,
  32. },
  33. },
  34. "layers": [{
  35. "id": "simple-tiles",
  36. "type": "raster",
  37. "source": "raster-tiles",
  38. "minzoom": 0,
  39. "maxzoom": 22
  40. }]
  41. },
  42. center: [117, 37],
  43. zoom: 3
  44. });
  45. map.addControl(new mapboxgl.NavigationControl(), 'top-left');
  46. map.addControl(new mapboxgl.supermap.LogoControl(), 'bottom-right');
  47. function createTheme() {
  48. var style1, style2, style3;
  49. style1 = new SuperMap.ServerTextStyle({
  50. fontHeight: 4,
  51. foreColor: new SuperMap.ServerColor(0, 0, 0),
  52. });
  53. style2 = new SuperMap.ServerTextStyle({
  54. fontHeight: 4,
  55. foreColor: new SuperMap.ServerColor(155, 30, 45),
  56. });
  57. style3 = new SuperMap.ServerTextStyle({
  58. fontHeight: 4,
  59. foreColor: new SuperMap.ServerColor(30, 45, 155),
  60. });
  61. var themeLabelItem1, themeLabelItem2, themeLabelItem3;
  62. themeLabelItem1 = new SuperMap.ThemeLabelItem({
  63. start: 300,//110000,
  64. end: 3508,//350000,
  65. style: style1
  66. });
  67. themeLabelItem2 = new SuperMap.ThemeLabelItem({
  68. start: 3508,//350000,
  69. end: 5508,//550000,
  70. style: style2
  71. });
  72. themeLabelItem3 = new SuperMap.ThemeLabelItem({
  73. start: 5508,//550000,
  74. end: 10724,//820000,
  75. style: style3
  76. });
  77. var themeLabel = new SuperMap.ThemeLabel({
  78. labelExpression: "NAME",
  79. rangeExpression: "pop_2014",
  80. numericPrecision: 0,
  81. items: [themeLabelItem1, themeLabelItem2, themeLabelItem3],
  82. background: new SuperMap.ThemeLabelBackground({
  83. backStyle: new SuperMap.ServerStyle({
  84. fillForeColor: new SuperMap.ServerColor(179, 209, 193),
  85. fillOpaqueRate: 60,
  86. lineWidth: 0.1
  87. }),
  88. labelBackShape: "RECT"
  89. })
  90. });
  91. var themeParameters = new SuperMap.ThemeParameters({
  92. themes: [themeLabel],
  93. datasetNames: ["China_Province_pg"],
  94. dataSourceNames: ["China"]
  95. });
  96. new mapboxgl.supermap.ThemeService(dataUrl).getThemeInfo(themeParameters, function (serviceResult) {
  97. var result = serviceResult.result;
  98. if (result && result.newResourceID) {
  99. map.addSource("theme", {
  100. "type": 'raster',
  101. "tiles": [host + '/iserver/services/map-china400/rest/maps/China/zxyTileImage.png?z={z}&x={x}&y={y}&transparent=true&cacheEnabled=false&layersID=' + result.newResourceID],
  102. "tileSize": 256,
  103. });
  104. map.addLayer({
  105. "id": "themeLayer",
  106. "type": "raster",
  107. "source": "theme",
  108. });
  109. }
  110. })
  111. }
  112. map.on('load', function () {
  113. createTheme();
  114. });
  115. </script>
  116. </body>
  117. </html>