[OpenLayers-Users] Feature collection array from GeoJSON format

Christopher Schmidt crschmidt at metacarta.com
Tue Mar 24 21:51:57 EDT 2009


On Wed, Mar 25, 2009 at 01:32:26PM +1300, Robert Connolly wrote:
> Hi Everyone,
> 
>  
> 
> I'm trying to extract features from a GeoJSON string using the GeoJSON
> format object. According to the documentation I'm supposed to be getting
> an array of OpenLayers.Feature.Vector items, however when I iterate over
> the array I just get zeros!
> 
>  
> 
> Here's a snippet of my code:
> 
>  
> 
> var features = geojson_format.read(data);
> 
> for(var feature in features)

1. features is an array. Arrays are not iterated over using 'for..in' in
javascript, instead:

  for (var i = 0; i < features.length; i++) {
    alert(features[i]);
  }

2. var feature in features syntx gives an index, not the object:

  for (var feature in features) {
    alert(features[feature]);
  }

-- Chris

> {
> 
>                alert(feature);
> 
> }
> 
>  
> 
> The alert box just alerts '0' (zero), for some reason. Does anyone know
> what's going on?
> 
>  
> 
> Thanks in advance,
> 
>  
> 
> Cheers,
> 
>  
> 
> Rob Connolly
> 

> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users


-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list