[OpenLayers-Users] howto manage empty geojson streams

Eric Lemoine eric.c2c at gmail.com
Mon Mar 16 08:55:50 EDT 2009


2009/3/16 Didrik Pinte <lists at dipole-consulting.com>:
> Hi list,

Hi


> We have an application that is linked to a servlet that generates a
> GeoJSON stream. In some situations, the stream is empty.
>
> Looking a Format/GeoJSON.js, I cannot find the correct way to provide a
> valid GeoJSON stream that containts no features. A FeatureCollection
> with no feature raise an error, an empty string raises an error too.
>
> What is the best practice for that kind of situation ?

Consider using OpenLayers.Protocol.HTTP.

var protocol = new OpenLayers.Protocol.HTTP({
    url: "url-to-your-service",
    format: new OpenLayers.Format.GeoJSON()
});
protocol.read({
    callback: function(response) {
        var features = response.features;
        // features will be null if the GeoJSON stream is empty
    }
});

Hope that helps,

--
Eric



More information about the Users mailing list