1
I’m having trouble deleting circle type objects (API google-maps) that are being shown on my map.
I have a function that receives JSON data and creates a global array (arrayElements) containing objects (element) that have: JSON information and an object (circle) google maps API circle. When I do a search ( get a new JSON), I access arrayElements, and for each element, i access the circle and execute the function circle.setMap(null), however, the problem is that some circles erase while others remain. I have debug, but n managed to identify the error.
var arrayElementos = [];
function setMapElements(mJsonData) {
if(arrayElementos.length==0){
var elementOptions = {
strokeColor: "#FF0000",
strokeOpacity: 0.8,
strokeWeight: 1,
fillColor: "#FF0000",
fillOpacity: 0.35,
map: map,
center: {},
radius: Math.sqrt(1) * 50
};
var elemento = {
idade:{},
genero:{},
circulo:{}
};
$.each(mJsonData, function(id,data){
elementOptions.center = new google.maps.LatLng(data.latitude,data.longitude);
elemento.genero = data.sexo;
elemento.idade = data.idade;
elemento.circulo = new google.maps.Circle(elementOptions);
mapElements.push(elemento);
});
}else{
$.each(arrayElementos, function(id,elemento){
elemento.circulo.setMap(null);
});
arrayElementos = [];
setMapElements(mJsonData);
}
};
I have no way of testing whether my answer completely solves your problem. Next time try to create a simplified version of your problem that fits all within your question and doesn’t depend on google maps, global json vectors, etc. If it’s small enough not to need a better scrollbar yet :)
– hugomg