Hi,
The time it takes is the time for the request to be sent, received
and read by OpenLayers. It's a normal behavior. Instead of calling
your "setNewMapCenter()" with a delay, you could call it when you
routeGpx layer has new features added to it. Do so by registering a
"featuresadded" event to it and to call your method there.
// untested, but should work
routeGpx.events.register("featuresadded", routeGpx, setNewMapCenter);
// instead of
// setTimeout("setNewMapCenter()", timeOut);
Also, add some properties to your setNewMapCenter method and check them
in Firebug. You'll see that you have scope to your layer and access to
your added features too.
Finally, you could use only one Vector layer and change the url
accordingly instead of creating new ones every time.
Best of luck,
Alexandre
On 11-01-12 11:24 AM, har.eck wrote:
Hi all,
This situation: I add a vector layer with GPX file to my map. After
this I will get the features from vector layer with GPX data to set a
new center and zoom of map. To get the features I have to add a delay
about 15 ms else the features are undefined.
Here a code snip:
var routeGpx, map;
function newOverlayLayer(routeName, routeUrl, timeOut){
routeGpx = new OpenLayers.Layer.Vector(
routeName,
{
protocol: new OpenLayers.Protocol.HTTP({
url: routeUrl,
format: new OpenLayers.Format.GPX()
}),
strategies: [new OpenLayers.Strategy.Fixed()],
displayInLayerSwitcher: false,
style: {strokeColor: "blue", strokeWidth: 4, strokeOpacity: 0.5},
projection: new OpenLayers.Projection("EPSG:4326")
}
);
routeGpx.setVisibility(true);
map.addLayer(routeGpx);
setTimeout("setNewMapCenter()", timeOut);
}
function setNewMapCenter(){
myFeature = routeGpx.features[0];
if(myFeature){
layerBounds = myFeature.geometry.getBounds();
mapCenter = layerBounds.getCenterLonLat();
mapZoom = map.getZoomForExtent(layerBounds, false);
map.setCenter(mapCenter, mapZoom - 1);
}
else {
alert("myFeature " + myFeature);
}
}
I have this illustrated here:
http://www.hareck.lima-city.de/OL/testol-wms-if-vector.html
Is this behavior normal, what is the reason for such long delay?
Or is there a better solution for feature request available?
Thanks Hareck
_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users
--
Alexandre Dubé
Mapgears
www.mapgears.com
_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users