I'm using geoxml3 to display KML files on Google Maps. I made script with which different KML layers can be turned on and off. Although every layer turns on as expected, when trying to turn off one layer, turns off another.
var G = google.maps;
var layers = new function() {this.data = [
{id:'japan',url:'kvadrati.kml'},
{id:'d1', url:'Didzis_21.03-03.04.kml'},
{id:'d2', url:'Didzis_04.04-17.04.kml'},
... ]};
function toggle() {for (var i=0; i<layers.data.length; i++) {
if (this.id == layers.data[i].id) {
if (layers.data[i].parsed) {
if (layers.data[i].on)
{geo.hideDocument(geo.docs[i]); layers.data[i].on = false}
else {geo.showDocument(geo.docs[i]); layers.data[i].on = true}}
else {geo.parse(layers.data[i].url); layers.data[i].parsed = true; layers.data[i].on = true}}
};};
function initialize() {
var options = {
center:new G.LatLng(34.9, 137.3),
zoom:10,
mapTypeId:G.MapTypeId.TERRAIN,
scaleControl:true,
overviewMapControl:true,
mapTypeControlOptions:{style:G.MapTypeControlStyle.DROPDOWN_MENU}
};
map = new G.Map(document.getElementById('map'), options);
geo = new geoXML3.parser({
map:map,
zoom:false,
singleInfoWindow:true,
infoWindowOptions:{maxWidth:100},
processStyles:true,
markerOptions:{shadow:''}
});
var el = document.getElementsByTagName('input');
for (var i=0; i<el.length; i++) {
el[i].type = 'checkbox';
G.event.addDomListener(el[i], 'click', toggle)};
};
G.event.addDomListener(window, 'load', initialize);
I'm sure that problem is in function toggle() where appears:
geo.[show/hide]Document(geo.docs[i]);
Test it here. It takes quite a long time to load a layer because they are in uncompressed (KML) format. I read that geoxml3 should support KMZ files, I even copied every file from this example but it wasn't working for me. Anybody knows why so?