[OpenLayers-Users] http protocol problem

Didrik Pinte lists at dipole-consulting.com
Fri Nov 7 05:05:51 EST 2008


On Thu, 2008-11-06 at 10:40 -0700, Tim Schaub wrote:
> 
> Yeah, the Fixed strategy sets the callback for protocol.read in this 
> case (when you are using the Fixed strategy).
> 
> When you use the Fixed strategy, it means you want features requested 
> once and immediately added to your layer.  So, if you register a 
> listener for "featuresadded", you'll know when the read/parse/add 
> sequence is done.
> 
> If you want to intervene (e.g. do something with the features before 
> they are added to the layer), you can register for 
> "beforefeaturesadded".  In this case, your listener will get an event 
> with a reference to the features bound for the layer.  If you modify 
> those features, they will be modified before they get added to the 
> layer.  If you want to remove features from that array, splice it.  If 
> you want to create your own array of features, just set event.features 
> again before your function returns.
> 
> If you want to mess with the response before it is parsed, I'd like to 
> hear the reason.  There are good reasons, I'm just curious.  This is a 
> job for a callback from the filter (unless we want to start adding 
> events to our formats).  In either case, it will take work - but I think 
> it would make a good change.
> 
> Tim

Hi Tim,

Thanks for the clear suggestions. Here is the explanation of what i'm
doing.
The callback I registered simply sets the extent of the map to the
extent of the data loaded in the layer. It was as simple as 

    function jsonreturn(response) {     

vector_layer.addFeatures(protocol.parseFeatures(response.priv));      
       map.setCenter(vector_layer.getDataExtent().getCenterLonLat(),

map.getZoomForExtent(vector_layer.getDataExtent(),false)-1, false,
false);
        map.setCenter(vector_layer.getDataExtent().getCenterLonLat());
    }

So without the Fixed strategy, it loads the data from the json stream
and then recenters the map [1]. With the Fixed strategy, I would just
recenter the map.

It could be possible to register a callback on "beforefeaturesadded" but
then features has to parsed to compute the bounding box ... that's not
really elegant.

Do you see a better solution ? 

Didrik

[1] By the way, you see that there is two calls to map.setCenter. I
don't know why but the first call adjust only the zoom level but do not
recenter. Calling setCenter a second time just works ... 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
Url : http://lists.osgeo.org/pipermail/openlayers-users/attachments/20081107/f03fec0a/attachment.bin


More information about the Users mailing list