[OpenLayers-Dev] Metadata inside a JSON
Matt Priour
mpriour at kestrelcomputer.com
Wed Jul 21 09:43:44 EDT 2010
The comment about it not being a good place to change properties was at the individual feature adding part of the cycle.
Changing properties before features are added is perfectly fine, however, you are right that it would be even better to make the layers from the metadata and then add features.
Just use an OpenLayers.Request and process the response in the callback function.
Matt Priour
Kestrel Computer Consulting
From: toni hernández
Sent: Wednesday, July 21, 2010 1:38 AM
To: Matt Priour
Cc: dev at openlayers.org
Subject: Re: [OpenLayers-Dev] Metadata inside a JSON
Thanks Matt,
I have been thinking about your solution. I could work but as you said "is not a good place/time to be changing layer properties". So I kept on thinking... and now I am wondering.
Wouldn't it be better to do an ajax call to web-service, then eval the ajax response with all the information about style, about features and everything and then create each layer with the proper style, features and everything?.
What do you think?
2010/7/20 Matt Priour <mpriour at kestrelcomputer.com>
Toni,
I am assuming you are using an OpenLayers.Layer.Vector layer with an HTTP protocol.
You need to add a listener for 'beforefeaturesadded' event on the layer.
The original JSON should be cached in the event object as well as the parsed features.
You want to apply the layer configuration metadata properities to the layer in the 'beforefeaturesadded' event handler.
be sure to use 'beforefeaturesadded' with the plural featureS rather than the 'beforefeatureadded' event with the singular feature
The plural features event runs once before any features are added from each response, while the singular feature runs before each individual feature is added and the original JSON response will NOT be available. Also that is not a good place/time to be changing layer properties anyway.
Matt Priour
Kestrel Computer Consulting
IN REPLY TO:
------------------------------------------------------------------------------------
Date: Tue, 20 Jul 2010 17:31:14 +0200
From: toni hern?ndez <tonidelacalle at gmail.com>
Subject: [OpenLayers-Dev] Metadata inside a JSON
hi all,
I have a map with lots of layers. Each layer has its own style. The map
application gets each layer from a web-service that some else has developed
and can not be modified (I guess).
I thouht I could put any kind of data in a json file, so I tried this:
{
"type": "FeatureCollection",
"name": "Mapa de la Internacionalitat",
"minScale":"whatever",
"maxScale":"whatever",
//and then features and its properties?
"features": [
...
]
}
Now I have realized that atributes "name", "minScale" and "maxScale" are not
available from the layer object. I can only get the features properties.
Is it possible to read first the data of the layer, then create the layer
and finally add the features?
How could / should I do that?
Thanks in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-dev/attachments/20100721/9eaf3875/attachment.html
More information about the Dev
mailing list