rankSymbolThemeLayer.html 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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_rankSymbolThemeLayer"></title>
  9. <script type="text/javascript" include="bootstrap" src="../js/include-web.js"></script>
  10. <script type="text/javascript" src="../../dist/ol/include-ol.js"></script>
  11. <script src='../data/chinaConsumptionLevel.js'></script>
  12. </head>
  13. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  14. <div id="popup" class="ol-popup">
  15. <div id="popup-content"></div>
  16. </div>
  17. <div id="map" style="width:100%;height:100%"></div>
  18. <script type="text/javascript">
  19. var map, themeSource,
  20. url = (window.isLocal ? window.server : "https://iserver.supermap.io") + "/iserver/services/map-china400/rest/maps/China_4326",
  21. container = document.getElementById('popup'),
  22. content = document.getElementById('popup-content'),
  23. overlay = new ol.Overlay(({
  24. element: container,
  25. autoPan: true,
  26. autoPanAnimation: {
  27. duration: 250
  28. }
  29. }));
  30. new ol.supermap.MapService(url).getMapInfo(function (serviceResult) {
  31. var mapJSONObj = serviceResult.result;
  32. map = new ol.Map({
  33. target: 'map',
  34. controls: ol.control.defaults({attributionOptions: {collapsed: false}})
  35. .extend([new ol.supermap.control.Logo()]),
  36. view: new ol.View({
  37. center: [116.85, 39.79],
  38. zoom: 4,
  39. projection: 'EPSG:4326',
  40. multiWorld: true
  41. }),
  42. overlays: [overlay]
  43. });
  44. var options = ol.source.TileSuperMapRest.optionsFromMapJSON(url, mapJSONObj);
  45. options.wrapX = true;
  46. var layer = new ol.layer.Tile({
  47. source: new ol.source.TileSuperMapRest(options)
  48. });
  49. map.addLayer(layer);
  50. map.once('postrender', function () {
  51. var features = [];
  52. for (var i = 0, len = chinaConsumptionLevel.length; i < len; i++) {
  53. // 省居民消费水平(单位:元)信息
  54. var provinceInfo = chinaConsumptionLevel[i];
  55. var geo = new ol.geom.Point([provinceInfo[1], provinceInfo[2]]);
  56. //ThemeFeature 格式类型
  57. // var fea = new ol.supermap.ThemeFeature(geo, attrs);
  58. //支持传入 ol.Feature 格式类型:
  59. var fea = new ol.Feature({
  60. geometry: geo,
  61. NAME: provinceInfo[0],
  62. CON2009: provinceInfo[3]
  63. });
  64. features.push(fea);
  65. }
  66. // 创建一个圆形符号专题图层
  67. themeSource = new ol.source.RankSymbol("RankSymbolLayer", "Circle",
  68. {
  69. map: map,
  70. attributions: " ",
  71. themeField: "CON2009",
  72. // 配置图表参数
  73. symbolSetting: {
  74. //必设参数
  75. codomain: [0, 40000], // 允许图形展示的值域范围,此范围外的数据将不制作图图形
  76. //圆最大半径 默认100
  77. maxR: 100,
  78. //圆最小半径 默认0
  79. minR: 0,
  80. // 圆形样式
  81. circleStyle: {fillOpacity: 0.8},
  82. // 符号专题图填充颜色
  83. fillColor: "#FFA500",
  84. // 专题图hover 样式
  85. circleHoverStyle: {fillOpacity: 1}
  86. }
  87. });
  88. themeSource.on("mousemove", showInfoWin);
  89. themeSource.addFeatures(features);
  90. var pointerInteraction = new ol.interaction.Pointer({
  91. handleMoveEvent: function (event) {
  92. themeSource.fire('mousemove', event);
  93. }
  94. });
  95. map.addInteraction(pointerInteraction);
  96. map.addLayer(new ol.layer.Image({
  97. source: themeSource
  98. }));
  99. themeSource.setOpacity(0.1);
  100. });
  101. // 地图弹窗的显示
  102. function showInfoWin(e) {
  103. // e.target 是图形对象,即数据的可视化对象。
  104. // 图形对象的 refDataID 属性是数据(feature)的 id 属性,它指明图形对象是由那个数据制作而来;
  105. // 图形对象的 dataInfo 属性是图形对象表示的具体数据,他有两个属性,field、R 和 value;
  106. if (e.target && e.target.refDataID && e.target.dataInfo) {
  107. closeInfoWin();
  108. // 获取图形对应的数据 (feature)
  109. var fea = themeSource.getFeatureById(e.target.refDataID);
  110. var info = e.target.dataInfo;
  111. // 弹窗内容
  112. var contentHTML = "<div style='color: #000; background-color: #fff'>";
  113. contentHTML += resources.text_Name + "<br><strong>" + fea.attributes.NAME + "</strong>";
  114. contentHTML += "<hr style='margin: 3px'>";
  115. switch (info.field) {
  116. case "CON2009":
  117. contentHTML += resources.text_consumptionLevel1 + "09" + resources.text_consumptionLevel2 + " <br/><strong>" + info.value + "</strong>(" + resources.text_yuan + ")";
  118. break;
  119. default:
  120. contentHTML += "No Data";
  121. }
  122. contentHTML += "</div>";
  123. content.innerHTML = contentHTML;
  124. overlay.setPosition(map.getCoordinateFromPixel([e.event.x, e.event.y]));
  125. return;
  126. }
  127. closeInfoWin();
  128. }
  129. // 移除地图弹窗
  130. function closeInfoWin() {
  131. if (overlay) {
  132. overlay.setPosition(undefined);
  133. }
  134. }
  135. });
  136. </script>
  137. </body>
  138. </html>