2

I am using OpenLayers and Overpass QL with GET method to retrieve data from the Overpass server. Some URLs tend to be very long and hence get rejected by the Overpass server. To get around this, I am thinking of using POST method to query the Overpass server using OpenLayers. Is there a way to use POST method with Overpass QL (not XML) in OpenLayers? And if yes, what (syntax) goes into the url property of OpenLayers.Layer.Vector?

1

The following solution works. Essentially, we take the parameters part of a normal GET request and put them as key value pairs inside params option and set readWithPOST property of protocol to true.

new OpenLayers.Layer.Vector("hospital", {  
     strategies: [new OpenLayers.Strategy.BBOX({ratio:1.0}),new OpenLayers.Strategy.Refresh()],
     protocol: new OpenLayers.Protocol.HTTP({
         url: "http://overpass-api.de/api/interpreter";  
         params: {
              "data":"way['amenity'~'hospital|clinic|nursing_home|dentist|health$|health_post'](poly: '" +polyCoords+"');node(w);node['amenity'~'hospital|clinic|nursing_home|dentist|health_post'](poly: '" +polyCoords+ "'););out meta qt;"
         },
         format: new OpenLayers.Format.OSMMeta(),
         readWithPOST: true
     }),
     projection: new OpenLayers.Projection("EPSG:4326")
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.