feat: 增加可选省份地图

This commit is contained in:
刘嘉威 2022-09-22 17:09:26 +08:00
parent e4ed2392bb
commit 2ed1b4bf23
43 changed files with 26414 additions and 1 deletions

View File

@ -0,0 +1,194 @@
import { echartOptionProfixHandle, PublicConfigClass } from '@/packages/public'
import { MapConfig } from './index'
import { chartInitConfig } from '@/settings/designSetting'
import { CreateComponentType } from '@/packages/index.d'
import dataJson from './data.json'
export const includes = []
export const option = {
dataset: dataJson,
mapRegion: {
adcode: 'china',
},
tooltip: {
show: true,
trigger: 'item'
},
visualMap: {
show: true,
pieces: [
{ gte: 1000, label: "1000个以上" }, // 不指定 max表示 max 为无限大Infinity
{ gte: 600, lte: 999, label: "600-999个" },
{ gte: 200, lte: 599, label: "200-599个" },
{ gte: 50, lte: 199, label: "49-199个" },
{ gte: 10, lte: 49, label: "10-49个" },
{ lte: 9, label: "1-9个" }, // 不指定 min表示 min 为无限大(-Infinity
],
inRange: {
// 渐变颜色,从小到大
color: [
"#c3d7df",
"#5cb3cc",
"#8abcd1",
"#66a9c9",
"#2f90b9",
"#1781b5",
],
},
textStyle: {
color: "#fff",
},
},
geo: {
type: 'map',
roam: false,
map: "china",
selectedMode: false, //是否允许选中多个区域
// aspectScale: 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: [
{
name: '',
type: "effectScatter",
coordinateSystem: "geo",
symbolSize: 4,
legendHoverLink: true,
showEffectOn: "render",
rippleEffect: {
scale: 6,
color: "#FFFFFF",
brushType: "fill",
},
tooltip: {
show: true,
// formatter: function (params:any) {
// console.log(params);
// if (params.data) {
// return params.name + "" + params.data["value"][2];
// }
// },
// formatter:"{a}: {b}<br />{c}: {d}",
backgroundColor: "rgba(0,0,0,.6)",
borderColor: "rgba(147, 235, 248, .8)",
textStyle: {
color: "#FFF",
},
},
label: {
// formatter: (param: any) => {
// return param.name.slice(0, 2);
// },
formatter: '{b}',
// formatter: '{a}: {b}<br />{c}: {d}{e}',
fontSize: 11,
offset: [0, 2],
position: "bottom",
textBorderColor: "#fff",
textShadowColor: "#000",
textShadowBlur: 10,
textBorderWidth: 0,
color: "#FFF",
show: true,
},
// colorBy: "data",
itemStyle: {
color: "#FFFFFF",
borderColor: "rgba(225,255,255,2)",
borderWidth: 4,
shadowColor: "#E1FFFF",
shadowBlur: 10,
},
data: []
},
{
name: '区域',
type: "map",
map: "china",
// aspectScale: 1,
data: [],
selectedMode: false, //是否允许选中多个区域
zoom: 1,
geoIndex: 1,
tooltip: {
show: true,
backgroundColor: "rgba(0,0,0,.6)",
borderColor: "rgba(147, 235, 248, .8)",
textStyle: {
color: "#FFF",
},
},
label: {
show: false,
color: "#000",
// formatter: function (val:any) {
// // console.log(val)
// if (val.data !== undefined) {
// return val.name.slice(0, 2);
// } else {
// return "";
// }
// },
rich: {},
emphasis: { show: false },
},
itemStyle: {
// borderColor: "rgba(147, 235, 248, .8)",
borderColor: '#93EBF8',
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,
},
shadowColor: "#80D9F842",
shadowOffsetX: -2,
shadowOffsetY: 2,
shadowBlur: 10,
emphasis: {
disabled:false,
areaColor: "#389BB7",
shadowColor:"#389BB7",
borderWidth: 1,
},
showHainanIsLands: true,
},
}
]
}
export const MapDefaultConfig = { ...option }
export default class Config extends PublicConfigClass implements CreateComponentType {
public key: string = MapConfig.key
public attr = { ...chartInitConfig, w: 750, h: 800, zIndex: -1 }
public chartConfig = MapConfig
public option = echartOptionProfixHandle(option, includes)
}

