From ee738141231340095b9cccaec53c2192d690384b Mon Sep 17 00:00:00 2001 From: Willi Date: Sun, 2 Dec 2012 11:19:35 +0100 Subject: removed duplicate checkboxes --- resources/map.js | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/resources/map.js b/resources/map.js index 938e08a..50fdd87 100644 --- a/resources/map.js +++ b/resources/map.js @@ -24,6 +24,7 @@ $(document).ready(function() { zoom: 12, layers: [self.tileLayer], }); + GlobalMap = map; function addHospitalLayer(){ L.control.layers(null, { @@ -52,6 +53,7 @@ $(document).ready(function() { var url = "http://overpass-api.de/api/interpreter?data=[out:json];node[amenity=hospital](" + bbox + ");out;"; converter = new op2geojson(); converter.fetch(url, function(data) { + self.hospitals = data; layer = buildLayer(data) self.hospitalLayer.addData(data); }); @@ -62,24 +64,31 @@ $(document).ready(function() { function buildLayer(data) { return L.geoJson(data, { onEachFeature: function(feature, layer) { - var isHierarchical = new RegExp('\:'); - _.each(feature.properties, function(val, key) { - if (isHierarchical.exec(isHierarchical)) { - key = key.split(':')[1]; - if (_.contains(self.hospitalAttributes), key) { - self.hospitalAttributes.push(key); - } - } - }); + storeAllAttributeKeys(feature); layer.bindPopup(self.popupTemplate({ properties: feature.properties })); } }); } + function storeAllAttributeKeys(feature) { + var isHierarchical = new RegExp('\:'); + var keys = _.keys(feature.properties); + _.each(feature.properties, function(val, key) { + if (isHierarchical.exec(key)) { + key = key.split(':')[1]; + } + if (!_.contains(self.hospitalAttributes, key)) { + self.hospitalAttributes.push(key); + } + }); + self.hospitalAttributes; + } + function geojsonLayer() { url = "http://overpass-api.de/api/interpreter?data=[out:json];node[amenity=hospital](52.34,13.3,52.52,13.6);out;"; converter = new op2geojson(); converter.fetch(url, function(data) { + self.hospitals = data; layer = buildLayer(data); self.hospitalLayer = layer; map.fireEvent('hospitalsfetched'); @@ -98,7 +107,7 @@ $(document).ready(function() { } }); var template = _.template('
<% _.each(attributes, function (attr) { %> \ - value=<%= attr %>> <%= attr %> \ + \ <% }); %> \
'); var t = template({ attributes: self.hospitalAttributes }); @@ -108,7 +117,9 @@ $(document).ready(function() { _.each($('.filter-box input'), function(el) { //first check them all el.click(); + // attach click handler $(el).click(checkedFilterBox); + $(el).dblclick(dontZoom); }); } -- cgit v1.2.3