From b09b0a7b374c1d60e5f3d041bb45b15bccaca5b3 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(-) (limited to 'resources') diff --git a/resources/map.js b/resources/map.js index b9edc79..86b6ea6 100644 --- a/resources/map.js +++ b/resources/map.js @@ -53,10 +53,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); @@ -74,9 +75,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); @@ -124,9 +125,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 From ead7cc174cc6c3f9fd9c72a484e3fa0d48a89e34 Mon Sep 17 00:00:00 2001 From: Harry Cutts Date: Sun, 2 Dec 2012 13:54:35 +0000 Subject: Correct the node filter Previously, nodes that belonged to hospital polygons were displayed as health facilities if they had any tags at all (e.g. odbl=clean). They are now only displayed if they contain the amenity tag. --- resources/op2geojson.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'resources') diff --git a/resources/op2geojson.js b/resources/op2geojson.js index 0fa2967..c453df7 100644 --- a/resources/op2geojson.js +++ b/resources/op2geojson.js @@ -19,7 +19,8 @@ op2geojson = function() { // Add nodes and ways to the layer var features = []; $.each(data.elements, function(i, item) { - if( item.type === 'node' && item.tags != null ) { + if( item.type === 'node' && item.tags != undefined + && item.tags['amenity'] != undefined) { features.push( instance.point(item) ); } else if (item.type === 'way') { features.push( instance.lineString(item, nodes) ); -- cgit v1.2.3 From 0270111b931f88a56e099bbc0b18a232cedc0579 Mon Sep 17 00:00:00 2001 From: Harry Cutts Date: Sun, 2 Dec 2012 14:06:25 +0000 Subject: Add doctors and dentists to the query --- resources/map.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'resources') diff --git a/resources/map.js b/resources/map.js index 86b6ea6..484363b 100644 --- a/resources/map.js +++ b/resources/map.js @@ -56,8 +56,10 @@ $(document).ready(function() { 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;"; + "(node[amenity=hospital]("+ bbox +");way[amenity=hospital]("+ bbox +");node(w););" + + "(node[amenity=doctors]("+ bbox +");way[amenity=doctors]("+ bbox +");node(w););" + + "(node[amenity=dentist]("+ bbox +");way[amenity=dentist]("+ bbox +");node(w););" + + "out;"; } map.on('hospitalsfetched', addHospitalLayer); -- cgit v1.2.3 From e010ed88f47e5e1629aaa494ccb8c173299842b0 Mon Sep 17 00:00:00 2001 From: Harry Cutts Date: Sun, 2 Dec 2012 14:21:49 +0000 Subject: Fix a query problem that was only showing dentists --- resources/map.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'resources') diff --git a/resources/map.js b/resources/map.js index 484363b..c078368 100644 --- a/resources/map.js +++ b/resources/map.js @@ -55,11 +55,11 @@ $(document).ready(function() { function createQueryData(bbox) { // TODO: Use POST instead of GET, for neatness - return "data=[out:json];" + + return "data=[out:json];(" + "(node[amenity=hospital]("+ bbox +");way[amenity=hospital]("+ bbox +");node(w););" + "(node[amenity=doctors]("+ bbox +");way[amenity=doctors]("+ bbox +");node(w););" + "(node[amenity=dentist]("+ bbox +");way[amenity=dentist]("+ bbox +");node(w););" + - "out;"; + ");out;"; } map.on('hospitalsfetched', addHospitalLayer); -- cgit v1.2.3 From 341797bc84fc0672e4eda0e79de815e7c2b123c8 Mon Sep 17 00:00:00 2001 From: Willi Date: Sun, 2 Dec 2012 15:48:37 +0100 Subject: removed obsolete line --- resources/map.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'resources') diff --git a/resources/map.js b/resources/map.js index b9edc79..6c7fbdf 100644 --- a/resources/map.js +++ b/resources/map.js @@ -44,7 +44,6 @@ $(document).ready(function() { self.layers = L.control.layers(null, { "Hospitals" : self.hospitalLayer }).addTo(map); - _.each(filteredLayers, function(layer, i) { self.layers.addOverlay(layer, self.hospitalAttributes[i]); }); @@ -116,11 +115,10 @@ $(document).ready(function() { if (isHierarchical.exec(key)) { key = key.split(':')[1]; } - if (!_.contains(self.hospitalAttributes, key) && isBoolean(val)) { + if ((!_.contains(self.hospitalAttributes, key)) && isBoolean(val)) { self.hospitalAttributes.push(key); } }); - self.hospitalAttributes; } function geojsonLayer() { -- cgit v1.2.3 From 19eaafbb9ff1996266ab617125bb02f47bd2c20e Mon Sep 17 00:00:00 2001 From: Willi Date: Sun, 2 Dec 2012 23:33:47 +0100 Subject: added locate me from @domoritz --- resources/libs/locate/L.Control.Locate.css | 36 ++++++ resources/libs/locate/L.Control.Locate.ie.css | 10 ++ resources/libs/locate/L.Control.Locate.js | 171 +++++++++++++++++++++++++ resources/libs/locate/LICENSE | 9 ++ resources/libs/locate/images/locate.png | Bin 0 -> 274 bytes resources/libs/locate/images/locate.svg | 137 ++++++++++++++++++++ resources/libs/locate/images/locate_active.png | Bin 0 -> 610 bytes resources/map.js | 2 + 8 files changed, 365 insertions(+) create mode 100755 resources/libs/locate/L.Control.Locate.css create mode 100755 resources/libs/locate/L.Control.Locate.ie.css create mode 100755 resources/libs/locate/L.Control.Locate.js create mode 100755 resources/libs/locate/LICENSE create mode 100755 resources/libs/locate/images/locate.png create mode 100755 resources/libs/locate/images/locate.svg create mode 100755 resources/libs/locate/images/locate_active.png (limited to 'resources') diff --git a/resources/libs/locate/L.Control.Locate.css b/resources/libs/locate/L.Control.Locate.css new file mode 100755 index 0000000..945732a --- /dev/null +++ b/resources/libs/locate/L.Control.Locate.css @@ -0,0 +1,36 @@ +.leaflet-control-locate { + height: 30px; +} + +.leaflet-control-locate > div { + -moz-border-radius: 7px; + -webkit-border-radius: 7px; + border-radius: 7px; +} +.leaflet-control-locate > div { + padding: 5px; + background: rgba(0, 0, 0, 0.25); +} +.leaflet-control-locate a { + background-color: rgba(255, 255, 255, 0.75); +} +.leaflet-control-locate a{ + background-image: url(images/locate.png); + background-position: 50% 50%; + background-repeat: no-repeat; + display: block; +} +.leaflet-control-locate a { + -moz-border-radius: 4px; + -webkit-border-radius: 4px; + border-radius: 4px; + width: 19px; + height: 19px; +} +.leaflet-control-locate a:hover { + background-color: #fff; +} + +.leaflet-control-locate.active a { + background-image: url(images/locate_active.png); +} \ No newline at end of file diff --git a/resources/libs/locate/L.Control.Locate.ie.css b/resources/libs/locate/L.Control.Locate.ie.css new file mode 100755 index 0000000..fdbe9d0 --- /dev/null +++ b/resources/libs/locate/L.Control.Locate.ie.css @@ -0,0 +1,10 @@ + +.leaflet-control-locate > div { + filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#3F000000',EndColorStr='#3F000000'); +} +.leaflet-control-locate a { + background-color: #eee; +} +.leaflet-control-locate a:hover { + background-color: #fff; +} diff --git a/resources/libs/locate/L.Control.Locate.js b/resources/libs/locate/L.Control.Locate.js new file mode 100755 index 0000000..b2ed522 --- /dev/null +++ b/resources/libs/locate/L.Control.Locate.js @@ -0,0 +1,171 @@ +L.Control.Locate = L.Control.extend({ + options: { + position: 'topleft', + drawCircle: true, + follow: false, // follow with zoom and pan the user's location + // range circle + circleStyle: { + color: '#136AEC', + fillColor: '#136AEC', + fillOpacity: 0.15, + weight: 2, + opacity: 0.5 + }, + // inner marker + markerStyle: { + color: '#136AEC', + fillColor: '#2A93EE', + fillOpacity: 0.7, + weight: 2, + opacity: 0.9, + radius: 4 + }, + debug: false + }, + + onAdd: function (map) { + var className = 'leaflet-control-locate', + classNames = className + " leaflet-control", + container = L.DomUtil.create('div', className); + + var self = this; + var _map = map; + this._layer = new L.LayerGroup(); + this._layer.addTo(_map); + this._event = undefined; + this._locateOptions = { + 'setView': false, + 'watch': true + }; + this._locateOnNextLocationFound = true; + this._atLocation = false; + this._active = false; + + var wrapper = L.DomUtil.create('div', className + "-wrap", container); + var link = L.DomUtil.create('a', className, wrapper); + link.href = '#'; + link.title = 'Show me where I am'; + + var _log = function(data) { + if (self.options.debug) { + console.log(data); + } + }; + + L.DomEvent + .on(link, 'click', L.DomEvent.stopPropagation) + .on(link, 'click', L.DomEvent.preventDefault) + .on(link, 'click', function() { + _log('at location: ' + self._atLocation); + if (self._atLocation && self._active) { + removeVisualization(); + } else { + self._active = true; + self._locateOnNextLocationFound = true; + if (!self._event) { + map.locate(self._locateOptions); + } else { + visualizeLocation(); + } + } + }) + .on(link, 'dblclick', L.DomEvent.stopPropagation); + + var onLocationFound = function (e) { + _log('onLocationFound'); + + if (self._event && + (self._event.latlng.lat != e.latlng.lat || + self._event.latlng.lon != e.latlng.lon)) { + _log('location has changed'); + self._atLocation = false; + } + + self._event = e; + + if (!self._active) { + return; + } + + if (self.options.follow) { + self._locateOnNextLocationFound = true; + } + + visualizeLocation(); + }; + + var visualizeLocation = function() { + _log('visualizeLocation,' + 'setView:' + self._locateOnNextLocationFound); + + var radius = self._event.accuracy / 2; + + if (self._locateOnNextLocationFound) { + self._map.fitBounds(self._event.bounds); + self._atLocation = true; + self._locateOnNextLocationFound = false; + } + + self._layer.clearLayers(); + + // curcle with the radius of the location's accuracy + if (self.options.drawCircle) { + L.circle(self._event.latlng, radius, self.options.circleStyle) + .addTo(self._layer); + } + + // small inner marker + L.circleMarker(self._event.latlng, self.options.markerStyle) + .bindPopup("You are within " + radius.toFixed(0) + " meters from this point") + .addTo(self._layer); + + if (!self._container) + return; + self._container.className = classNames + " active"; + }; + + var removeVisualization = function() { + self._container.className = classNames; + self._active = false; + + self._layer.clearLayers(); + }; + + var onLocationError = function (err) { + _log('onLocationError'); + + // ignore timeout error if the location is watched + if (err.code==3 && this.options.locateOptions.watch) { + return; + } + + map.stopLocate(); + removeVisualization(); + alert(err.message); + }; + + map.on('movestart', function() { + self._atLocation = false; + }); + + // event hooks + map.on('locationfound', onLocationFound, self); + map.on('locationerror', onLocationError, self); + + if (this.options.autoLocate) { + map.locate(self._locateOptions); + } + + return container; + } +}); + +L.Map.addInitHook(function () { + if (this.options.locateControl) { + this.locateControl = L.control.locate(); + this.addControl(this.locateControl); + } +}); + +L.control.locate = function (options) { + return new L.Control.Locate(options); +}; diff --git a/resources/libs/locate/LICENSE b/resources/libs/locate/LICENSE new file mode 100755 index 0000000..e0d82f6 --- /dev/null +++ b/resources/libs/locate/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2012 Dominik Moritz + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/resources/libs/locate/images/locate.png b/resources/libs/locate/images/locate.png new file mode 100755 index 0000000..9505daa Binary files /dev/null and b/resources/libs/locate/images/locate.png differ diff --git a/resources/libs/locate/images/locate.svg b/resources/libs/locate/images/locate.svg new file mode 100755 index 0000000..40ad2be --- /dev/null +++ b/resources/libs/locate/images/locate.svg @@ -0,0 +1,137 @@ + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + diff --git a/resources/libs/locate/images/locate_active.png b/resources/libs/locate/images/locate_active.png new file mode 100755 index 0000000..f1a239f Binary files /dev/null and b/resources/libs/locate/images/locate_active.png differ diff --git a/resources/map.js b/resources/map.js index 482a5f7..44fe54c 100644 --- a/resources/map.js +++ b/resources/map.js @@ -28,6 +28,8 @@ $(document).ready(function() { layers: [self.tileLayer], }); GlobalMap = map; + + L.control.locate().addTo(map); function addHospitalLayer(){ var filteredLayers = _.map(self.hospitalAttributes, function (attr) { -- cgit v1.2.3