View File

@ -0,0 +1,194 @@
<template>
<!-- Echarts 全局设置 -->
<global-setting :optionData="optionData"></global-setting>
<CollapseItem name="地图" :expanded="true">
<SettingItemBox name="地图区域">
<SettingItem name="默认中国">
<n-select size="small" v-model:value="mapRegion.adcode" :options="mapRegionOptions" value-field="adcode" label-field="name"/>
</SettingItem>
<SettingItem name="大小">
<n-input-number
v-model:value="seriesList[1].zoom"
:min="1"
size="small"
placeholder="请输入地图大小"
></n-input-number>
</SettingItem>
</SettingItemBox>
<SettingItemBox name="区域颜色" :alone="true">
<SettingItem name="0%处颜色">
<n-color-picker
size="small"
:modes="['hex']"
v-model:value="seriesList[1].itemStyle.areaColor.colorStops[0].color"
></n-color-picker>
</SettingItem>
<SettingItem name="100%处颜色">
<n-color-picker
size="small"
:modes="['hex']"
v-model:value="seriesList[1].itemStyle.areaColor.colorStops[1].color"
></n-color-picker>
</SettingItem>
</SettingItemBox>
<SettingItemBox name="阴影" >
<SettingItem name="颜色">
<n-color-picker
size="small"
:modes="['hex']"
v-model:value="seriesList[1].itemStyle.shadowColor"
></n-color-picker>
</SettingItem>
<SettingItem name="模糊程度">
<n-input-number
v-model:value="seriesList[1].itemStyle.shadowBlur"
size="small"
placeholder="请输入模糊程度"
></n-input-number>
</SettingItem>
<SettingItem name="水平偏移">
<n-input-number
v-model:value="seriesList[1].itemStyle.shadowOffsetX"
size="small"
placeholder="请输入水平偏移大小"
></n-input-number>
</SettingItem>
<SettingItem name="垂直偏移">
<n-input-number
v-model:value="seriesList[1].itemStyle.shadowOffsetY"
size="small"
placeholder="请输入垂直偏移大小"
></n-input-number>
</SettingItem>
</SettingItemBox>
<SettingItemBox name="聚焦" >
<!-- <setting-item name="禁用">
<n-space>
<n-switch v-model:value="seriesList[1].itemStyle.emphasis.disabled" size="small"></n-switch>
</n-space>
</setting-item> -->
<SettingItem name="颜色(预览可见)">
<n-color-picker
size="small"
:modes="['hex']"
v-model:value="seriesList[1].itemStyle.emphasis.areaColor"
></n-color-picker>
</SettingItem>
<SettingItem name="阴影(预览可见)">
<n-color-picker
size="small"
:modes="['hex']"
v-model:value="seriesList[1].itemStyle.emphasis.shadowColor"
></n-color-picker>
</SettingItem>
<SettingItem name="边框大小(预览)">
<n-input-number
v-model:value="seriesList[1].itemStyle.emphasis.borderWidth"
:min="1"
size="small"
placeholder="请输入边框大小"
></n-input-number>
</SettingItem>
</SettingItemBox>
<SettingItemBox name="边框">
<SettingItem name="颜色">
<n-color-picker
size="small"
:modes="['hex']"
v-model:value="seriesList[1].itemStyle.borderColor"
></n-color-picker>
</SettingItem>
<SettingItem name="大小">
<n-input-number
v-model:value="seriesList[1].itemStyle.borderWidth"
:min="1"
size="small"
placeholder="请输入边框大小"
></n-input-number>
</SettingItem>
</SettingItemBox>
<SettingItemBox name="其他" v-if="mapRegion.adcode==='china'">
<SettingItem >
<n-checkbox v-model:checked="seriesList[1].itemStyle.showHainanIsLands" size="small">显示南海群岛</n-checkbox>
</SettingItem>
</SettingItemBox>
</CollapseItem>
<CollapseItem name="标记" :expanded="true">
<SettingItemBox name="样式">
<SettingItem name="大小">
<n-input-number v-model:value="seriesList[0].symbolSize" size="small" :min="0"></n-input-number>
</SettingItem>
<SettingItem name="颜色">
<n-color-picker size="small" :modes="['hex']" v-model:value="seriesList[0].itemStyle.color"></n-color-picker>
</SettingItem>
</SettingItemBox>
<SettingItemBox name="涟漪">
<SettingItem name="涟漪大小">
<n-input-number
v-model:value="seriesList[0].rippleEffect.scale"
:min="1"
size="small"
placeholder="请输入涟漪大小"
></n-input-number>
</SettingItem>
<SettingItem name="涟漪颜色">
<n-color-picker size="small" :modes="['hex']" v-model:value="seriesList[0].rippleEffect.color"></n-color-picker>
</SettingItem>
<SettingItem name="涟漪的绘制方式">
<n-select size="small" v-model:value="seriesList[0].rippleEffect.brushType" :options="rippleEffectOptions"/>
</SettingItem>
</SettingItemBox>
</CollapseItem>
</template>
<script setup lang="ts">
import { PropType, computed } from 'vue'
import { CollapseItem, SettingItemBox, SettingItem } from '@/components/Pages/ChartItemSetting'
import { lineConf } from '@/packages/chartConfiguration/echarts/index'
import { GlobalThemeJsonType } from '@/settings/chartThemes/index'
import { GlobalSetting } from '@/components/Pages/ChartItemSetting'
import { ref } from 'vue'
import mapChinaJson from './mapGeojson/china.json'
const mapRegionOptions=ref([
{
adcode:'china',
name:'中国',
}
])
const rippleEffectOptions=ref([
{
value:'fill',
label:'实心',
},{
value:'stroke',
label:'空心',
}
])
const props = defineProps({
optionData: {
type: Object as PropType<GlobalThemeJsonType>,
required: true
}
})
const initMapRegionOptions=()=>{
mapChinaJson.features.forEach((element:any) => {
if(element.properties.name){
mapRegionOptions.value.push({...element.properties})
}
});
}
initMapRegionOptions()
const seriesList = computed(() => {
return props.optionData.series
})
const mapRegion = computed(() => {
return props.optionData.mapRegion
})
</script>

