feat: 添加点标记

This commit is contained in:
蒋承 2022-10-24 10:20:06 +08:00
parent ff7a0830d0
commit f8b645f867
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 { chartInitConfig } from '@/settings/designSetting'
import cloneDeep from 'lodash/cloneDeep'
import dataJson from './data.json'
export const option = {
dataset: '',
dataset: dataJson,
amapKey: 'aa76ad84f92f661980f710cbe966b7f6',
amapStyleKey: 'normal',
amapStyleKeyCustom: '',
amapLon: 116.39,
amapLat: 40.91,
amapLon: 116.397428,
amapLat: 39.90923,
amapZindex: 10,
viewMode: '2D',
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)
let map = shallowRef(null)
let markers = ref([])
const ininMap = () => {
AMapLoader.load({
@ -46,7 +47,20 @@ const ininMap = () => {
features: features.value,
pitch: pitch.value, // 0 - 83
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 => {})
@ -55,6 +69,7 @@ const ininMap = () => {
watch(
() => props.chartConfig.option,
newData => {
markers.value = newData.dataset.points
ininMap()
},
{ immediate: true, deep: true }