Did you try storing it in a global variable. Before you fetch the new kml, use the .setMap for the old KML file to Null. Now store the new kml into the old variable, then redisplay?
On Mon, Oct 11, 2010 at 8:24 PM, John M Phillips < [email protected]> wrote: > Since "soils" is created with a new command, you need to delete the > old value > before creating a new object. > > There may be better coding, such as testing for existance of soils, > but here is > what I have done in a similar situation > > 1) make soils global in your script in the outer most block with > var soils; > > 2) force a known creation of soils, note do not declare another > variable; > soils = new google.maps.KmlLayer( ... > > 3) to put new kml data > soils.setMap(null); // remove from > display; > delete soils; // delete > the objects data > soils = new google.maps.KmlLayer( ... // add new data to the > object > > On Oct 11, 11:26 am, "[email protected]" <[email protected]> > wrote: > > 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.h... > > 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]<google-maps-js-api-v3%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/google-maps-js-api-v3?hl=en. > > -- 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.
