[OpenLayers-Users] Openlayers.Feature.Vector cloning

Christopher Schmidt crschmidt at metacarta.com
Thu Feb 7 09:54:12 EST 2008


On Thu, Feb 07, 2008 at 02:37:24PM +0100, François Van Der Biest wrote:
> Hi list,
> 
> I'm showing some vector features on my map, which come from a GeoJson file.
> In this GeoJson, features have an id, which is not a standard attribute ...
> for instance:
> {
> "type": "Feature",
> "id": "1",
> "geometry": {
> "type": "Point",
> "coordinates": [613100, 2003000]
> },
> "properties": {
> "post80": "true",
> "precise": "true"
> }
> }
> 
> As a result, OL features inherit this id as a "fid" property.
> 
> For some reason, I have to clone these features.
> I was surprised to see that "fid" property is not copied (it becomes "null"
> in the cloned feature).



> The reason lies around line 100 in Vector.js :
> * Method: clone
> * Create a clone of this vector feature. Does not set any non-standard
> properties.
> 
> I guess I have no other solution to move the id parameter inside the geojson
> "properties" object.

Well, no, that's not exactly true:

1. When you clone a feature, you have a reference to both features:

 var f = feat.clone();

You can then set the fid yourself:

  f.fid = feat.fid;

However, I don't consider the fid a 'non-standard property', which is
how OL treats the 'id' property. Since we kinda wrote the spec and the
reference implementations, calling 'id' non-standard is just silly: 'not
required' possibly, but not 'non standard': I'd have no problem with a
patch that added .fid cloning to Features.

Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list