[OpenLayers-Dev] initialise layer.vector with features doesn't work

Eric Lemoine eric.lemoine at camptocamp.com
Thu Aug 25 07:51:46 EDT 2011


On Thu, Aug 25, 2011 at 12:41 PM, Steven M. Ottens <steven at minst.net> wrote:
> Hi all,
>
> I'm trying to initialise a vector layer directly with features eg:
> var params = { features: new OpenLayers.Geometry.Point(5,52) };
> layer = new OpenLayers.Layer.Vector('name', params);
>
> However, the Vector class initialises with an empty features array and
> overrides my passed in features array, see line 267:
> http://trac.osgeo.org/openlayers/browser/trunk/openlayers/lib/OpenLayers/Layer/Vector.js#L267
>
> The API docs suggest it is possible to pass in features, although doesn't
> explicitly say so (
> http://dev.openlayers.org/apidocs/files/OpenLayers/Layer/Vector-js.html#OpenLayers.Layer.Vector.features
> )
>
> Is this a bug or a feature?
>
> If it is a feature what is the preferred way to initialise a vector layer
> with a feature? Or should I first initialise the vector layer and then use
> addFeature()?

Hi Steven

Currently addFeatures is the only way. But I agree it'd be good to be
able to pass features to the constructor.


-- 
Eric Lemoine

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex

Tel : 00 33 4 79 44 44 96
Mail : eric.lemoine at camptocamp.com
http://www.camptocamp.com


More information about the Dev mailing list