components_graph_theme_layer_vue.html 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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_componentsGraphThemeLayer_Vue"></title>
  9. <script type="text/javascript" include="vue" src="../js/include-web.js"></script>
  10. <script include="iclient-mapboxgl-vue,mapbox-gl-enhance" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
  11. <script type="text/javascript" src="../data/chinaConsumptionLevel.js"></script>
  12. <style>
  13. #main {
  14. margin: 0 auto;
  15. width: 100%;
  16. height: 100%;
  17. }
  18. </style>
  19. </head>
  20. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  21. <div id="main">
  22. <sm-web-map server-url='https://iportal.supermap.io/iportal' map-id="1329428269">
  23. <sm-graph-theme-layer
  24. :options="graphThemeLayerOptions"
  25. layer-name="pieThemeLayer"
  26. :data="graphFeatures"
  27. charts-type="Pie"
  28. @load="addLayerSucceeded"
  29. ></sm-graph-theme-layer>
  30. </sm-web-map>
  31. </div>
  32. <script>
  33. var features, chartsSettingForPieOrRing, themeLayerOptions, popup;
  34. var feas = [];
  35. for (var i = 0, len = chinaConsumptionLevel.length; i < len; i++) {
  36. // 省居民消费水平(单位:元)信息
  37. var provinceInfo = chinaConsumptionLevel[i];
  38. var fea = {
  39. type: 'feature',
  40. geometry: {
  41. type: 'Point',
  42. coordinates: [provinceInfo[1], provinceInfo[2]],
  43. },
  44. properties: {
  45. NAME: provinceInfo[0],
  46. CON2009: provinceInfo[3],
  47. CON2010: provinceInfo[4],
  48. CON2011: provinceInfo[5],
  49. CON2012: provinceInfo[6],
  50. CON2013: provinceInfo[7],
  51. },
  52. };
  53. feas.push(fea);
  54. }
  55. features = {
  56. type: 'FeatureCollection',
  57. features: feas,
  58. };
  59. chartsSettingForPie = {
  60. width: 240,
  61. height: 100,
  62. codomain: [0, 40000], // 允许图表展示的值域范围,此范围外的数据将不制作图表
  63. sectorStyle: { fillOpacity: 0.8 }, // 柱状图中柱条的(表示字段值的图形)样式
  64. sectorStyleByFields: [
  65. { fillColor: '#FFB980' },
  66. { fillColor: '#5AB1EF' },
  67. { fillColor: '#B6A2DE' },
  68. { fillColor: '#2EC7C9' },
  69. { fillColor: '#D87A80' },
  70. ],
  71. sectorHoverStyle: { fillOpacity: 1 },
  72. xShapeBlank: [10, 10, 10], // 水平方向上的空白间距参数
  73. axisYLabels: ['4万', '3万', '2万', '1万', '0'], // y 轴标签内容
  74. axisXLabels: ['09年', '10年', '11年', '12年', '13年'], // x 轴标签内容
  75. backgroundStyle: { fillColor: '#CCE8CF' }, // 背景样式
  76. backgroundRadius: [5, 5, 5, 5], // 背景框圆角参数
  77. };
  78. // 设置 graphThemeLayer option 参数
  79. themeLayerOptions = {
  80. attributions: ' ',
  81. themeFields: ['CON2009', 'CON2010', 'CON2011', 'CON2012', 'CON2013'],
  82. opacity: 0.9,
  83. chartsSetting: chartsSettingForPie,
  84. };
  85. // 添加弹窗
  86. function showInfo(themeLayer, map) {
  87. themeLayer.on('mousemove', function(e) {
  88. if (popup) {
  89. popup.remove();
  90. }
  91. if (e.target && e.target.refDataID && e.target.dataInfo) {
  92. // 获取图形对应的数据 (feature)
  93. var fea = themeLayer.getFeatureById(e.target.refDataID);
  94. var info = e.target.dataInfo;
  95. // 弹窗内容
  96. var contentHTML = "<div style='color: #000; background-color: #fff'>";
  97. contentHTML += resources.text_Name + '<br><strong>' + fea.attributes.NAME + '</strong>';
  98. contentHTML += "<hr style='margin: 3px'>";
  99. switch (info.field) {
  100. case 'CON2009':
  101. contentHTML += resources.text_consumptionLevel1 + '09' + resources.text_consumptionLevel2 + '<br/><strong>' + info.value + '</strong>(' + resources.text_yuan + ')';
  102. break;
  103. case 'CON2010':
  104. contentHTML += resources.text_consumptionLevel1 + '10' + resources.text_consumptionLevel2 + '<br/><strong>' + info.value + '</strong>(' + resources.text_yuan + ')';
  105. break;
  106. case 'CON2011':
  107. contentHTML += resources.text_consumptionLevel1 + '11' + resources.text_consumptionLevel2 + '<br/><strong>' + info.value + '</strong>(' + resources.text_yuan + ')';
  108. break;
  109. case 'CON2012':
  110. contentHTML += resources.text_consumptionLevel1 + '12' + resources.text_consumptionLevel2 + ' <br/><strong>' + info.value + '</strong>(' + resources.text_yuan + ')';
  111. break;
  112. case 'CON2013':
  113. contentHTML += resources.text_consumptionLevel1 + '13' + resources.text_consumptionLevel2 + ' <br/><strong>' + info.value + '</strong>(' + resources.text_yuan + ')';
  114. break;
  115. default:
  116. contentHTML += 'No Data';
  117. }
  118. contentHTML += '</div>';
  119. var tempPoint = map.unproject({ x: e.event.x, y: e.event.y });
  120. popup = new mapboxgl.Popup({ closeOnClick: false })
  121. .setLngLat([tempPoint.lng, tempPoint.lat])
  122. .setHTML(contentHTML)
  123. .addTo(map);
  124. return;
  125. }
  126. if (popup) {
  127. popup.remove();
  128. }
  129. });
  130. }
  131. new Vue({
  132. el: '#main',
  133. data() {
  134. return {
  135. graphThemeLayerOptions: themeLayerOptions,
  136. graphFeatures: features,
  137. addLayerSucceeded: showInfo,
  138. };
  139. },
  140. });
  141. </script>
  142. </body>
  143. </html>