[OpenLayers-Users] Duplicate layers when adding GML layers
Scott Neville
scott07 at worldsofwar.co.uk
Thu May 12 18:08:17 EDT 2011
Hi,
When you add a GML layer programmatic after the map has been created (in
this instance from a GPX file loaded from the server) the layer shows
correctly. However when you zoom in the original path of the layer
remains shown on the map and the new path of the layer is also drawn.
When you zoom in again the path the layer took from both previous times
is shown, so when you have zoomed in 5/6 times the map is plastered in
many lines from the GPX file.
I have tested this in firefox 3 and 4 and its consistently reproducible.
The code I am using to add the layer to the map is called after the map
has been created when the user clicks a button and looks like this:
function plotButtonClick()
{
var tGPX = new OpenLayers.Layer.GML("GPX Track", "Location?action=gpx", {
format: OpenLayers.Format.GPX,
style: {strokeColor: "green", strokeWidth: 5, strokeOpacity: 0.5},
projection: new OpenLayers.Projection("EPSG:4326")
});
if (mLastShownGPX != null)
{
tIFrame.mMap.removeLayer(mLastShownGPX);
}
tIFrame.mMap.addLayer(tGPX);
mLastShownGPX = tGPX;
}
The mLastShownGPX variable is a page level variable, as there is the
option to remove the layer plotted and change it for another. The
tIFrame variable is an IFrame within the page that holds the map.
Anyway I guess I am doing something wrong so any help would be appreciated.
Thanks
More information about the Users
mailing list