View File

@ -0,0 +1,76 @@
{
"point": [
{
"name": "北京",
"value": [116.405285, 39.904989, 200],
"label":666
},
{
"name": "郑州",
"value": [113.665412, 34.757975,888],
"label":666
},
{
"name":"青海",
"value":[101.778916, 36.623178,666],
"label":666
},
{
"name":"宁夏回族自治区",
"value":[106.278179, 38.46637,66],
"label":666
} ,
{
"name":"哈尔滨市",
"value":[126.642464, 45.756967,101],
"label":666
}
],
"map": [
{
"name": "北京市",
"value": 666
},
{
"name": "河北省",
"value": 98
},
{
"name": "江苏省",
"value": 300
},
{
"name": "福建省",
"value": 1199
},
{
"name": "山东省",
"value": 86
},
{
"name": "河南省",
"value": 850
},
{
"name": "湖北省",
"value": 84
},
{
"name": "广西壮族自治区",
"value": 81
},
{
"name": "海南省",
"value": 900
},
{
"name": "青海省",
"value": 800
},
{
"name": "新疆维吾尔自治区",
"value": 7
}
]
}

View File

@ -0,0 +1,15 @@
import { ConfigType, PackagesCategoryEnum, ChartFrameEnum } from '@/packages/index.d'
import image from '@/assets/images/chart/charts/map.png'
import { ChatCategoryEnum, ChatCategoryEnumName } from '../../index.d'
export const MapConfig: ConfigType = {
key: 'MapBase',
chartKey: 'VMapBase',
conKey: 'VCMapBase',
title: '地图(可选省份)',
category: ChatCategoryEnum.MAP,
categoryName: ChatCategoryEnumName.MAP,
package: PackagesCategoryEnum.CHARTS,
chartFrame: ChartFrameEnum.COMMON,
image
}

View File

