[OpenLayers-Dev] Layer.GML how to access the XML?

Christopher Schmidt crschmidt at metacarta.com
Mon May 4 15:37:42 EDT 2009


On Mon, May 04, 2009 at 11:46:34AM -0700, gwales wrote:
> I could see from firebug that features[0].geometry was possibly the answer
> to my issue but on trying to access features[0] i get 'undefined' and if try
> to go deeper than that I get an error.
> 
> Code is:
>              // Add the Layer with GPX Track
>              var lgpx = new OpenLayers.Layer.GML("MMGPX",
> "TrackLogs/MM_TL_1.gpx", {
>                  format: OpenLayers.Format.GPX,
>                  style: {strokeColor: "blue", strokeWidth: 5, strokeOpacity:
> 0.5},
>                  projection: new OpenLayers.Projection("EPSG:4326")
>              });
>              map.addLayer(lgpx);
>  
>         	console.log(lgpx);
>         	var featGeom=lgpx.features[0].geometry;
>         	console.log(featGeom);
> 
> I am unsure what I am doing incorrectly in trying to access that linestring?

Data is loaded asynchronously. use: layer.events.register("loadend",
layer, function() {
console.log(this.features[0].geometry.components.length); });

-- 
Christopher Schmidt
MetaCarta



More information about the Dev mailing list