Hello, thanks Darrell and Eric for the answers. I got it working as Eric suggested.
Christian Am 06.10.2009 um 21:50 schrieb Eric Lemoine: > On Fri, Oct 2, 2009 at 11:00 PM, Christian Schanz > <christian.sch...@gmail.com> wrote: >> Hello, >> >> I need a function that returns a featurecollection which is created >> from a GeoJSON. >> So I think that I need to do something like the following: >> >> function getGeoJSON() { >> var featurecollection; >> function handler(request) { >> //TODO: What to do here? >> } >> var request = OpenLayers.Request.GET( { >> url: "http://path/to/my/GeoJSON", >> callback: handler >> }); >> return featurecollection; >> } >> >> But how exactly should the handler look like? >> I have tried to add something like >> featurecollection = request.responseText; >> to the handler but then I get no features returned at all. >> >> And as a second question: Should my GeoJSON generating server >> insert a >> mime-type at the beginning of the >> response or is this not needed? > > I'd recommend using a protocol. Something like this: > > var protocol = new OpenLayers.Protocol.HTTP({ > url: "url-to-geojson", > format: new OpenLayers.Format.GeoJSON() > }); > > protocol.read({ > callback: function(response) { > if(response.success()) { > var features = response.features; > console.log(features); > } else { > console.log("failure"); > } > } > }); > > > Hope this helps, > > -- > Eric Lemoine > > Camptocamp France SAS > Savoie Technolac, BP 352 > 73377 Le Bourget du Lac, Cedex > > Tel : 00 33 4 79 44 44 96 > Mail : eric.lemo...@camptocamp.com > http://www.camptocamp.com _______________________________________________ Users mailing list Users@openlayers.org http://openlayers.org/mailman/listinfo/users