企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
添加静态资源 地图json文件 D:\ireport365\ireport365.war\cdn\1.0\assets-map-json\ 路径 里分别添加 cityMap.js 和main-city包 在D:\ireport365\ireport365.war\WEB-INF\pages\enduser\designer\index.jsp路径里添加 `<script src="${pageContext.request.contextPath}/cdn/1.0/assets-map-json/cityMap.js"></script>` 在D:\ireport365\ireport365.war\WEB-INF\classes\system-resource\report-template.html 这里添加 `<script src="${cdnPath}cdn/1.0/assets-map-json/cityMap.js"></script>` 下钻地图 D:\ireport365\ireport365.war\js\enduser\designer\vs-component-echarts.js 第一步添加 组件type及图片等 ![](https://box.kancloud.cn/d6a6b496098689354c86b35269e49190_798x142.png) ~~~ { name: "", type: "DrillDownChinaMap", coverImage: contextPath + "/images/componenttypes/" + locale + "/echarts/zh_chinaAreaMap.png", coverImageWidth: a, tip: "地图下钻" } ~~~ 二 echarts图形对象 option ~~~ //存储切换的每一级地图信息 // const mapStack = [{mapCode: '100000',mapName: 'china'}]; const mapStack = []; let curMap = {}; var timeFn = null; // 下钻地图 //初始化地图 DrillDownChinaMapoptionTemplate = { animationDuration: 500, // backgroundColor: "#154e90", title: { show: false, }, tooltip: { show: true, trigger: "item", formatter: function(data){ //console.log(data); if( !isNaN(data.value) &&data.value!=null ){ return data.name+":"+data.value; } } }, legend: { show: false, orient: "vertical", x: "left", data: [], selectedMode: "single", textStyle: { color: "#ccc" } }, dataRange: { y: "top", min: 0, max: 100, itemWidth: 12, itemHeight: 10, calculable: true, color: ["#ff3333", "orange", "yellow", "lime", "aqua"], textStyle: { color: "#000" } }, series: [{ name: '', type: 'map', mapType: '', selectedMode: 'single', itemStyle: { normal: { label: { show: true, textStyle: { fontSize: "10", color: "#999" } }, borderColor: 'rgba(147, 235, 248, 1)', borderWidth: 1, areaColor: { type: 'radial', x: 0.5, y: 0.5, r: 0.8, colorStops: [{ offset: 0, color: 'rgba(147, 235, 248, 0)' // 0% 处的颜色 }, { offset: 1, color: 'rgba(147, 235, 248, .2)' // 100% 处的颜色 }], globalCoord: false // 缺省为 false }, shadowColor: 'rgba(128, 217, 248, 1)', // shadowColor: 'rgba(255, 255, 255, 1)', shadowOffsetX: -2, shadowOffsetY: 2, shadowBlur: 10 }, emphasis: { areaColor: '#389BB7', borderWidth: 0 } }, data: [] }] }; ~~~ 三 添加类别联动 联动不加了 下钻特殊性 不联动 ~~~ var factory = { // 是否显示类别 isShowThresholdCategory: function (scope) { switch (scope.component.type) { case "chinaAreaMap": case "chinamap": case "chinamap2": case "chinaHeatMap": case "DrillDownChinaMap": return true } return false }, // 获取类别名称 getThresholdCategoryName: function (scope) { switch (scope.component.type) { case "chinaAreaMap": case "chinamap": case "chinamap2": case "chinaHeatMap": case "DrillDownChinaMap": return vsLang.threshold_range } return "" }, // 是否显示行为 isShowEventCategory: function (scope) { switch (scope.component.type) { case "column": case "mixed": case "pie": case "rose": case "treemap": case "bar": case "line": return true } return false }, // 联动里面的指标联动 supportReceiveMeasureLink: function (scope) { switch (scope.component.type) { case "column": case "pie": case "rose": case "treemap": case "bar": case "line": case "chinaAreaMap": case "chinamap2": case "chinaHeatMap": return true } return false }, ~~~ 四 添加提示框 默认显示 ~~~ case "DrillDownChinaMap": if (component.config.showItemLabel == null) { component.config.showItemLabel = true } option.tooltip.confine = true; break; ~~~ 五 添加刷新数据的方法 ![](https://box.kancloud.cn/a8dc965f0e64700b68b1481800fe798e_407x68.png) ~~~ case "DrillDownChinaMap": internalRefreshChinaDownMapModelData(); break; ~~~ 六 在refreshChartView 刷新视图函数里 添加处理数据的方法 ~~~ var internalRefreshChinaDownMapModelData = function () { var option = component.config.chartConfig; var dimensions = component.config.datasourceConfig.dimensions; var measures = component.config.datasourceConfig.measures; var data = component.context.data; var chartData = []; var chartDataMap = {}; var measureIdx = 0; // console.log(data.length) for (var i = 0; i < data.length; i++) { // console.log(data[i]) for(var j = 0; j< data[i].length;j++){ // console.log(data[i][j]) var value = data[i][j][measures[measureIdx].name]; var name = factory._internalFindKvValue(component, data[i][j][dimensions[i].name]); // console.log(value) // console.log(name) chartData.push({ name: name, value: value }); } } // console.log(component) // console.log(chartData) option.series[0].data = chartData; component.context.chart.setOption(option, true) }; ~~~ 七 在buildDataDescription函数里重新写 接收数据的方法 也就是加了个 switch判断 DrillDownChinaMap判断力有拆分数组分别获取数据 组合成data 传出去 ~~~ scope.$on(event_refreshBindingData, function (target, param) { switch (component.type) { case "DrillDownChinaMap": var dimensions = component.config.datasourceConfig.dimensions; var measures = component.config.datasourceConfig.measures; var result = []; // 拆分数组 for(var i=0,len=dimensions.length;i<len;i+=1){ result.push(dimensions.slice(i,i+1)); } // console.log(result) // console.log(dimensions) if (dimensions && dimensions.length > 0 && measures && measures.length > 0) { // console.log(dimensions) var dd = []; for(var i = 0;i<result.length;i++){ // console.log(result[i]) scope.queryModelData({ eventParam: param, dimensions: result[i], measures: measures, tableKey: component.config.datasourceConfig.metadataConfig.metadataTable.key, onQuerySuccess: function (response) { if (response.data.success) { // console.log(response.data.data.data); dd.push(response.data.data.data) component.context.data = dd; // console.log('234534543') // console.log(component.context.data) factory.refreshChartView(scope, element, component, $compile) } else { toaster.error({ body: response.data.message }) } }, onError: function () { toaster.error({ body: vsLang.connection_failed }) } }) } // console.log(dd) // component.context.data = dd; // factory.refreshChartView(scope, element, component, $compile) } // alert('3123123') break; case "line": case "area": case "column": case "mixed": case "bar": case "pie": case "rose": case "treemap": case "gauge": case "gauge2": case "radar": case "chinamap": case "chinaAreaMap": case "chinamap2": case "chinaHeatMap": var dimensions = component.config.datasourceConfig.dimensions; var measures = component.config.datasourceConfig.measures; // console.log(dimensions) if (dimensions && dimensions.length > 0 && measures && measures.length > 0) { console.log(dimensions) scope.queryModelData({ eventParam: param, dimensions: dimensions, measures: measures, tableKey: component.config.datasourceConfig.metadataConfig.metadataTable.key, onQuerySuccess: function (response) { if (response.data.success) { console.log(response.data); factory.refreshChartView(scope, element, component, $compile) } else { toaster.error({ body: response.data.message }) } }, onError: function () { toaster.error({ body: vsLang.connection_failed }) } }) } break; } }); ~~~ 八 在添加组件的事件 ~~~ case "DrillDownChinaMap": // 数据处理 var option = component.config.chartConfig; loadMap1('100000', 'china'); function loadMap1(mapCode, mapName) { $.ajaxSettings.async = false; $.getJSON('/cdn/1.0/assets-map-json/main-city/' + mapCode + '.json', function(data1) { if (data1) { echarts.registerMap(mapName, data1); console.log(data1) option.series[0].mapType = mapName console.log(mapName) scope.component.context.chart.setOption(option, true) curMap = { mapCode: mapCode, mapName: mapName }; } else { alert('无法加载该地图'); } }); } /** 绑定用户切换地图区域事件 cityMap对象存储着地图区域名称和区域的信息(name-code) 当mapCode有值,说明可以切换到下级地图 同时保存上级地图的编号和名称 */ component.context.chart.on("mapselectchanged", function (params) { clearTimeout(timeFn); if (params.dataIndex < 0) { return } // console.log(params) timeFn = setTimeout(function(){ const name = params.batch[0].name; const mapCode = cityMap[name]; console.log(mapCode) console.log(name); if (!mapCode) { //如果地图无法继续下钻,则让点击的区域呈现选中状态 option.series[0].data = [{ name: name, selected: true, // value:Math.round(Math.random()*1000) }] return false; } else { loadMap1(mapCode, name); //将上一级地图信息压入mapStack mapStack.push({ mapCode: curMap.mapCode, mapName: curMap.mapName }); } // scope.component.context.chart.setOption(option, true) console.log(mapStack) }, 250); }); /** 绑定双击事件,并加载上一级地图 */ component.context.chart.on('dblclick', function(params) { //当双击事件发生时,清除单击事件,仅响应双击事件 clearTimeout(timeFn); var map = mapStack.pop(); if (!mapStack.length && !map) { // alert('已经到达最上一级地图了'); loadMap1('100000', 'china'); return; } loadMap1(map.mapCode, map.mapName); // scope.component.context.chart.setOption(option, true) }); break ~~~ 九 自定义服务 主要用在配置项 ![](https://box.kancloud.cn/55b9261bf5d15da752a8a6d0aef20b60_958x496.png) ~~~ if (component.type === "DrillDownChinaMap") { factory._buildChinaAreaMapAreaChartDescription4(chartCategory, scope, element, component, $compile); var valueMapCategory = { name: "valueMap", title: vsLang.area_mapping, groups: [] }; component.description.categories.push(valueMapCategory); factory._buildChinamapKeyValueMapChartDescription(valueMapCategory, scope, element, component, $compile); valueMapCategory.groups.push({ name: "text", title: { text: "", show: false }, elements: [{ title: vsLang.reload_component, type: "button", onClick: function () { scope.$broadcast(event_refreshChartView, {}) } }] }) } ~~~ _buildChinaAreaMapAreaChartDescription4 方法 写在3 的下面 ~~~ _buildChinaAreaMapAreaChartDescription4: function (dataCategory, scope, element, component, $compile) { dataCategory.groups.push({ name: "text", title: { text: vsLang.area_name }, elements: [{ title: vsLang.text, type: "switch", bind: "showItemLabel", on: vsLang.show, off: vsLang.hidden }, { title: vsLang.size, type: "configSlide", bind: "itemLabelSize", config: { slideEnd: 100 } }, { title: vsLang.color, type: "colorpicker", bind: "itemLabelColor" }] }); dataCategory.groups.push({ name: "text", title: { text: vsLang.area_blocks }, elements: [{ title: "阴影颜色", type: "colorpicker", bind: "areaColor" }, { title: vsLang.border_color, type: "colorpicker", bind: "areaBorderColor" }] }); dataCategory.groups.push({ name: "text", title: { text: vsLang.data_range_tool }, elements: [{ title: vsLang.display, type: "switch", bind: "showDataRange", on: vsLang.on, off: vsLang.off }, { title: vsLang.unit, type: "text-input-sl", bind: "dataRangeUnit" }, { title: vsLang.orientation, type: "radio-icon", bind: "dataRangeOrient", items: [{ name: vsLang.vertical, value: "vertical", icon: "fa fa-ellipsis-v" }, { name: vsLang.horizontal, value: "horizontal", icon: "fa fa-ellipsis-h" }] }, { title: vsLang.vertical_position_short, type: "radio-icon", bind: "dataRangePosY", items: [{ name: vsLang.position_top, value: "top", icon: "fa fa-minus", pStyle: "padding-top:0;padding-bottom:12px;" }, { name: vsLang.position_middle, value: "center", icon: "fa fa-minus", pStyle: "padding-top:6px;padding-bottom:6px;" }, { name: vsLang.position_bottom, value: "bottom", icon: "fa fa-minus", pStyle: "padding-top:12px;padding-bottom:0px;" }] }, { title: vsLang.horizontal_position_short, type: "radio-icon", bind: "dataRangePosX", items: [{ name: vsLang.position_left, value: "left", icon: "fa fa-align-left" }, { name: vsLang.position_center, value: "center", icon: "fa fa-align-center" }, { name: vsLang.position_right, value: "right", icon: "fa fa-align-right" }] }, { title: vsLang.vertical_offset_short, type: "configSlide", bind: "dataRangeOffsetY", config: { slideEnd: 1000 } }, { title: vsLang.horizontal_offset_short, type: "configSlide", bind: "dataRangeOffsetX", config: { slideEnd: 1000 } }, { title: vsLang.font_color, type: "colorpicker", bind: "dataRangeFontColor" }, { title: vsLang.font_size, type: "configSlide", bind: "dataRangeFontSize", config: { slideEnd: 100 } }, { title: vsLang.width, type: "configSlide", bind: "dataRangeWidth", config: { slideEnd: 100 } }, { title: vsLang.height, type: "configSlide", bind: "dataRangeHeight", config: { slideEnd: 100 } }] }); scope.$watch("component.config.showItemLabel", function(newValue, oldValue) { if (newValue != null && (oldValue == null || oldValue !== newValue)) { var option = component.config.chartConfig; option.series[0].itemStyle.normal.label.show = newValue; scope.component.context.chart.setOption(option, true) } }); scope.$watch("component.config.itemLabelSize", function(newValue, oldValue) { if (newValue != null && (oldValue == null || oldValue !== newValue)) { var option = component.config.chartConfig; option.series[0].itemStyle.normal.label.textStyle.fontSize = newValue; scope.component.context.chart.setOption(option, true) } }); scope.$watch("component.config.itemLabelColor", function(newValue, oldValue) { if (isValidColorValue(newValue)) { var option = component.config.chartConfig; option.series[0].itemStyle.normal.label.textStyle.color = newValue; scope.component.context.chart.setOption(option, true) } }); scope.$watch("component.config.areaBorderColor", function(newValue, oldValue) { if (newValue != null && (oldValue == null || oldValue !== newValue)) { var option = component.config.chartConfig; option.series[0].itemStyle.normal.borderColor = newValue; scope.component.context.chart.setOption(option, true) } }); scope.$watch("component.config.areaColor", function(newValue, oldValue) { if (isValidColorValue(newValue)) { var option = component.config.chartConfig; // console.log(newValue) option.series[0].itemStyle.normal.shadowColor = newValue; scope.component.context.chart.setOption(option, true) } }); scope.$watch("component.config.showDataRange", function(newValue, oldValue) { if (newValue != null && (oldValue == null || oldValue !== newValue)) { var option = component.config.chartConfig; option.dataRange.show = newValue; scope.component.context.chart.setOption(option, true) } }); scope.$watch("component.config.dataRangeUnit", function(newValue, oldValue) { if (newValue != null && (oldValue == null || oldValue !== newValue)) { scope.$broadcast(event_refreshChartView, {}) } }); scope.$watch("component.config.dataRangeOrient", function(newValue, oldValue) { if (newValue != null && (oldValue == null || oldValue !== newValue)) { var option = component.config.chartConfig; option.dataRange.orient = newValue; scope.component.context.chart.setOption(option, true) } }); scope.$watch("component.config.dataRangePosY", function(newValue, oldValue) { if (newValue != null && (oldValue == null || oldValue !== newValue)) { var option = component.config.chartConfig; option.dataRange.y = newValue; scope.component.context.chart.setOption(option, true) } }); scope.$watch("component.config.dataRangeOffsetX", function(newValue, oldValue) { if (newValue != null && (oldValue == null || oldValue !== newValue)) { var option = component.config.chartConfig; option.dataRange.x = newValue; scope.component.context.chart.setOption(option, true) } }); scope.$watch("component.config.dataRangeOffsetY", function(newValue, oldValue) { if (newValue != null && (oldValue == null || oldValue !== newValue)) { var option = component.config.chartConfig; option.dataRange.y = newValue; scope.component.context.chart.setOption(option, true) } }); scope.$watch("component.config.dataRangePosX", function(newValue, oldValue) { if (newValue != null && (oldValue == null || oldValue !== newValue)) { var option = component.config.chartConfig; option.dataRange.x = newValue; scope.component.context.chart.setOption(option, true) } }); scope.$watch("component.config.dataRangeFontColor", function(newValue, oldValue) { if (isValidColorValue(newValue)) { var option = component.config.chartConfig; if (option.dataRange.textStyle == null) { option.dataRange.textStyle = {} } option.dataRange.textStyle.color = newValue; scope.component.context.chart.setOption(option, true) } }); scope.$watch("component.config.dataRangeFontSize", function(newValue, oldValue) { if (newValue != null && (oldValue == null || oldValue !== newValue)) { var option = component.config.chartConfig; if (option.dataRange.textStyle == null) { option.dataRange.textStyle = {} } option.dataRange.textStyle.fontSize = newValue; scope.component.context.chart.setOption(option, true) } }); scope.$watch("component.config.dataRangeWidth", function(newValue, oldValue) { if (newValue != null && (oldValue == null || oldValue !== newValue)) { var option = component.config.chartConfig; option.dataRange.itemWidth = newValue; scope.component.context.chart.setOption(option, true) } }); scope.$watch("component.config.dataRangeHeight", function(newValue, oldValue) { if (newValue != null && (oldValue == null || oldValue !== newValue)) { var option = component.config.chartConfig; option.dataRange.itemHeight = newValue; scope.component.context.chart.setOption(option, true) } }) }, ~~~ 十 初始化的数据 ~~~ // 下钻地图 case "DrillDownChinaMap": // 初始化地图 option = angular.copy(DrillDownChinaMapoptionTemplate); // delete option.series[0].markLine; // delete option.series[0].markPoint; // delete option.series[0].geoCoord; // loadMap('100000', 'china'); option.dataRange = { y: "top", itemWidth: 12, itemHeight: 10, splitList: [{ start: 800, color: "#006EDD" }, { start: 500, end: 800, color: "#3892E5" }, { start: 300, end: 500, color: "#70B6EE" }, { start: 100, end: 300, color: "#A8DAF6" }, { end: 100, color: "#E0FFFF" }] }; option.series[0].data = [ {name:"北京",value:177}, {name:"天津",value:42}, {name:"河北",value:102}, {name:"山西",value:81}, {name:"内蒙古",value:47}, {name:"辽宁",value:67}, {name:"吉林",value:82}, {name:"黑龙江",value:66}, {name:"上海",value:24}, {name:"江苏",value:92}, {name:"浙江",value:114}, {name:"安徽",value:109}, {name:"福建",value:116}, {name:"江西",value:91}, {name:"山东",value:119}, {name:"河南",value:137}, {name:"湖北",value:116}, {name:"湖南",value:114}, {name:"重庆",value:91}, {name:"四川",value:125}, {name:"贵州",value:62}, {name:"云南",value:83}, {name:"西藏",value:9}, {name:"陕西",value:80}, {name:"甘肃",value:56}, {name:"青海",value:10}, {name:"宁夏",value:18}, {name:"新疆",value:67}, {name:"广东",value:123}, {name:"广西",value:59}, {name:"海南",value:14}, {name:'省委',value:190}, {name:'合肥市',value:190}, {name:'六安市',value:190}, {name:'滁州市',value:190}, {name:'蚌埠市',value:190}, {name:'淮南市',value:90}, {name:'宿州市',value:120}, {name:'淮北市',value:120}, {name:'亳州市',value:120}, {name:'阜阳市',value:120}, {name:'安庆市',value:190}, {name:'池州市',value:190}, {name:'黄山市',value:190}, {name:'宣城市',value:190}, {name:'芜湖市',value:190}, {name:'马鞍山市',value:190}, {name:'铜陵市',value:90}, ]; break; ~~~ 十一 初始化判断组件的大小 ![](https://box.kancloud.cn/16a1ac5bec51dcee4ea488a29dba44c7_795x333.png) ~~~ $vsPluginDescriptions.register(new function () { this.onBuildComponent = function (b) { console.log(b) if (b.type === "gauge") { b.sizeX = 2; b.sizeY = 10 } else if (b.type === "gauge2") { b.sizeX = 4; b.sizeY = 23 } else { if (b.type === "chinamap" || b.type === "DrillDownChinaMap") { b.sizeX = 4; b.sizeY = 18 } else { b.sizeY = 10 } } }; ~~~ 以上本文件代码添加完毕 design.js 分享页添加的代码 路径 D:\ireport365\ireport365.war\WEB-INF\classes\report-resource\design.js 一 添加提示框 默认开启 ![](https://box.kancloud.cn/77ebac8ebd9c58cd0523aff72f85e65e_710x154.png) ~~~ case "DrillDownChinaMap": if (component.config.showItemLabel == null) { component.config.showItemLabel = true } option.tooltip.confine = true; break; ~~~ 二 添加处理数据的判断 ![](https://box.kancloud.cn/6e23cd0f1ac5869ae8b5d787e81139b8_533x77.png) ~~~ case "DrillDownChinaMap": internalRefreshChinaDownMapModelData(); break ~~~ 三 函数的具体内容 ~~~ var internalRefreshChinaDownMapModelData = function () { var option = component.config.chartConfig; var dimensions = component.config.datasourceConfig.dimensions; var measures = component.config.datasourceConfig.measures; var data = component.context.data; console.log(data) console.log(data.length) var chartData = []; var chartDataMap = {}; var measureIdx = 0; console.log(data.length) for (var i = 0; i < data.length; i++) { console.log(data[i]) for(var j = 0; j< data[i].length;j++){ console.log(data[i][j]) var value = data[i][j][measures[measureIdx].name]; var name = factory._internalFindKvValue(component, data[i][j][dimensions[i].name]); // console.log(value) // console.log(name) chartData.push({ name: name, value: value }); } } // console.log(component) // console.log(chartData) option.series[0].data = chartData; component.context.chart.setOption(option, true) }; ~~~ 四 同理添加 修改刷新事件里的方法 和设计页有一点不一样 看清楚 ~~~ scope.$on(event_refreshBindingData, function(target, param) { switch (component.type) { case "DrillDownChinaMap": var dimensions = component.config.datasourceConfig.dimensions; var measures = component.config.datasourceConfig.measures; var result = []; // 拆分数组 for(var i=0,len=dimensions.length;i<len;i+=1){ result.push(dimensions.slice(i,i+1)); } if (dimensions && dimensions.length > 0 && measures && measures.length > 0) { var dd = []; for(var i = 0;i<result.length;i++){ // console.log(result[i]) scope.queryModelData({ eventParam: param, dimensions: result[i], measures: measures, tableKey: component.config.datasourceConfig.metadataConfig.metadataTable.key, onQuerySuccess: function (response) { if (response.data.success) { dd.push(response.data.data.data) component.context.data = dd; factory.refreshChartView(scope, element, component, $compile) } else { toaster.error({ body: response.data.message }) } }, onError: function () { toaster.error({ body: vsLang.connection_failed }) } }) } } break var dimensions = component.config.datasourceConfig.dimensions; var measures = component.config.datasourceConfig.measures; if (dimensions && dimensions.length > 0 && measures && measures.length > 0) { scope.queryModelData({ eventParam: param, dimensions: dimensions, measures: measures, tableKey: component.config.datasourceConfig.metadataConfig.metadataTable.key, onQuerySuccess: function(response) { if (response.data.success) { refreshChartView(scope, element, component, $compile) } else { console.log(response.data.message) } }, onError: function() {} }) } } }); ~~~ 、添加处理数据函数 ~~~ case "DrillDownChinaMap": //存储切换的每一级地图信息 // const mapStack = [{mapCode: '100000',mapName: 'china'}]; const mapStack = []; let curMap = {}; var timeFn = null; var option = component.config.chartConfig; var mapdata = option.series[0].data; option.series[0].data = mapdata; loadMap1('100000', 'china'); function loadMap1(mapCode, mapName) { console.log(mapCode) console.log(mapName) $.ajaxSettings.async = false; $.getJSON('/cdn/1.0/assets-map-json/main-city/' + mapCode + '.json', function(data) { if (data) { echarts.registerMap(mapName, data); console.log(data) option.series[0].mapType = mapName console.log(mapName) scope.component.context.chart.setOption(option, true) curMap = { mapCode: mapCode, mapName: mapName }; } else { alert('无法加载该地图'); } }); } /** 绑定用户切换地图区域事件 cityMap对象存储着地图区域名称和区域的信息(name-code) 当mapCode有值,说明可以切换到下级地图 同时保存上级地图的编号和名称 */ component.context.chart.on("mapselectchanged", function (params) { clearTimeout(timeFn); if (params.dataIndex < 0) { return } // console.log(params) timeFn = setTimeout(function(){ const name = params.batch[0].name; const mapCode = cityMap[name]; console.log(mapCode) console.log(name); if (!mapCode) { //如果地图无法继续下钻,则让点击的区域呈现选中状态 option.series[0].data = [{ name: name, selected: true, // value:Math.round(Math.random()*1000) }] return false; } else { loadMap1(mapCode, name); //将上一级地图信息压入mapStack mapStack.push({ mapCode: curMap.mapCode, mapName: curMap.mapName }); } // scope.component.context.chart.setOption(option, true) console.log(mapStack) }, 250); }); /** 绑定双击事件,并加载上一级地图 */ component.context.chart.on('dblclick', function(params) { //当双击事件发生时,清除单击事件,仅响应双击事件 clearTimeout(timeFn); var map = mapStack.pop(); if (!mapStack.length && !map) { // alert('已经到达最上一级地图了'); loadMap1('100000', 'china'); return; } loadMap1(map.mapCode, map.mapName); // scope.component.context.chart.setOption(option, true) }); break; ~~~ 以上 是本文件的修改内容 设计页 和分享页 都要加 bug 返回地图 有时候没有数据 ![](https://box.kancloud.cn/f862ee13f51151e5c370f5a25b3b5178_998x799.png) ~~~ var mapdata = option.series[0].data; option.series[0].data = mapdata; ~~~