rangeThemeLayer.html 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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_popDensityRange"></title>
  9. <style type="text/css">
  10. .legendItemHeader,
  11. .legendItemValue {
  12. width: 120px;
  13. height: 18px;
  14. font-size: 14px;
  15. }
  16. </style>
  17. </head>
  18. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  19. <div id="map" style="width: 100%;height:100%">
  20. <div style="z-index: 100;position: relative;width: 272px;float:right">
  21. <div id="infoBox" class="panel panel-primary infoPane"
  22. style="width:272px;margin-top: 250px;position: absolute;font-size:14px;display: none;float:right">
  23. <div class="panel-heading">
  24. <h5 class='panel-title text-center' data-i18n="resources.text_attributeTable"></h5>
  25. </div>
  26. <div id="infoContent" class="panel-body content">
  27. </div>
  28. </div>
  29. <div class="panel panel-primary legend" style="width:272px;margin-top: 400px;position: absolute;float:right">
  30. <div id="mapLegend" class="panel-heading">
  31. <h5 class='panel-title text-center'>
  32. <span data-i18n="resources.text_legend"></span>
  33. </h5>
  34. </div>
  35. <div class="panel-body text-center">
  36. <table>
  37. <tr>
  38. <td class="legendItemHeader" data-i18n="resources.text_populationDensity"></td>
  39. <td class="legendItemValue" data-i18n="resources.text_color"></td>
  40. </tr>
  41. <tr>
  42. <td class="legendItemHeader">0 - 0.02</td>
  43. <td class="legendItemValue" style="background: #FDE2CA"></td>
  44. </tr>
  45. <tr>
  46. <td class="legendItemHeader">0.02 - 0.04</td>
  47. <td class="legendItemValue" style="background: #FACE9C"></td>
  48. </tr>
  49. <tr>
  50. <td class="legendItemHeader">0.04 - 0.06</td>
  51. <td class="legendItemValue" style="background: #F09C42"></td>
  52. </tr>
  53. <tr>
  54. <td class="legendItemHeader">0.06 - 0.1</td>
  55. <td class="legendItemValue" style="background: #D0770B"></td>
  56. </tr>
  57. <tr>
  58. <td class="legendItemHeader">0.1 - 0.2</td>
  59. <td class="legendItemValue" style="background: #945305"></td>
  60. </tr>
  61. </table>
  62. </div>
  63. </div>
  64. </div>
  65. </div>
  66. <script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
  67. <script type="text/javascript" src="../../dist/ol/include-ol.js"></script>
  68. <script type="text/javascript">
  69. var map, themeSource
  70. baseUrl = (window.isLocal ? window.server : "https://iserver.supermap.io") + "/iserver/services/map-jingjin/rest/maps/京津地区地图",
  71. url2 = (window.isLocal ? window.server : "https://iserver.supermap.io") + "/iserver/services/data-jingjin/rest/data",
  72. extent = [104.07, 30.54, 119.51, 42.31];
  73. new ol.supermap.MapService(baseUrl).getMapInfo(function (serviceResult) {
  74. var mapJSONObj = serviceResult.result;
  75. map = new ol.Map({
  76. target: 'map',
  77. controls: ol.control.defaults({attributionOptions: {collapsed: false}})
  78. .extend([new ol.supermap.control.Logo()]),
  79. view: new ol.View({
  80. center: [116.85, 39.79],
  81. zoom: 8,
  82. projection: "EPSG:4326",
  83. multiWorld: true
  84. })
  85. });
  86. var options = ol.source.TileSuperMapRest.optionsFromMapJSON(baseUrl, mapJSONObj);
  87. var layer = new ol.layer.Tile({
  88. source: new ol.source.TileSuperMapRest(options)
  89. });
  90. map.addLayer(layer);
  91. var getFeatureParam, getFeatureBySQLService, getFeatureBySQLParams;
  92. getFeatureParam = new SuperMap.FilterParameter({
  93. name: "Jingjin",
  94. attributeFilter: "SMID > -1"
  95. });
  96. getFeatureBySQLParams = new SuperMap.GetFeaturesBySQLParameters({
  97. queryParameter: getFeatureParam,
  98. toIndex: 500,
  99. datasetNames: ["Jingjin:BaseMap_R"]
  100. });
  101. getFeatureBySQLService = new SuperMap.GetFeaturesBySQLService(url2, {
  102. format: SuperMap.DataFormat.ISERVER,
  103. eventListeners: {"processCompleted": processCompleted, "processFailed": processFailed}
  104. });
  105. getFeatureBySQLService.processAsync(getFeatureBySQLParams);
  106. });
  107. function processCompleted(getFeaturesEventArgs) {
  108. var result = getFeaturesEventArgs.result;
  109. if (result && result.features) {
  110. addThemeLayer();
  111. themeSource.addFeatures(result.features);
  112. //显示图例
  113. document.getElementById("mapLegend").style.display = "block";
  114. }
  115. }
  116. function addThemeLayer() {
  117. themeSource = new ol.source.Range("ThemeLayer",
  118. {
  119. map: map,
  120. attributions: " ",
  121. style: {
  122. shadowBlur: 16,
  123. shadowColor: "#000000",
  124. fillColor: "#FFFFFF"
  125. },
  126. isHoverAble: true,
  127. highlightStyle: {
  128. stroke: true,
  129. strokeWidth: 4,
  130. strokeColor: 'blue',
  131. fillColor: "#00EEEE",
  132. fillOpacity: 0.8
  133. },
  134. themeField: "POP_DENSITY99",
  135. styleGroups: [
  136. {
  137. start: 0,
  138. end: 0.02,
  139. style: {
  140. color: '#FDE2CA'
  141. }
  142. },
  143. {
  144. start: 0.02,
  145. end: 0.04,
  146. style: {
  147. color: '#FACE9C'
  148. }
  149. },
  150. {
  151. start: 0.04,
  152. end: 0.06,
  153. style: {
  154. color: '#F09C42'
  155. }
  156. },
  157. {
  158. start: 0.06,
  159. end: 0.1,
  160. style: {
  161. color: '#D0770B'
  162. }
  163. },
  164. {
  165. start: 0.1,
  166. end: 0.2,
  167. style: {
  168. color: '#945305'
  169. }
  170. }]
  171. });
  172. //专题图层 mousemove 事件
  173. themeSource.on('mousemove', function (e) {
  174. if (e.target && e.target.refDataID) {
  175. document.getElementById("infoBox").style.display = "block";
  176. var fid = e.target.refDataID;
  177. var fea = themeSource.getFeatureById(fid);
  178. if (fea) {
  179. document.getElementById("infoContent").innerHTML = "";
  180. document.getElementById("infoContent").innerHTML += "ID: " + fea.attributes.SMID + "<br/>";
  181. document.getElementById("infoContent").innerHTML += resources.text_districtName + fea.attributes.NAME + "<br/>";
  182. document.getElementById("infoContent").innerHTML += resources.text_densityOfPopulation + parseFloat(fea.attributes.POP_DENSITY99).toFixed(5) + "<br/>";
  183. }
  184. }
  185. else {
  186. document.getElementById("infoContent").innerHTML = "";
  187. document.getElementById("infoBox").style.display = "none";
  188. }
  189. });
  190. var pointerInteraction = new ol.interaction.Pointer({
  191. handleMoveEvent: function (event) {
  192. themeSource.fire('mousemove', event);
  193. }
  194. });
  195. map.addInteraction(pointerInteraction);
  196. var themeLayer = new ol.layer.Image({
  197. source: themeSource
  198. });
  199. themeLayer.setOpacity(0.8);
  200. map.addLayer(themeLayer);
  201. }
  202. function processFailed(e) {
  203. widgets.alert.showAlert(e.error.errorMsg, false);
  204. }
  205. </script>
  206. </body>
  207. </html>