On Oct 11, 7:54 am, Jennifer Dudeck <[email protected]> wrote: > I have polygons, representing different soil types, stored in a > database. What I am attempting to accomplish is to show only the > polygons currently in the viewing window. When the bounds or zoom is > changed, a function is enacted that gets the KML for a new KMLlayer > from a PHP script. All of this works just fine, but there is one > hitch. I want to remove the previous KMLlayer every time the bounds/ > zoom is changed, and replace it with the new KML. However, right now, > it is not removing the old KML, just adding the new polygons on top of > it. Can anyone help me figure out why my code is not removing the old > KML?
have you tried soils.setMap(null); to remove it? from the documentation: http://code.google.com/apis/maps/documentation/javascript/reference.html#KmlLayer setMap(map:Map) None Renders the KML Layer on the specified map. If map is set to null, the layer is removed. If that doesn't help, a link might get more assistance. -- Larry > > This is the event listener: > > google.maps.event.addListener(map, 'idle', showSoils); > > And this is the actual function: > > function showSoils() { > > //remove previous overlay > var soils = new google.maps.KmlLayer(); > > var zoomlevel = map.getZoom(); > > //if the zoom level is close enough > if(zoomlevel>13) > { > //obtain points in database-friendly format: > var bounds = map.getBounds(); > var ne = String(bounds.getNorthEast()); > var firstcomma = ne.search("[,]"); > firstlat = ne.substring(1, firstcomma); > firstlong = ne.substring(firstcomma+2, ne.length-1); > > var sw = String(bounds.getSouthWest()); > var firstcomma = sw.search("[,]"); > secondlat = sw.substring(1, firstcomma); > secondlong = sw.substring(firstcomma+2, sw.length-1); > > bcoords = firstlat + " " + firstlong + ", " + secondlat + " " + > firstlong + ", " + secondlat + " " + secondlong + ", " + firstlat + " > " + secondlong + ", " + firstlat + " " + firstlong; > > var soils = new google.maps.KmlLayer('http://myfarms.org/test/ > soils_in_view.php?bcoords=' + escape(bcoords), { map: map, > preserveViewport: true }); > } > } -- You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.
