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