[OpenLayers-Users] Problem with Protocol HTTP and vector layer

Eric Lemoine eric.c2c at gmail.com
Tue Oct 21 11:14:03 EDT 2008


On Tue, Oct 21, 2008 at 1:41 PM, Jérome Freyre <jerome.freyre at hispeed.ch> wrote:

> [...]
>
> Based on the example
> (http://openlayers.org/dev/examples/protocol-gears.html), I create a method
> called sync :
>
> function sync() {
> 	resp = view.protocol.read();
> 	if (!resp.success()) {
> 		alert("reading failed");
> 	        return;
> 	}
>
> 	view.destroyFeatures();
>
> 	if (!resp.features || resp.features.length <= 0) {
> 		alert("No features to read");
> 	        return;
> 	}
> 	view.addFeatures(resp.features);
> 	alert("features successfully read");
> }
>
> view.protocol.read() is correctly working (I saw the call to getGeoJSON in
> firebug) and my getGeoJSON.php return the correct GeoJSON. But my function
> always do the alert on the "reading failed" and I don't understand why!?

Because, as opposed to Protocol.Gears, Protocol.HTTP is asynchronous.
You need to pass a callback to read() and read the response from
there:

protocol.read({
    callback: function(resp) {
        if (!resp.success()) {
            alter("failure");
        }
    }
});

--
Eric


More information about the Users mailing list