How can I port this to v3? removeOverlay is not included in v3.
if( mapElements[lMapElementIndex]['marker'] != 0 ){
//map.removeOverlay(mapElements[lMapElementIndex]['marker']); V2
}
V3?
if( mapElements[lMapElementIndex]['marker'] != 0 ){
//map.removeOverlay(mapElements[lMapElementIndex]['marker']);
mapElements(mapElements[lMapElementIndex]['marker']).setMap(null);
} //but throws an error mapElements is not a function
You need to use the setMap
method of the overlay. From the docs:
To remove an overlay from a map, call the overlay's
setMap()
method, passingnull
.
Assuming mapElements
is an array of objects, and that the marker
property refers to an overlay instance, then all you need to do is:
mapElements[lMapElementIndex]['marker'].setMap(null);
Your attempt throws an error because you are trying to call mapElements
as a function (when it appears to be an array). There is no need for that. Just get rid of the function call and it should work fine.