vue高德地图使用小结
地图加载
<script
>
mounted(){
this.findYourData();
let self
= this;
setTimeout(function () {
self
.initMap();
},800)
}
methods
:{
initMap() {
this.location
= [this.data
.longitude
,this.data
.latitude
];
this.$mapUtil
.loadMap('2.0').then(AMap
=> {
this.map
= new AMap.Map('Maps', {
zoom
: 14,
center
: this.location
,
resizeEnable
: true,
mapStyle
: 'amap://styles/whitesmoke',
viewMode
: '2D',
lang
:'zh_cn',
})
}).catch(() => {
console
.log('地图加载失败!')
})
}
}
</script
>
地图添加标记点
let icon
= new AMap.Icon({
size
: new AMap.Size(43, 50),
image
: require('图像地址'),
imageOffset
: new AMap.Pixel(0,0),
imageSize
: new AMap.Size(43, 50)
});
var marker
= new AMap.Marker({
position
: [121.12,48.48],
map
: that
.map
,
icon
: icon
,
offset
: new AMap.Pixel(-25,-25)
})
this.map
.add(marker
)
marker
.setMap(this.map
)
this.map
.setFitView(marker
)
地图添加圆
var circle
= new AMap.Circle({
center
: [121.12,48.48],
radius
: 1000,
borderWeight
: 1,
strokeColor
: "#3070FF",
strokeOpacity
: 1,
strokeWeight
: 1,
fillOpacity
: 0.05,
strokeStyle
: 'solid',
strokeDasharray
: [10, 10],
fillColor
: '#3096FF',
zIndex
: 50,
})
circle
.setMap(this.map
)
地图添加轨迹
var polygon
= new AMap.Polygon({
path
:[[116.478935,39.997761],[116.484648,39.999861]],
strokeColor
: "#F56C6C",
strokeWeight
: 5,
strokeOpacity
: 0.6,
fillOpacity
: 0,
fillColor
: '#E6A23C',
showDir
:true,
zIndex
: 50,
})
polygon
.setMap(this.map
)
地图添加文本标记
var text
= new AMap.Text({
text
:'纯文本标记',
anchor
:'center',
draggable
:true,
cursor
:'pointer',
angle
:10,
style
:{
'padding': '.75rem 1.25rem',
'margin-bottom': '1rem',
'border-radius': '.25rem',
'background-color': 'white',
'width': '15rem',
'height': '15rem',
'border-width': 0,
'box-shadow': '0 2px 6px 0 rgba(114, 124, 245, .5)',
'text-align': 'center',
'font-size': '20px',
'color': 'blue'
},
position
: [116.396923,39.918203]
});
text
.setMap(map
);
转载请注明原文地址:https://tech.qufami.com/read-21146.html