openlayer map.clearOverlays() 不能清除地图上生成的信息
我用openlayer在地图上绘制地图覆盖物时,发现一个问题,
后来我发现这些覆盖物都是在地图上的单独DIV,
就用了个比较笨的方法。用FOR循环,找出地图上覆盖物的ID,再移除
。代码为下:
function clearDiv(){
//找出地图上所有的覆盖DIV
for(var i=0;i<D.length;i++){
//如果此覆盖物存在子DIV,且通过子DIV的ID得知是我们需要移除的DIV
if(map.D.children[i].firstElementChild && map.D.children[i].firstElementChild.id == "lengthLabel"){
//移除
map.D.children[i].firstElementChild.remove();
}
}
}
希望能给遇到相同问题的人提供帮助
转载自:https://blog.csdn.net/bailiran1/article/details/81280247