[OpenLayers-Users] Setting attributes of a Feature.Vector

Andy Dale andy.dale at gmail.com
Thu Oct 11 08:41:05 EDT 2007


Hi,

Doing it the way you said (directly underneath the feature creation) does
work, but i want to move the feature attributes extraction to a separate
function like so:

function extractDetails() {
            var feats = polygonLayer.features; // This is the Layer.Vector
            for(item in feats) {
                atts = item.attributes;

                // do stuff depending on attributes
            }
}

the problem is that atts never has any properties (you can never call
atts.<anything>), is the above approach completely wrong ??

Thanks,

Andy

On 11/10/2007, Christopher Schmidt <crschmidt at metacarta.com> wrote:
>
> On Thu, Oct 11, 2007 at 09:17:06AM +0200, Andy Dale wrote:
> > "An optional object that will be mapped to the
> > attributes<
> http://dev.openlayers.org/docs/files/OpenLayers/Feature/Vector-js.html#OpenLayers.Feature.Vector.attributes
> >property."
> >
> > So I attempted to set the second parameter in a varity of ways such as:
> >
> > 3) {first: "test", second: 21};
>
> This is the right one.
>
> >
> > I attempt to access the attributes as follows:
> >
> > 1) Call Layer.Vector.features
> > 2) Iterate over the returned features
> > 3) On each feature call Feature.attributes
> > 4) Try and access the attributes
>
> This should work.
>
> f = new OpenLayers.Feature.Vector(geometry, {'a':'b'});
> alert(f.attributes.a);
>
> Should do the trick. Is it not working for you?
>
> Regards,
> --
> Christopher Schmidt
> MetaCarta
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20071011/dc28c2b8/attachment.html


More information about the Users mailing list