AMapLoader.load({
key: 'XXXXXX', // 开发者Key必填
version: '2.0' // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
}).then((AMap) => {
const map = new AMap.Map('container', {
//设置地图容器id
resizeEnable: true,
center: [val.location.lng, val.location.lat],
zoomEnable: false,
autoFitView: true,
dragEnable: false,
zoom: [2, 22] //初始化地图级别
})
// var overlays = map.getAllOverlays()
AMap.plugin(['AMap.PlaceSearch'], function () {
var placeSearch = new AMap.PlaceSearch({
map
})
select(val)
function select(val) {
allPoi.value = val
var circle = new AMap.Circle({
center: new AMap.LngLat(val?.location?.lng ?? '', val?.location?.lat ?? ''), // 圆心位置
radius: 800,
autoFitView: true,
strokeColor: '#6C77F9',
strokeOpacity: 0,
strokeWeight: 0,
fillColor: '#6C77F9',
fillOpacity: 0.3
})
placeSearch.search(val?.name ?? '', ()=> {
// 注:获取坑货高德搜索完自己创建的标点覆盖物
var overlays = map.getAllOverlays()
// 移除点,坑我好久
map.remove(overlays)
// placeSearch.render.markerList.clear()
// 添加自定义标点(清除完再添加)
map.add(circle)
map.setFitView()
})
}
})
效果:::
})