|
|
@@ -4,7 +4,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
-import { PropType, reactive, watch } from 'vue'
|
|
|
+import { PropType, reactive, watch, ref, nextTick } from 'vue'
|
|
|
import config, { includes, MapDefaultConfig } from './config'
|
|
|
import VChart from 'vue-echarts'
|
|
|
import { use, registerMap, getMap } from 'echarts/core'
|
|
|
@@ -51,28 +51,12 @@ use([
|
|
|
VisualMapComponent
|
|
|
])
|
|
|
|
|
|
-
|
|
|
const option = reactive({
|
|
|
- value: mergeTheme(props.chartConfig.option, props.themeSetting, includes),
|
|
|
+ value: mergeTheme(props.chartConfig.option, props.themeSetting, includes)
|
|
|
})
|
|
|
+const vChartRef = ref<typeof VChart>()
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-// const mapJsonModules:any = {}
|
|
|
-// const files = import.meta.globEager('./mapGeojson/*.json')
|
|
|
-// for (const key in files) {
|
|
|
-// const filename = key.replace(/(\.\/mapGeojson\/|\.(json))/g, "");
|
|
|
-// mapJsonModules[filename] = files[key].default || files[key]
|
|
|
-// }
|
|
|
-// //注册地图 同步
|
|
|
-// const registerMapModules=()=>{
|
|
|
-// let adcode= props.chartConfig.option.mapRegion.adcode
|
|
|
-// registerMap(adcode, { geoJSON: mapJsonModules[adcode] as any, specialAreas: {} })
|
|
|
-// }
|
|
|
-// registerMapModules()
|
|
|
-
|
|
|
-
|
|
|
-//动态获取json注册地图
|
|
|
+//动态获取json注册地图
|
|
|
const getGeojson = (regionId: string) => {
|
|
|
return new Promise<boolean>((resolve, reject) => {
|
|
|
import(`./mapGeojson/${regionId}.json`).then(data => {
|
|
|
@@ -81,58 +65,52 @@ const getGeojson = (regionId: string) => {
|
|
|
})
|
|
|
})
|
|
|
}
|
|
|
-//异步时先注册空的
|
|
|
+//异步时先注册空的 保证初始化不报错
|
|
|
registerMap(props.chartConfig.option.mapRegion.adcode, { geoJSON: {} as any, specialAreas: {} })
|
|
|
-//保证初始化不报错
|
|
|
-const registerMapModulesAsync= async ()=>{
|
|
|
+// 进行更换初始化地图
|
|
|
+const registerMapInitAsync = async () => {
|
|
|
+ await nextTick()
|
|
|
await getGeojson(props.chartConfig.option.mapRegion.adcode)
|
|
|
- //触发option 变动
|
|
|
- props.chartConfig.option.mapRegion.adcodeFlag=!props.chartConfig.option.mapRegion.adcodeFlag
|
|
|
- updateOptions()
|
|
|
+ vEchartsSetOption()
|
|
|
}
|
|
|
-registerMapModulesAsync()
|
|
|
-
|
|
|
+registerMapInitAsync()
|
|
|
const updateOptions = async () => {
|
|
|
option.value = props.chartConfig.option
|
|
|
}
|
|
|
-// 更换地图
|
|
|
-const mapGeoHandle = (regionId: string) => {
|
|
|
- props.chartConfig.option.geo.map = regionId
|
|
|
- props.chartConfig.option.series.forEach((item: any) => {
|
|
|
- if (item.type === 'map') item.map = regionId
|
|
|
- })
|
|
|
- updateOptions()
|
|
|
+const vEchartsSetOption =()=>{
|
|
|
+ vChartRef.value?.setOption(props.chartConfig.option)
|
|
|
}
|
|
|
const dataSetHandle = async (dataset: any) => {
|
|
|
props.chartConfig.option.series.forEach((item: any) => {
|
|
|
if (item.type === 'effectScatter' && dataset.point) item.data = dataset.point
|
|
|
else if (item.type === 'map' && dataset.point) item.data = dataset.map
|
|
|
})
|
|
|
- option.value = props.chartConfig.option
|
|
|
+ updateOptions()
|
|
|
}
|
|
|
+// 更换地图
|
|
|
+const mapGeoHandle = async (regionId: string) => {
|
|
|
+ await getGeojson(regionId)
|
|
|
+ props.chartConfig.option.geo.map = regionId
|
|
|
+ props.chartConfig.option.series.forEach((item: any) => {
|
|
|
+ if (item.type === 'map') item.map = regionId
|
|
|
+ })
|
|
|
+ updateOptions()
|
|
|
+}
|
|
|
+
|
|
|
//是否显示南海群岛
|
|
|
const mapTypeHandle = async (show: boolean) => {
|
|
|
if (show) {
|
|
|
- await getGeojson("china")
|
|
|
- // registerMap('china', { geoJSON: mapJsonModules["china"] as any, specialAreas: {} })
|
|
|
- props.chartConfig.option.mapRegion.adcodeFlag=!props.chartConfig.option.mapRegion.adcodeFlag
|
|
|
+ await getGeojson('china')
|
|
|
} else {
|
|
|
registerMap('china', { geoJSON: mapJsonWithoutHainanIsLands as any, specialAreas: {} })
|
|
|
}
|
|
|
-
|
|
|
- updateOptions()
|
|
|
+ vEchartsSetOption()
|
|
|
}
|
|
|
//层级发生变化
|
|
|
const mapZoomHandle = async (newData: number) => {
|
|
|
- props.chartConfig.option.geo.zoom = newData
|
|
|
+ props.chartConfig.option.series[1].zoom = newData
|
|
|
updateOptions()
|
|
|
}
|
|
|
-//区域发生变化
|
|
|
-const mapRegionHandle = async (newData: string) => {
|
|
|
- await getGeojson(newData)
|
|
|
- // registerMapModules()
|
|
|
- mapGeoHandle(newData)
|
|
|
-}
|
|
|
|
|
|
//监听数据发生变化
|
|
|
watch(
|
|
|
@@ -147,35 +125,32 @@ watch(
|
|
|
)
|
|
|
//监听是否显示南海群岛
|
|
|
watch(
|
|
|
- () => props.chartConfig.option.series[1].itemStyle.showHainanIsLands,
|
|
|
+ () => props.chartConfig.option.mapRegion.showHainanIsLands,
|
|
|
newData => {
|
|
|
mapTypeHandle(newData)
|
|
|
},
|
|
|
{
|
|
|
- deep: true,
|
|
|
- immediate: true
|
|
|
+ deep: false
|
|
|
}
|
|
|
)
|
|
|
//监听地图区域发生变化
|
|
|
watch(
|
|
|
() => props.chartConfig.option.mapRegion.adcode,
|
|
|
newData => {
|
|
|
- mapRegionHandle(newData)
|
|
|
+ mapGeoHandle(newData)
|
|
|
},
|
|
|
{
|
|
|
- deep: true,
|
|
|
- immediate: true
|
|
|
+ deep: false
|
|
|
}
|
|
|
)
|
|
|
//监听大小发生变化
|
|
|
watch(
|
|
|
- () => props.chartConfig.option.series[1].zoom,
|
|
|
+ () => props.chartConfig.option.geo.zoom,
|
|
|
newData => {
|
|
|
mapZoomHandle(newData)
|
|
|
},
|
|
|
{
|
|
|
- deep: true,
|
|
|
- immediate: true
|
|
|
+ deep: false
|
|
|
}
|
|
|
)
|
|
|
|