From a1fce06c1857c99d8a421f513180d299617edacb Mon Sep 17 00:00:00 2001 From: Harry Cutts Date: Sun, 2 Dec 2012 13:50:10 +0000 Subject: Change from using GET to POST, for neatness --- resources/map.js | 17 +++++++++-------- resources/op2geojson.js | 6 +++--- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/resources/map.js b/resources/map.js index 6d00c2e..077e370 100644 --- a/resources/map.js +++ b/resources/map.js @@ -56,10 +56,11 @@ $(document).ready(function() { $('.leaflet-control-layers-selector').first().trigger('click') } - function createQueryURL(bbox) { - return "http://overpass-api.de/api/interpreter?" + - "data=[out:json];(node[amenity=hospital](" + bbox + - ");way[amenity=hospital]("+ bbox +");node(w););out;"; + function createQueryData(bbox) { + // TODO: Use POST instead of GET, for neatness + return "data=[out:json];" + + "(node[amenity=hospital]("+ bbox + +");way[amenity=hospital]("+ bbox +");node(w););out;"; } map.on('hospitalsfetched', addHospitalLayer); @@ -77,9 +78,9 @@ $(document).ready(function() { var sw = bounds.getSouthWest(); var ne = bounds.getNorthEast(); bbox = [sw.lat, sw.lng, ne.lat, ne.lng].join(','); - var url = createQueryURL(bbox); + var data = createQueryData(bbox); converter = new op2geojson(); - converter.fetch(url, function(data) { + converter.fetch("http://overpass-api.de/api/interpreter", data, function(data) { self.hospitals = data; layer = buildLayer(data) self.hospitalLayer.addData(data); @@ -127,9 +128,9 @@ $(document).ready(function() { } function geojsonLayer() { - url = createQueryURL(52.34,13.3,52.52,13.6); + data = createQueryData([52.34,13.3,52.52,13.6]); converter = new op2geojson(); - converter.fetch(url, function(data) { + converter.fetch("http://overpass-api.de/api/interpreter", data, function(data) { self.hospitals = data; layer = buildLayer(data); self.hospitalLayer = layer; diff --git a/resources/op2geojson.js b/resources/op2geojson.js index 55be9e3..0fa2967 100644 --- a/resources/op2geojson.js +++ b/resources/op2geojson.js @@ -5,8 +5,8 @@ op2geojson = function() { var instance = {}, geojson; - instance.fetch = function(url, callback) { - $.getJSON(url, { format: "json" }, + instance.fetch = function(url, data, callback) { + $.post(url, data, function(data) { // List all of the returned nodes var nodes = []; @@ -28,7 +28,7 @@ op2geojson = function() { geojson = instance.featureCollection(features); callback(geojson); } - ); + , "json");; }; instance.point = function(node) { -- cgit v1.2.3