Como definir a visibilidade de polígonos no Gmap
Utilizando o seguinte código, eu consigo exibir as marcações e escondê-las conforme o checkbox do filtro, porém ao tentar esconder os polígonos, ele não o faz. Não há erros no console.
function initialize() {
var a = new google.maps.LatLng(-9.6457169, -36.4931743),
b = {
zoom: 10,
scrollwheel: !1,
center: a,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("mapa"), b)
}
function abrirInfoBox(a, b) {
"string" == typeof idInfoBoxAberto && "object" == typeof infoBox[idInfoBoxAberto] && infoBox[idInfoBoxAberto].close(), console.log(infoBox[a]);
try {
infoBox[a].open(map, b)
} catch (c) {}
idInfoBoxAberto = a
}
function carregarPontos() {
$.post("/mapa/markers", function(a) {
var b = new google.maps.LatLngBounds;
$.each(a, function(a, c) {
try {
if (c.Latitude.length > 0) {
var d = new google.maps.Marker({
position: new google.maps.LatLng(c.Latitude, c.Longitude),
title: c.Titulo,
slug: c.icone,
icon: "../img/layout/icones/" + c.icone + ".png"
}),
e = {
content: "<p>" + c.Descricao + "</p>",
pixelOffset: new google.maps.Size(-150, 0)
};
infoBox[c.Id] = new InfoBox(e), infoBox[c.Id].marker = d, infoBox[c.Id].listener = google.maps.event.addListener(d, "click", function() {
abrirInfoBox(c.Id, d)
}), markers.push(d), b.extend(d.position)
} else if (c.json.length > 0) {
var f = [];
$.each($.parseJSON(c.json), function(a, b) {
f[a] = new google.maps.LatLng(b.lat, b.lng)
}), overlays[a] = new google.maps.Polygon({
paths: f,
strokeColor: "#" + c.cor,
strokeOpacity: .8,
strokeWeight: 3,
fillColor: "#" + c.cor,
fillOpacity: .35
}), overlays[a].setMap(map)
}
} catch (g) {}
});
new MarkerClusterer(map, markers)
return overlays;
}, "json");
}
function doFilter() {
data = dataTeste;
for (var a = $("input[type=checkbox]:checked"), b = [], c = 0, d = a.length; d > c; c++) b.push($(a[c]).val());
$.each(markers, function(a, c) {
var d = !1;
return $.each(b, function(b, e) {
if (d === !1) try {
e == c.slug ? (d = !0, markers[a].setVisible(!0)) : markers[a].setVisible(!1)
} catch (f) {}
}), d === !0 ? !0 : void 0
})
}
var map, idInfoBoxAberto, infoBox = [], markers = [], overlays = [], dataTeste = {};
initialize();
dataTeste = carregarPontos();
console.log(typeof dataTeste);
$(document).on("click", "input[type=checkbox]", doFilter);
$(".overlay").bind("click", function(abc) {
obj = $(this),
$.each(dataTeste, function(a, b) {
b.icone == obj.val() && (overlays[a].setMap(obj.is(":checked") ? map : null), console.log("1"))
})
});
Os filtros ara os polígonos possuem a classe "overlay"
Discussão (1)
Carregando comentários...