Skip to content

Commit

Permalink
Code style/warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
simon04 committed Apr 7, 2013
1 parent 50caa6a commit 4e82ad1
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 39 deletions.
9 changes: 4 additions & 5 deletions aed.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,21 @@
iconUrl: 'https://upload.wikimedia.org/wikipedia/commons/thumb/b/bc/Automated_External_Defibrillator_%28symbol%29.svg/16px-Automated_External_Defibrillator_%28symbol%29.svg.png',
iconSize: new L.Point(16, 16),
iconAnchor: new L.Point(8, 8),
shadowSize: new L.Point(0, 0),
shadowSize: new L.Point(0, 0)
});

var aedUrl = 'http://overpass-api.de/api/interpreter?data=[out:json];node[emergency=aed];out;node[medical=aed];out;';
var aedInfo = function(tags) {
var r = $('<table>');
for (key in tags)
for (var key in tags)
r.append($('<tr>').append($('<th>').text(key)).append($('<td>').text(tags[key])));
return $('<div>').append(r).html();
}
};
$.getJSON(aedUrl, function(data) {
$.each(data.elements, function(ign, i) {
var pos = new L.LatLng(i.lat, i.lon);
var icon = aedIcon;
var popup = aedInfo(i.tags);
var marker = new L.Marker(pos, {icon: icon}).bindPopup(popup);
var marker = new L.Marker(pos, {icon: aedIcon}).bindPopup(popup);
map.addLayer(marker);
});
});
Expand Down
25 changes: 12 additions & 13 deletions map.ivb.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ IVB.displayExtension = function (layer) {
return function (w) {
L.geoJson({
type: 'Feature',
geometry: w.geometry,
geometry: w.geometry
}, {
style: function (e) {
return {
opacity: 1,
color: '#666',
//svg: {'stroke-dasharray': '6,8'},
weight: 3,
weight: 3
};
},
}
}).addTo(layer);
};
};
Expand All @@ -47,7 +47,7 @@ IVB.handleRelation = function (p) {
id: mem.obj.id,
tags: mem.obj.tags,
reltags: p.tags,
angle: stopAngles[mem.ref],
angle: stopAngles[mem.ref]
});
});
};
Expand All @@ -62,26 +62,26 @@ IVB.getStopAngles = function (relation) {
if (idx < 0) return;
// take two adjacent ways
// ignore projection and use lat/lon directly (shouldn't make a big difference as 2 nodes are rather close)
var lonlat1 = mem.obj.coordinates[idx == 0 ? 0 : idx - 1];
var lonlat2 = mem.obj.coordinates[idx == 0 ? 1 : idx];
var lonlat1 = mem.obj.coordinates[idx === 0 ? 0 : idx - 1];
var lonlat2 = mem.obj.coordinates[idx === 0 ? 1 : idx];
// determine in which order those two nodes are used
var polarity;
var idxWay = relation.members.filter(function (r) {
return r.obj.type == 'way' && r.role != 'platform';
}).indexOf(mem);
if (idxWay < 0) {
// ignore
} else if (idxWay == 0) {
} else if (idxWay === 0) {
// assumes ways in a block, i.e., w/o stops in between
// f first node linked to next way then -1 else +1
var nodes = relation.members[1].obj.nodes;
if (!nodes) return;
polarity = nodes.indexOf(mem.obj.nodes[0]) >= 0 ? 180 : 0;
} else {
// if first node linked to previous way then +1 else -1
var nodes = relation.members[idxWay - 1].obj.nodes;
if (!nodes) return;
polarity = nodes.indexOf(mem.obj.nodes[0]) >= 0 ? 0 : 180;
var relNodes = relation.members[idxWay - 1].obj.nodes;
if (!relNodes) return;
polarity = relNodes.indexOf(mem.obj.nodes[0]) >= 0 ? 0 : 180;
}
// compute direction, i.e., angle (with mathematical meaning: 0=horizontal, anti-clockwise)
var angle = polarity + Math.atan2(lonlat2[1] - lonlat1[1], lonlat2[0] - lonlat1[0]) * 180 / Math.PI;
Expand All @@ -107,7 +107,7 @@ IVB.addLine = function (lineref, geojson) {
return {opacity: 1, color: color.charAt(0) == '#' ? color : ('#' + color)};
},
pointToLayer: IVB.addStop,
onEachFeature: IVB.bindPopup,
onEachFeature: IVB.bindPopup
}).addTo(IVB.layers[lineref] || IVB.map);
if (!IVB.layers[lineref]) {
IVB.layers[lineref] = layer;
Expand All @@ -127,7 +127,7 @@ IVB.addStop = function (data, latlng) {
data.tags && data.tags.name ? data.tags.name.replace(/\/| /g, '-').replace(/\(|\)/g, '') : ''].join(' ');
// Add halt name as DivIcon
L.marker(latlng, {
icon: L.divIcon({className: className, html: data.tags.name || ''}),
icon: L.divIcon({className: className, html: data.tags.name || ''})
}).addTo(IVB.layers.stopLabels);
IVB.halts[id] = true;
}
Expand All @@ -145,4 +145,3 @@ IVB.bindPopup = function (p, l) {
+ (p.tags && p.tags.name ? '&nbsp;' + p.tags.name : '')
);
};

14 changes: 7 additions & 7 deletions map.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,35 @@ POImap.init = function () {
map = new L.Map('map', {
center: new L.LatLng(47.2632776, 11.4010086),
zoom: 13,
layers: osm,
layers: osm
});

map.getControl = function () {
var ctrl = new L.Control.Layers({
'OpenSteetMap': osm,
'OpenSteetMap (no labels)': osm_no,
'OpenSteetMap (black/white)': osm_bw,
'Transport Map': transport,
'Transport Map': transport
});
return function () {
return ctrl;
}
};
}();
map.addControl(map.getControl());