@ -0,0 +1,183 @@
<template>
<v-chart ref="vChartRef" :theme="themeColor" :option="option.value" :manual-update="isPreview()" autoresize>
</v-chart>
</template>
<script setup lang="ts">
import { PropType, reactive, watch } from 'vue'
import config, { includes, MapDefaultConfig } from './config'
import VChart from 'vue-echarts'
import { use, registerMap, getMap } from 'echarts/core'
import { EffectScatterChart, MapChart } from 'echarts/charts'
import { CanvasRenderer } from 'echarts/renderers'
import { useChartDataFetch } from '@/hooks'
import { mergeTheme } from '@/packages/public/chart'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { isPreview } from '@/utils'
import mapJsonWithoutHainanIsLands from './mapWithoutHainanIsLands.json'
import {
DatasetComponent,
GridComponent,
TooltipComponent,
LegendComponent,
GeoComponent,
VisualMapComponent
} from 'echarts/components'
const props = defineProps({
themeSetting: {
type: Object,
required: true
},
themeColor: {
type: Object,
required: true
},
chartConfig: {
type: Object as PropType<config>,
required: true
}
})
use([
MapChart,
DatasetComponent,
CanvasRenderer,
GridComponent,
TooltipComponent,
LegendComponent,
GeoComponent,
EffectScatterChart,
VisualMapComponent
])
const option = reactive({
value: mergeTheme(props.chartConfig.option, props.themeSetting, includes),
})
// 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
const getGeojson = (regionId: string) => {
return new Promise<boolean>((resolve, reject) => {
import(`./mapGeojson/${regionId}.json`).then(data => {
console.log({data});
registerMap(regionId, { geoJSON: data.default as any, specialAreas: {} })
resolve(true)
})
})
}
//
registerMap(props.chartConfig.option.mapRegion.adcode, { geoJSON: {} as any, specialAreas: {} })
//
const registerMapModulesAsync= async ()=>{
await getGeojson(props.chartConfig.option.mapRegion.adcode)
}
registerMapModulesAsync()
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 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
}
//
const mapTypeHandle = async (show: boolean) => {
if (show) {
await getGeojson("china")
// registerMap('china', { geoJSON: mapJsonModules["china"] as any, specialAreas: {} })
} else {
registerMap('china', { geoJSON: mapJsonWithoutHainanIsLands as any, specialAreas: {} })
}
updateOptions()
}
//
const mapZoomHandle = async (newData: number) => {
props.chartConfig.option.geo.zoom = newData
updateOptions()
}
//
const mapRegionHandle = async (newData: string) => {
await getGeojson(newData)
// registerMapModules()
mapGeoHandle(newData)
}
//
watch(
() => props.chartConfig.option.dataset,
newData => {
dataSetHandle(newData)
},
{
immediate: true,
deep: false
}
)
//
watch(
() => props.chartConfig.option.series[1].itemStyle.showHainanIsLands,
newData => {
mapTypeHandle(newData)
},
{
deep: true,
immediate: true
}
)
//
watch(
() => props.chartConfig.option.mapRegion.adcode,
newData => {
mapRegionHandle(newData)
},
{
deep: true,
immediate: true
}
)
//
watch(
() => props.chartConfig.option.series[1].zoom,
newData => {
mapZoomHandle(newData)
},
{
deep: true,
immediate: true
}
)
//
useChartDataFetch(props.chartConfig, useChartEditStore, (newData: any) => {
console.log('预览', newData)
dataSetHandle(newData)
})
</script>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"adcode":710000,"name":"台湾省","center":[121.509062,25.044332],"centroid":[120.971485,23.749452],"childrenNum":0,"level":"province","acroutes":[100000],"parent":{"adcode":100000}},"geometry":{"type":"MultiPolygon","coordinates":[[[[120.443558,22.441245],[120.517584,22.408536],[120.569903,22.361728],[120.640505,22.241347],[120.659209,22.15432],[120.662001,22.066983],[120.651464,22.033165],[120.667691,21.983168],[120.70157,21.927065],[120.743246,21.915569],[120.78155,21.923957],[120.85468,21.883333],[120.87291,21.897387],[120.866482,21.98436],[120.907315,22.033208],[120.904154,22.119757],[120.914955,22.302718],[120.981658,22.528305],[121.015009,22.584168],[121.033292,22.650725],[121.078498,22.669656],[121.170544,22.723133],[121.210481,22.770665],[121.237931,22.836327],[121.324708,22.945666],[121.354687,23.01006],[121.370388,23.084347],[121.409535,23.102669],[121.430294,23.137196],[121.415015,23.195973],[121.440358,23.272096],[121.479558,23.3223],[121.497788,23.419789],[121.521497,23.483198],[121.523078,23.538708],[121.587778,23.76102],[121.621604,23.92075],[121.659381,24.006893],[121.639992,24.064276],[121.643838,24.097713],[121.678085,24.133906],[121.689044,24.174401],[121.809172,24.339055],[121.826717,24.423579],[121.867498,24.478978],[121.885464,24.529677],[121.892524,24.617912],[121.862598,24.671515],[121.837993,24.76015],[121.845053,24.836269],[121.932883,24.938645],[122.012178,25.001469],[121.980776,25.03079],[121.947425,25.031955],[121.917077,25.137908],[121.842155,25.135332],[121.782407,25.160425],[121.750531,25.160716],[121.707327,25.191493],[121.700319,25.226913],[121.655324,25.241859],[121.623026,25.294694],[121.584986,25.308926],[121.535038,25.307515],[121.444415,25.270624],[121.413487,25.238912],[121.371864,25.159885],[121.319281,25.140691],[121.209322,25.127104],[121.133135,25.078728],[121.102102,25.075153],[121.024704,25.040479],[121.009688,24.993649],[120.960899,24.940227],[120.908475,24.852012],[120.892299,24.767526],[120.823753,24.688321],[120.762371,24.658335],[120.688661,24.600678],[120.64277,24.490172],[120.589187,24.432354],[120.546299,24.370413],[120.521009,24.312038],[120.470534,24.24259],[120.451461,24.182691],[120.392029,24.11824],[120.316158,23.984881],[120.278276,23.927798],[120.245768,23.840553],[120.175377,23.807385],[120.102773,23.700981],[120.094817,23.587466],[120.121741,23.504664],[120.107831,23.341264],[120.081434,23.29191],[120.018947,23.073115],[120.029537,23.048623],[120.131382,23.002118],[120.149138,22.896715],[120.200403,22.721101],[120.274272,22.560181],[120.297191,22.531315],[120.443558,22.441245]]],[[[124.542984,25.903911],[124.586346,25.913777],[124.572805,25.93974],[124.541825,25.931031],[124.542984,25.903911]]],[[[123.445286,25.725966],[123.472104,25.713024],[123.508933,25.723237],[123.514834,25.751226],[123.483063,25.768587],[123.444496,25.746514],[123.445286,25.725966]]],[[[119.64597,23.55091],[119.701081,23.550657],[119.678057,23.600041],[119.610089,23.603953],[119.594388,23.577245],[119.566306,23.584732],[119.562565,23.530377],[119.573788,23.505885],[119.609141,23.503864],[119.64597,23.55091]]],[[[123.667207,25.914066],[123.707092,25.916873],[123.678008,25.938667],[123.667207,25.914066]]],[[[119.506031,23.625567],[119.505241,23.575814],[119.472416,23.557136],[119.523207,23.563699],[119.525578,23.624895],[119.506031,23.625567]]],[[[119.49739,23.386683],[119.495125,23.350156],[119.516885,23.349903],[119.49739,23.386683]]],[[[119.557454,23.666474],[119.604083,23.616989],[119.615516,23.660925],[119.586485,23.675974],[119.557454,23.666474]]],[[[121.46823,22.676644],[121.476502,22.64166],[121.513541,22.631833],[121.5147,22.67639],[121.46823,22.676644]]],[[[121.510538,22.087185],[121.507693,22.048523],[121.534089,22.022146],[121.594522,21.995382],[121.604586,22.022699],[121.575028,22.037122],[121.575607,22.084421],[121.510538,22.087185]]],[[[122.097533,25.500168],[122.093581,25.47183],[122.124825,25.475932],[122.097533,25.500168]]],[[[119.421467,23.216684],[119.421309,23.18935],[119.453396,23.217697],[119.421467,23.216684]]],[[[120.355042,22.327259],[120.395454,22.342287],[120.383072,22.355573],[120.355042,22.327259]]]]}}]}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,4 @@
{
"type":"FeatureCollection",
"features":[]
}

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,4 @@
import { MapChinaConfig } from './MapChina/index'
import { MapConfig } from './MapBase/index'
export default [MapChinaConfig]
export default [MapChinaConfig,MapConfig]