今天讨论这样一个场景:根据一组给定的坐标来绘制很多很多的多边形,并且在一个事件里面清除所有的形状,我用的是高德地图api,有的细节和思路在文档里面不能快速找到清晰的说明,大家看了以下的代码希望能有所启发
绘制图像:
items.map(item => {
let { fenceid, fence } = item;
const pathPoint = fence.map(value => {
return [x, y];
});
let polygon = new AMap.Polygon({
path: pathPoint,
strokeWeight: 1,
strokeColor: '#ff8f1f',
strokeOpacity: 0.9,
fillColor: '#4876FF',
fillOpacity: 0,
map: this.map
});
this.cache[fenceid] = {
fence,
polygon
};
polygon.setMap(this.map);
});
清除图像:
clearFence = ()=>{
if(this.cache){
for(let i in this.cache){
var _i = i;
this.cache[i].polygon.hide();
}
this.cache = {};
}
return;
}
网友评论