feat: 增加可选省份地图(异步会有问题)

This commit is contained in:
刘嘉威 2022-09-22 17:16:54 +08:00
parent 2ed1b4bf23
commit ae4ae074d8
2 changed files with 6 additions and 1 deletions

View File

@ -10,6 +10,7 @@ export const option = {
dataset: dataJson, dataset: dataJson,
mapRegion: { mapRegion: {
adcode: 'china', adcode: 'china',
adcodeFlag: true,
}, },
tooltip: { tooltip: {
show: true, show: true,

View File

@ -76,7 +76,6 @@ const option = reactive({
const getGeojson = (regionId: string) => { const getGeojson = (regionId: string) => {
return new Promise<boolean>((resolve, reject) => { return new Promise<boolean>((resolve, reject) => {
import(`./mapGeojson/${regionId}.json`).then(data => { import(`./mapGeojson/${regionId}.json`).then(data => {
console.log({data});
registerMap(regionId, { geoJSON: data.default as any, specialAreas: {} }) registerMap(regionId, { geoJSON: data.default as any, specialAreas: {} })
resolve(true) resolve(true)
}) })
@ -87,6 +86,9 @@ registerMap(props.chartConfig.option.mapRegion.adcode, { geoJSON: {} as any, spe
// //
const registerMapModulesAsync= async ()=>{ const registerMapModulesAsync= async ()=>{
await getGeojson(props.chartConfig.option.mapRegion.adcode) await getGeojson(props.chartConfig.option.mapRegion.adcode)
//option
props.chartConfig.option.mapRegion.adcodeFlag=!props.chartConfig.option.mapRegion.adcodeFlag
updateOptions()
} }
registerMapModulesAsync() registerMapModulesAsync()
@ -113,9 +115,11 @@ const mapTypeHandle = async (show: boolean) => {
if (show) { if (show) {
await getGeojson("china") await getGeojson("china")
// registerMap('china', { geoJSON: mapJsonModules["china"] as any, specialAreas: {} }) // registerMap('china', { geoJSON: mapJsonModules["china"] as any, specialAreas: {} })
props.chartConfig.option.mapRegion.adcodeFlag=!props.chartConfig.option.mapRegion.adcodeFlag
} else { } else {
registerMap('china', { geoJSON: mapJsonWithoutHainanIsLands as any, specialAreas: {} }) registerMap('china', { geoJSON: mapJsonWithoutHainanIsLands as any, specialAreas: {} })
} }
updateOptions() updateOptions()
} }
// //