[OpenLayers-Dev] [OpenLayers-Trac] [OpenLayers] #1324: OpenLayers.Feature.Vector.clone() must clone the fid property.

Eric Lemoine eric.c2c at gmail.com
Tue Feb 12 00:44:25 EST 2008


On Feb 12, 2008 3:52 AM, Christopher Schmidt <crschmidt at metacarta.com> wrote:
> On Tue, Feb 12, 2008 at 09:54:28AM +1100, Roald de Wit wrote:
> > Hi,
> >
> > On Mon, 2008-02-11 at 09:17 -0500, Christopher Schmidt wrote:
> > > On Thu, Feb 07, 2008 at 03:18:55PM -0000, OpenLayers wrote:
> > > > #1324: OpenLayers.Feature.Vector.clone() must clone the fid property.
> > >
> > > Anyone have thoughts on this? I'm not sure if we should be cloning this,
> > > since it feels to me like a clone is a different object, and fids should
> > > be unique...
> >
> > If the requirement is that an object must always have a unique fid, then
> > not cloning the fid is also insufficient.
> >
> > You'd have to create a new unique fid. The simplest way would be copying
> > the original fid and adding a random number, like:
> >
> > newObject.fid = oldObject.fid + "_" + Math.round(Math.random() * 1000));
>
> Actually, There's an OpenLayers.Util.createUniqID(), which is
> guartenteed to be unique. (I might have spelled it wrong.) IT uses a
> monotonically increasing value.
>
> That's not really here nor there though. Your point is correct: if a
> *unique* FID is required, then it should be set to something uniquely
> generated (presumably at the application level). However, what I
> actually meant was "a unique or null FID": 'null' usually means 'use the
> remote server to populate one for me', instead of using the value as a
> FID. This is the behavior I think makes the most sense: for most
> applications, when you clone a feature, you want to keep a null FID
> until you serialize and post to a server, and *then* do the logic to
> create one and assign it on the client.
>
> With that in mind, i think not cloning the FID is a good idea.

Yeah, I actually agree with you that we shouldn't clone the fid. It
should be up to the application code to set it, either at the client
slide or at the server side as you explained it above.

Thanks,
--
Eric



More information about the Dev mailing list