L.LatLngBounds.prototype.toOverpassBBoxString = function (){
var a = this._southWest,
b = this._northEast;
return [a.lat, a.lng, b.lat, b.lng].join(",");
}
};

var path_style = L.Path.prototype._updateStyle;
L.Path.prototype._updateStyle = function () {
path_style.apply(this);
for (k in this.options.svg) {
for (var k in this.options.svg) {
this._path.setAttribute(k, this.options.svg[k]);
}
}
};

if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
Expand All @@ -58,7 +58,7 @@ POImap.loadAndParseOverpassJSON = function (overpassQueryUrl, callbackNode, call
$.getJSON(url, function (json) {
POImap.parseOverpassJSON(json, callbackNode, callbackWay, callbackRelation);
});
}
};

POImap.parseOverpassJSON = function (overpassJSON, callbackNode, callbackWay, callbackRelation) {
var nodes = {}, ways = {};
Expand Down
8 changes: 4 additions & 4 deletions railway.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
onEachFeature: function (e, layer) {
if (e.properties && e.properties.name) layer.bindPopup(e.properties.name);
if (e.properties && e.properties.style) layer.setStyle(e.properties.style);
},
}
});
map.addLayer(layer);
map.zoomIn();
Expand All @@ -33,10 +33,10 @@
var r = $('<table>');
if (type && id)
r.append($('<tr>').append($('<th>').text('ID')).append($('<td>').text(id).append(' ').append($('<a>').attr({href: 'href="http://localhost:8111/load_object?objects='+type+id, target: '_blank'}).text('edit')).append(' ').append($('<a>').attr({href: 'http://www.openstreetmap.org/browse/'+{w:'way',n:'node',r:'relation'}[type]+'/'+id, target: '_blank'}).text('browse'))));
for (key in tags)
for (var key in tags)
r.append($('<tr>').append($('<th>').text(key)).append($('<td>').text(tags[key])));
return $('<div>').append(r).html();
}
};

var handleNode = function (n) {
if (!n.tags || !n.tags.railway) return;
Expand All @@ -51,7 +51,7 @@
iconUrl: icon.icon,
iconSize: new L.Point(icon.size, icon.size),
iconAnchor: new L.Point(icon.size/2, icon.size/2),
shadowSize: new L.Point(0, 0),
shadowSize: new L.Point(0, 0)
})
}).bindPopup(tagsTable(n.tags, 'n', n.id)));
};
Expand Down
6 changes: 3 additions & 3 deletions restaurant.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@
iconUrl: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAMAAABhEH5lAAAAXVBMVEUAAAD///+KU1P///////////////9xQED///9fMjJ1QkL///+jbm7///////////////////+XXFz///9pOjr///94RUVfMjL///////////9kNTWdYmL///9bLS2eoyA3AAAAHnRSTlMATKY/JkhAyBLwxUqIKhE9AkSZLtk0v/IFBkHmkTPuNN4DAAAAaElEQVR4Xp3INxbDIAAE0V2RlINz3Psf0zR6DwxuPMUUHz+ydI4W9+N23olqGvFmDk/mZF/SF70vGcW4nBIaOqkb3DWhaZTGiUpopcQ1I1AiKmT6gmYWhD/o0QcP+BC/Ny+mBVoTX+0DgJ0JB2LUDeEAAAAASUVORK5CYII=', //darkred
iconSize: new L.Point(18, 18),
iconAnchor: new L.Point(9, 9),
shadowSize: new L.Point(0, 0),
shadowSize: new L.Point(0, 0)
});

var poiUrl = 'http://overpass-api.de/api/interpreter?data=[out:json];node(BBOX)[amenity=restaurant];out;'.replace(/(BBOX)/g, map.getBounds().toOverpassBBoxString());

var poiInfo = function(tags) {
var r = $('<table>');
for (key in tags)
for (var key in tags)
r.append($('<tr>').append($('<th>').text(key)).append($('<td>').text(tags[key])));
return $('<div>').append(r).html();
}
};

$.getJSON(poiUrl, function(data) {
$.each(data.elements, function(ign, i) {
Expand Down
10 changes: 4 additions & 6 deletions semicircle.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,21 @@ L.Semicircle = L.Circle.extend({
if (this._checkIfEmpty()) {
return '';
} else if (L.Browser.svg) {
return "M" + p.x + "," + (p.y - r)
+ "A" + r + "," + r + ",0,1,1," + p.x + "," + (p.y + r);
return "M" + p.x + "," + (p.y - r) + "A" + r + "," + r + ",0,1,1," + p.x + "," + (p.y + r);
} else {
//TODO: adapt
p._round();
r = Math.round(r);
return "AL " + p.x + "," + p.y + " " + r + "," + r + " 0," + (65535 * 360);
}
},
}
});

L.SemicircleMarker = L.Semicircle.extend({
options: {
radius: 10,
weight: 2,
angle: 0,
angle: 0
},
initialize: function (latlng, options) {
L.Semicircle.prototype.initialize.call(this, latlng, null, options);
Expand All @@ -47,6 +46,5 @@ L.SemicircleMarker = L.Semicircle.extend({
setAngle: function (angle) {
this._angle = angle;
return this.redraw();
},
}
});

2 changes: 1 addition & 1 deletion wiwosm.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
},
onEachFeature: function (feature, layer) {
layer.bindPopup('<a href="http://de.wikipedia.org/wiki/' + article.replace(/ /g, '_') + '" target="_blank">' + article + '</a>');
},
}
}).addTo(map);
map.getControl().addOverlay(layer, article);
});
Expand Down

0 comments on commit 4e82ad1

Please sign in to comment.