mirror of
https://gitee.com/dromara/go-view.git
synced 2025-02-24 16:22:57 +08:00
perf: 可选省份地图组件异步加载geojson
This commit is contained in:
parent
ae4ae074d8
commit
34d799049d
@ -10,7 +10,7 @@ export const option = {
|
|||||||
dataset: dataJson,
|
dataset: dataJson,
|
||||||
mapRegion: {
|
mapRegion: {
|
||||||
adcode: 'china',
|
adcode: 'china',
|
||||||
adcodeFlag: true,
|
showHainanIsLands:true
|
||||||
},
|
},
|
||||||
tooltip: {
|
tooltip: {
|
||||||
show: true,
|
show: true,
|
||||||
@ -42,25 +42,13 @@ export const option = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
geo: {
|
geo: {
|
||||||
|
show:false,
|
||||||
type: 'map',
|
type: 'map',
|
||||||
roam: false,
|
roam: false,
|
||||||
map: "china",
|
map: "china",
|
||||||
selectedMode: false, //是否允许选中多个区域
|
selectedMode: false, //是否允许选中多个区域
|
||||||
// aspectScale: 1,
|
// aspectScale: 1,
|
||||||
zoom: 1,
|
zoom: 1,
|
||||||
tooltip: {
|
|
||||||
show: false,
|
|
||||||
},
|
|
||||||
label: {
|
|
||||||
show: false,
|
|
||||||
}, //地图中文字内容及样式控制
|
|
||||||
itemStyle: {
|
|
||||||
areaColor: "rgba(0,0,0,0)",
|
|
||||||
borderColor: "rgba(0,0,0,0)",
|
|
||||||
},
|
|
||||||
emphasis: {
|
|
||||||
disabled: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
series: [
|
series: [
|
||||||
{
|
{
|
||||||
@ -135,7 +123,7 @@ export const option = {
|
|||||||
},
|
},
|
||||||
label: {
|
label: {
|
||||||
show: false,
|
show: false,
|
||||||
color: "#000",
|
color: "#fff",
|
||||||
// formatter: function (val:any) {
|
// formatter: function (val:any) {
|
||||||
// // console.log(val)
|
// // console.log(val)
|
||||||
// if (val.data !== undefined) {
|
// if (val.data !== undefined) {
|
||||||
@ -145,7 +133,18 @@ export const option = {
|
|||||||
// }
|
// }
|
||||||
// },
|
// },
|
||||||
rich: {},
|
rich: {},
|
||||||
emphasis: { show: false },
|
// emphasis: { show: false },
|
||||||
|
},
|
||||||
|
emphasis: {
|
||||||
|
disabled:false,
|
||||||
|
label: {
|
||||||
|
color: "#fffFFF",
|
||||||
|
},
|
||||||
|
itemStyle:{
|
||||||
|
areaColor: "#389BB7",
|
||||||
|
shadowColor:"#389BB7",
|
||||||
|
borderWidth: 1,
|
||||||
|
}
|
||||||
},
|
},
|
||||||
itemStyle: {
|
itemStyle: {
|
||||||
// borderColor: "rgba(147, 235, 248, .8)",
|
// borderColor: "rgba(147, 235, 248, .8)",
|
||||||
@ -172,13 +171,6 @@ export const option = {
|
|||||||
shadowOffsetX: -2,
|
shadowOffsetX: -2,
|
||||||
shadowOffsetY: 2,
|
shadowOffsetY: 2,
|
||||||
shadowBlur: 10,
|
shadowBlur: 10,
|
||||||
emphasis: {
|
|
||||||
disabled:false,
|
|
||||||
areaColor: "#389BB7",
|
|
||||||
shadowColor:"#389BB7",
|
|
||||||
borderWidth: 1,
|
|
||||||
},
|
|
||||||
showHainanIsLands: true,
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
</SettingItem>
|
</SettingItem>
|
||||||
<SettingItem name="大小">
|
<SettingItem name="大小">
|
||||||
<n-input-number
|
<n-input-number
|
||||||
v-model:value="seriesList[1].zoom"
|
v-model:value="mapGeo.zoom"
|
||||||
:min="1"
|
:min="1"
|
||||||
size="small"
|
size="small"
|
||||||
placeholder="请输入地图大小"
|
placeholder="请输入地图大小"
|
||||||
@ -63,34 +63,37 @@
|
|||||||
></n-input-number>
|
></n-input-number>
|
||||||
</SettingItem>
|
</SettingItem>
|
||||||
</SettingItemBox>
|
</SettingItemBox>
|
||||||
<SettingItemBox name="聚焦" >
|
<SettingItemBox name="聚焦 (预览可见)" >
|
||||||
<!-- <setting-item name="禁用">
|
<setting-item name="禁用">
|
||||||
<n-space>
|
<n-space>
|
||||||
<n-switch v-model:value="seriesList[1].itemStyle.emphasis.disabled" size="small"></n-switch>
|
<n-switch v-model:value="seriesList[1].emphasis.disabled" size="small"></n-switch>
|
||||||
</n-space>
|
</n-space>
|
||||||
</setting-item> -->
|
</setting-item>
|
||||||
<SettingItem name="颜色(预览可见)">
|
<SettingItem name="颜色">
|
||||||
<n-color-picker
|
<n-color-picker
|
||||||
size="small"
|
size="small"
|
||||||
:modes="['hex']"
|
:modes="['hex']"
|
||||||
v-model:value="seriesList[1].itemStyle.emphasis.areaColor"
|
v-model:value="seriesList[1].emphasis.itemStyle.areaColor"
|
||||||
></n-color-picker>
|
></n-color-picker>
|
||||||
</SettingItem>
|
</SettingItem>
|
||||||
<SettingItem name="阴影(预览可见)">
|
<SettingItem name="阴影">
|
||||||
<n-color-picker
|
<n-color-picker
|
||||||
size="small"
|
size="small"
|
||||||
:modes="['hex']"
|
:modes="['hex']"
|
||||||
v-model:value="seriesList[1].itemStyle.emphasis.shadowColor"
|
v-model:value="seriesList[1].emphasis.itemStyle.shadowColor"
|
||||||
></n-color-picker>
|
></n-color-picker>
|
||||||
</SettingItem>
|
</SettingItem>
|
||||||
<SettingItem name="边框大小(预览)">
|
<SettingItem name="边框大小">
|
||||||
<n-input-number
|
<n-input-number
|
||||||
v-model:value="seriesList[1].itemStyle.emphasis.borderWidth"
|
v-model:value="seriesList[1].emphasis.itemStyle.borderWidth"
|
||||||
:min="1"
|
:min="1"
|
||||||
size="small"
|
size="small"
|
||||||
placeholder="请输入边框大小"
|
placeholder="请输入边框大小"
|
||||||
></n-input-number>
|
></n-input-number>
|
||||||
</SettingItem>
|
</SettingItem>
|
||||||
|
<SettingItem name="文字颜色">
|
||||||
|
<n-color-picker size="small" :modes="['hex']" v-model:value="seriesList[1].emphasis.label.color"></n-color-picker>
|
||||||
|
</SettingItem>
|
||||||
</SettingItemBox>
|
</SettingItemBox>
|
||||||
<SettingItemBox name="边框">
|
<SettingItemBox name="边框">
|
||||||
<SettingItem name="颜色">
|
<SettingItem name="颜色">
|
||||||
@ -111,7 +114,7 @@
|
|||||||
</SettingItemBox>
|
</SettingItemBox>
|
||||||
<SettingItemBox name="其他" v-if="mapRegion.adcode==='china'">
|
<SettingItemBox name="其他" v-if="mapRegion.adcode==='china'">
|
||||||
<SettingItem >
|
<SettingItem >
|
||||||
<n-checkbox v-model:checked="seriesList[1].itemStyle.showHainanIsLands" size="small">显示南海群岛</n-checkbox>
|
<n-checkbox v-model:checked="mapRegion.showHainanIsLands" size="small">显示南海群岛</n-checkbox>
|
||||||
</SettingItem>
|
</SettingItem>
|
||||||
</SettingItemBox>
|
</SettingItemBox>
|
||||||
</CollapseItem>
|
</CollapseItem>
|
||||||
@ -148,7 +151,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { PropType, computed } from 'vue'
|
import { PropType, computed } from 'vue'
|
||||||
import { CollapseItem, SettingItemBox, SettingItem } from '@/components/Pages/ChartItemSetting'
|
import { CollapseItem, SettingItemBox, SettingItem } from '@/components/Pages/ChartItemSetting'
|
||||||
import { lineConf } from '@/packages/chartConfiguration/echarts/index'
|
|
||||||
import { GlobalThemeJsonType } from '@/settings/chartThemes/index'
|
import { GlobalThemeJsonType } from '@/settings/chartThemes/index'
|
||||||
import { GlobalSetting } from '@/components/Pages/ChartItemSetting'
|
import { GlobalSetting } from '@/components/Pages/ChartItemSetting'
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
@ -190,5 +192,7 @@ const seriesList = computed(() => {
|
|||||||
const mapRegion = computed(() => {
|
const mapRegion = computed(() => {
|
||||||
return props.optionData.mapRegion
|
return props.optionData.mapRegion
|
||||||
})
|
})
|
||||||
|
const mapGeo = computed(() => {
|
||||||
|
return props.optionData.geo
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<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 config, { includes, MapDefaultConfig } from './config'
|
||||||
import VChart from 'vue-echarts'
|
import VChart from 'vue-echarts'
|
||||||
import { use, registerMap, getMap } from 'echarts/core'
|
import { use, registerMap, getMap } from 'echarts/core'
|
||||||
@ -51,26 +51,10 @@ use([
|
|||||||
VisualMapComponent
|
VisualMapComponent
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
const option = reactive({
|
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) => {
|
const getGeojson = (regionId: string) => {
|
||||||
@ -81,58 +65,52 @@ const getGeojson = (regionId: string) => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
//异步时先注册空的
|
//异步时先注册空的 保证初始化不报错
|
||||||
registerMap(props.chartConfig.option.mapRegion.adcode, { geoJSON: {} as any, specialAreas: {} })
|
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)
|
await getGeojson(props.chartConfig.option.mapRegion.adcode)
|
||||||
//触发option 变动
|
vEchartsSetOption()
|
||||||
props.chartConfig.option.mapRegion.adcodeFlag=!props.chartConfig.option.mapRegion.adcodeFlag
|
|
||||||
updateOptions()
|
|
||||||
}
|
}
|
||||||
registerMapModulesAsync()
|
registerMapInitAsync()
|
||||||
|
|
||||||
const updateOptions = async () => {
|
const updateOptions = async () => {
|
||||||
option.value = props.chartConfig.option
|
option.value = props.chartConfig.option
|
||||||
}
|
}
|
||||||
// 更换地图
|
const vEchartsSetOption =()=>{
|
||||||
const mapGeoHandle = (regionId: string) => {
|
vChartRef.value?.setOption(props.chartConfig.option)
|
||||||
props.chartConfig.option.geo.map = regionId
|
|
||||||
props.chartConfig.option.series.forEach((item: any) => {
|
|
||||||
if (item.type === 'map') item.map = regionId
|
|
||||||
})
|
|
||||||
updateOptions()
|
|
||||||
}
|
}
|
||||||
const dataSetHandle = async (dataset: any) => {
|
const dataSetHandle = async (dataset: any) => {
|
||||||
props.chartConfig.option.series.forEach((item: any) => {
|
props.chartConfig.option.series.forEach((item: any) => {
|
||||||
if (item.type === 'effectScatter' && dataset.point) item.data = dataset.point
|
if (item.type === 'effectScatter' && dataset.point) item.data = dataset.point
|
||||||
else if (item.type === 'map' && dataset.point) item.data = dataset.map
|
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) => {
|
const mapTypeHandle = async (show: boolean) => {
|
||||||
if (show) {
|
if (show) {
|
||||||
await getGeojson("china")
|
await getGeojson('china')
|
||||||
// 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: {} })
|
||||||
}
|
}
|
||||||
|
vEchartsSetOption()
|
||||||
updateOptions()
|
|
||||||
}
|
}
|
||||||
//层级发生变化
|
//层级发生变化
|
||||||
const mapZoomHandle = async (newData: number) => {
|
const mapZoomHandle = async (newData: number) => {
|
||||||
props.chartConfig.option.geo.zoom = newData
|
props.chartConfig.option.series[1].zoom = newData
|
||||||
updateOptions()
|
updateOptions()
|
||||||
}
|
}
|
||||||
//区域发生变化
|
|
||||||
const mapRegionHandle = async (newData: string) => {
|
|
||||||
await getGeojson(newData)
|
|
||||||
// registerMapModules()
|
|
||||||
mapGeoHandle(newData)
|
|
||||||
}
|
|
||||||
|
|
||||||
//监听数据发生变化
|
//监听数据发生变化
|
||||||
watch(
|
watch(
|
||||||
@ -147,35 +125,32 @@ watch(
|
|||||||
)
|
)
|
||||||
//监听是否显示南海群岛
|
//监听是否显示南海群岛
|
||||||
watch(
|
watch(
|
||||||
() => props.chartConfig.option.series[1].itemStyle.showHainanIsLands,
|
() => props.chartConfig.option.mapRegion.showHainanIsLands,
|
||||||
newData => {
|
newData => {
|
||||||
mapTypeHandle(newData)
|
mapTypeHandle(newData)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
deep: true,
|
deep: false
|
||||||
immediate: true
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
//监听地图区域发生变化
|
//监听地图区域发生变化
|
||||||
watch(
|
watch(
|
||||||
() => props.chartConfig.option.mapRegion.adcode,
|
() => props.chartConfig.option.mapRegion.adcode,
|
||||||
newData => {
|
newData => {
|
||||||
mapRegionHandle(newData)
|
mapGeoHandle(newData)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
deep: true,
|
deep: false
|
||||||
immediate: true
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
//监听大小发生变化
|
//监听大小发生变化
|
||||||
watch(
|
watch(
|
||||||
() => props.chartConfig.option.series[1].zoom,
|
() => props.chartConfig.option.geo.zoom,
|
||||||
newData => {
|
newData => {
|
||||||
mapZoomHandle(newData)
|
mapZoomHandle(newData)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
deep: true,
|
deep: false
|
||||||
immediate: true
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user