03_themeLabel.html 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. <script type="text/javascript" src="../../dist/ol/include-ol.js"></script>
  11. </head>
  12. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%; position: absolute;top: 0;">
  13. <div id="map" style="width: 100%;height:100%"></div>
  14. <script type="text/javascript">
  15. var map, themeLayer, options
  16. url = (window.isLocal ? window.server : "https://iserver.supermap.io")+"/iserver/services/map-world/rest/maps/World";
  17. new ol.supermap.MapService(url).getMapInfo(function (serviceResult) {
  18. var mapJSONObj = serviceResult.result;
  19. map = new ol.Map({
  20. target: 'map',
  21. controls: ol.control.defaults({attributionOptions: {collapsed: false}})
  22. .extend([new ol.supermap.control.Logo()]),
  23. view: new ol.View({
  24. center: [0, 0],
  25. zoom: 2,
  26. projection: "EPSG:4326",
  27. multiWorld: true
  28. })
  29. });
  30. options = ol.source.TileSuperMapRest.optionsFromMapJSON(url, mapJSONObj);
  31. var layer = new ol.layer.Tile({
  32. source: new ol.source.TileSuperMapRest(options)
  33. });
  34. map.addLayer(layer);
  35. createTheme();
  36. });
  37. function createTheme() {
  38. var style1, style2, style3;
  39. style1 = new SuperMap.ServerTextStyle({
  40. fontHeight: 4,
  41. foreColor: new SuperMap.ServerColor(100, 20, 50),
  42. sizeFixed: true,
  43. bold: true
  44. });
  45. style2 = new SuperMap.ServerTextStyle({
  46. fontHeight: 4,
  47. foreColor: new SuperMap.ServerColor(250, 0, 0),
  48. sizeFixed: true,
  49. bold: true
  50. });
  51. style3 = new SuperMap.ServerTextStyle({
  52. fontHeight: 4,
  53. foreColor: new SuperMap.ServerColor(93, 95, 255),
  54. sizeFixed: true,
  55. bold: true
  56. });
  57. var themeLabelItem1, themeLabelItem2, themeLabelItem3, themeLabelItem4, themeLabelItem5, themeLabelItem6;
  58. themeLabelItem1 = new SuperMap.ThemeLabelItem({
  59. start: 0.0,
  60. end: 7800000,
  61. style: style1
  62. });
  63. themeLabelItem2 = new SuperMap.ThemeLabelItem({
  64. start: 7800000,
  65. end: 15000000,
  66. style: style2
  67. });
  68. themeLabelItem3 = new SuperMap.ThemeLabelItem({
  69. start: 15000000,
  70. end: 30000000,
  71. style: style3
  72. });
  73. themeLabelItem4 = new SuperMap.ThemeLabelItem({
  74. start: 0.0,
  75. end: 55,
  76. style: style1
  77. });
  78. themeLabelItem5 = new SuperMap.ThemeLabelItem({
  79. start: 55,
  80. end: 109,
  81. style: style2
  82. });
  83. themeLabelItem6 = new SuperMap.ThemeLabelItem({
  84. start: 109,
  85. end: 300,
  86. style: style3
  87. });
  88. var themeLabel = new SuperMap.ThemeLabel({
  89. matrixCells: [
  90. [new SuperMap.LabelThemeCell({
  91. themeLabel: new SuperMap.ThemeLabel({
  92. labelExpression: "CAPITAL",
  93. rangeExpression: "SmID",
  94. numericPrecision: 0,
  95. items: [themeLabelItem4, themeLabelItem5, themeLabelItem6]
  96. })
  97. })],
  98. [new SuperMap.LabelThemeCell({
  99. themeLabel: new SuperMap.ThemeLabel({
  100. labelExpression: "CAP_POP",
  101. rangeExpression: "CAP_POP",
  102. numericPrecision: 0,
  103. items: [themeLabelItem1, themeLabelItem2, themeLabelItem3]
  104. })
  105. })]
  106. ],
  107. background: new SuperMap.ThemeLabelBackground({
  108. backStyle: new SuperMap.ServerStyle({
  109. fillForeColor: new SuperMap.ServerColor(179, 209, 193),
  110. fillOpaqueRate: 60,
  111. lineWidth: 0.1
  112. }),
  113. labelBackShape: "RECT"
  114. })
  115. });
  116. var themeParameters = new SuperMap.ThemeParameters({
  117. themes: [themeLabel],
  118. datasetNames: ["Capitals"],
  119. dataSourceNames: ["World"]
  120. });
  121. new ol.supermap.ThemeService(url).getThemeInfo(themeParameters, function (serviceResult) {
  122. var result = serviceResult.result;
  123. if (result && result.newResourceID) {
  124. themeLayer = new ol.layer.Tile({
  125. source: new ol.source.TileSuperMapRest({
  126. url: url,
  127. noWrap: true,
  128. cacheEnabled: false,
  129. transparent: true,
  130. layersID: result.newResourceID,
  131. transparent: true
  132. })
  133. });
  134. map.addLayer(themeLayer);
  135. }
  136. });
  137. }
  138. </script>
  139. </body>
  140. </html>