feat: 添加点标记

This commit is contained in:
蒋承 2022-10-24 10:20:06 +08:00
parent e89dc9d0e7
commit 94b06552f2
3 changed files with 37 additions and 4 deletions

View File

@ -3,14 +3,15 @@ import { CreateComponentType } from '@/packages/index.d'
import { MapAmapConfig } from './index' import { MapAmapConfig } from './index'
import { chartInitConfig } from '@/settings/designSetting' import { chartInitConfig } from '@/settings/designSetting'
import cloneDeep from 'lodash/cloneDeep' import cloneDeep from 'lodash/cloneDeep'
import dataJson from './data.json'
export const option = { export const option = {
dataset: '', dataset: dataJson,
amapKey: 'aa76ad84f92f661980f710cbe966b7f6', amapKey: 'aa76ad84f92f661980f710cbe966b7f6',
amapStyleKey: 'normal', amapStyleKey: 'normal',
amapStyleKeyCustom: '', amapStyleKeyCustom: '',
amapLon: 116.39, amapLon: 116.397428,
amapLat: 40.91, amapLat: 39.90923,
amapZindex: 10, amapZindex: 10,
viewMode: '2D', viewMode: '2D',
pitch: 60, pitch: 60,

View File

@ -0,0 +1,17 @@
{
"points": [
{
"icon": "//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-1.png",
"position": [116.300467, 39.907761],
"title": "我是一个文本"
},
{
"icon": "//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-2.png",
"position": [116.368904, 39.913423]
},
{
"icon": "//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-3.png",
"position": [116.305467, 39.807761]
}
]
}

View File

@ -29,6 +29,7 @@ let {
} = toRefs(props.chartConfig.option) } = toRefs(props.chartConfig.option)
let map = shallowRef(null) let map = shallowRef(null)
let markers = ref([])
const ininMap = () => { const ininMap = () => {
AMapLoader.load({ AMapLoader.load({
@ -46,7 +47,20 @@ const ininMap = () => {
features: features.value, features: features.value,
pitch: pitch.value, // 0 - 83 pitch: pitch.value, // 0 - 83
skyColor: skyColor.value, skyColor: skyColor.value,
viewMode: viewMode.value, // viewMode: viewMode.value //
})
markers?.value.forEach((marker: any) => {
//
if (!/\d/.test(marker.icon || marker.position)) {
return
}
var marker = new AMap.Marker({
icon: marker?.icon,
position: [marker.position[0], marker.position[1]],
title: marker?.title,
offset: new AMap.Pixel(-13, -30)
})
marker.setMap(map)
}) })
}) })
.catch(e => {}) .catch(e => {})
@ -55,6 +69,7 @@ const ininMap = () => {
watch( watch(
() => props.chartConfig.option, () => props.chartConfig.option,
newData => { newData => {
markers.value = newData.dataset.points
ininMap() ininMap()
}, },
{ immediate: true, deep: true } { immediate: true, deep: true }