[OpenLayers-Users] http protocol problem

Tim Schaub tschaub at opengeo.org
Thu Nov 6 12:40:48 EST 2008


Hey-

Didrik Pinte wrote:
> On Wed, 2008-11-05 at 23:23 +0100, Eric Lemoine wrote:
>> Hi. How do you register your callback? Sorry i don't see what you're
>> talking about. Eric
> 
> Hi Eric,
> 
> I register the callback like this :
> --------------------------------------------------------------------
>     var protocol, vector_layer;
>     protocol = new OpenLayers.Protocol.HTTP( {
>                 url : 'stream.json',
>                 format: new OpenLayers.Format.GeoJSON(),
>                 callback : jsonreturn,
>                 params : {
>                     id: 1
>                 }
>         });
> 
>       vector_layer = new OpenLayers.Layer.Vector('Points', {
>             styleMap    : styleMap,            
>             strategies  : [
>                 //new OpenLayers.Strategy.Fixed(),
>                 new OpenLayers.Strategy.Cluster()
>             ],
>             protocol: protocol
>        }); 
>       protocol.read();
> --------------------------------------------------------------------
> 
> So, with the previous code, if I uncomment the Fixed strategy (and
> comment the protocol.read() line), the "jsonreturn" callback function is
> never called. When the fixed strategy is commented, everything runs
> fine.

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

> 
> Didrik
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users


-- 
Tim Schaub
OpenGeo - http://opengeo.org
Expert service straight from the developers.



More information about the Users mailing list