diff options
-rw-r--r-- | public/css/sublab-2013041401.css | 15 | ||||
-rw-r--r-- | scripts/osmux.py | 166 | ||||
-rw-r--r-- | template/pages/mate/content.html | 186 | ||||
-rw-r--r-- | template/pages/mate/desc_de | 1 | ||||
-rw-r--r-- | template/pages/mate/desc_en | 1 | ||||
-rw-r--r-- | template/pages/mate/keywords | 1 | ||||
-rw-r--r-- | template/template/template.html | 2 |
7 files changed, 1 insertions, 371 deletions
diff --git a/public/css/sublab-2013041401.css b/public/css/sublab-2013041401.css index e63f5c2..72413e6 100644 --- a/public/css/sublab-2013041401.css +++ b/public/css/sublab-2013041401.css @@ -312,21 +312,6 @@ span.box { padding: 2px; } -.olFramedCloudPopupContent h2 { - color: #000000; - font-size: 14px; - } - -.olFramedCloudPopupContent p { - color: #000000; - font-size: 12px; - } - -.olFramedCloudPopupContent a { - color: #3333FF; - font-size: 14px; - } - #mapdiv img { border: 0px; } diff --git a/scripts/osmux.py b/scripts/osmux.py deleted file mode 100644 index f0cdf48..0000000 --- a/scripts/osmux.py +++ /dev/null @@ -1,166 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -''' - -OSMux - A query multiplexer for the Overpass OpenStreetMap-API - -Version 2011-10-22 - -(c) 2011 - Conrad Hoffmann <ch@bitfehler.net> - -This software is public domain and comes without warranty of any kind. - -This script splits queries for large areas into several smaller bounding boxes, sends them to them -to the server and merges the results into a single file (the result for the original query). - -Additionally, ways are returned as nodes, so they can be displayed in map overlays. Actually, for -a matching way the script returns the first node of the way - but with all the tags that were -originally attached to the way. - -Basic usage instructions available via the --help switch. - -See http://code.bitfehler.net/osmux for more details. - -''' - -from os import close -from os import remove -from sys import stderr -from time import sleep -from tempfile import mkstemp -from argparse import ArgumentParser -from urllib.request import urlretrieve -import xml.etree.ElementTree as etree - -QUERY_TEMPLATE = 'http://www.overpass-api.de/api/xapi?%s[bbox=%f,%f,%f,%f][%s=%s]' - -def log(msg): - ''' Print a message to the console, unless the 'quiet' flag was set. ''' - if not params.quiet: - print(msg) - -def extract(xmlfile): - ''' Extract nodes from a query result. - - Regular nodes are just added to the result. For ways, the ways tags are copied to the first - node of the way and this first node is added to the result. - - ''' - tree = etree.parse(xmlfile) - root = tree.getroot() - result = {} - nodes = {} - - for child in root: - if child.tag == 'node': - # Save all nodes in this temp structure, if we are parsing ways we need them later on. - nodes[child.attrib['id']] = child - # If the node also contains the tag we are looking for, add it to the result. - for tag in child: - if tag.attrib['k'] == params.tag: - result[child.attrib['id']] = child - elif child.tag == 'way': - # Create a new custom node that contains all of the ways tags and add it to result. If - # a way is returned, it must contain the tag we are looking for, so no need to check. - node = nodes[child[0].attrib['ref']] - for sub in child: - if sub.tag == 'tag': - etree.SubElement(node, 'tag', sub.attrib) - result[node.attrib['id']] = node - elif child.tag == 'remark': - # This usually means the query timed out or ran out of memory. - print('Potential error: %s' % child.text, file=stderr) - - return result - -# Parse command line arguments. -parser = ArgumentParser(description='Generate an OpenLayers OSM file using the Overpass API.', - epilog='See http://code.bitfehler.net for more details.') -parser.add_argument('-q', '--quiet', dest='quiet', action='store_true', help='suppress progress messages') -parser.add_argument('-S', '--step', dest='step', metavar='D', default=1.0, type=float, help='split into steps of D degrees') -parser.add_argument('-p', '--pause', dest='pause', metavar='P', default=1, type=int, help='pause for P seconds between requests to reduce server load (default: 1, must be >= 0)') -parser.add_argument('-t', '--tag', dest='tag', metavar='<tag>', type=str, required=True, help='return only elements with this tag') -parser.add_argument('-v', '--value', dest='value', metavar='<value>', default='*', type=str, help='return only elements with this value (omit for \'*\')') -parser.add_argument('-s', '--south', dest='south', metavar='S', type=float, required=True, help='latitude of the southern border of the bounding box') -parser.add_argument('-w', '--west', dest='west', metavar='W', type=float, required=True, help='longitude of the western border of the bounding box') -parser.add_argument('-n', '--north', dest='north', metavar='N', type=float, required=True, help='latitude of the northern border of the bounding box') -parser.add_argument('-e', '--east', dest='east', metavar='E', type=float, required=True, help='longitude of the eastern border of the bounding box') -parser.add_argument('outfile', metavar='<output file>', type=str, help='the output file for the merged OSM data') -params = parser.parse_args() - -# Sanity checks for the arguments. -if params.pause < 0: - print('Value for --pause must be >= 0. Exiting.', file=stderr) - exit(1) -if params.step <= 0: - print('Value for --pause must be > 0. Exiting.', file=stderr) - exit(1) -try: - open(params.outfile, mode='a', encoding='utf-8') -except IOError as e: - (errno, strerror) = e.args - print('Failed to open output file for writing: %s. Exiting.' % strerror, file=stderr) - exit(1) -if min(params.south, params.north) != params.south: - print('Value for --south must be less then --north. Use negative numbers for southern hemisphere. Exiting.', file=stderr) - exit(1) -if min(params.east, params.west) != params.west: - print('Value for --west must be less then --east. Use e.g. --east 187.5 if you need to cover the 180th meridian. Exiting.', file=stderr) - exit(1) - - -(handle, tmpfile) = mkstemp(suffix='.xml', prefix='osm') -close(handle) -log("Using temporary file %s, step %f and pause %d." % (tmpfile, params.step, params.pause)) - -result = {} - -cur_lat = params.south -cur_lon = params.west - -while cur_lat < params.north: - - # While we are in this loop, there are more squares to fetch. - - # We know which square to go for, get its bbox: - bbox_lon = [cur_lon, min(cur_lon + params.step, params.east)] - bbox_lat = [cur_lat, min(cur_lat + params.step, params.north)] - - nquery = QUERY_TEMPLATE % ('node', bbox_lon[0], bbox_lat[0], bbox_lon[1], bbox_lat[1], params.tag, params.value) - wquery = QUERY_TEMPLATE % ('way', bbox_lon[0], bbox_lat[0], bbox_lon[1], bbox_lat[1], params.tag, params.value) - - log("Fetching %s" % nquery) - urlretrieve(nquery, tmpfile) - result.update(extract(tmpfile)) - - log("Fetching %s" % wquery) - urlretrieve(wquery, tmpfile) - result.update(extract(tmpfile)) - - # Calculate the next sub-bbox: - if cur_lon + params.step < params.east: - # Proceed with next square in current "row": - cur_lon += params.step - else: - # Reset longitude, continue with next "row", if any: - cur_lon = params.west - cur_lat += params.step - - # Wait a moment - might help the server. - sleep(params.pause) - - -log("Removing temporary data file...") -remove(tmpfile) - -log("Generating data...") -with open(params.outfile, mode='w', encoding='utf-8') as out: - out.write('''<?xml version='1.0' encoding='UTF-8'?> -<osm version="0.6" generator="OSMux (http://code.bitfehler.net/osmux"> -<bound box="%f,%f,%f,%f" origin="Osmosis SNAPSHOT-rexported"/> -''' % (params.west, params.south, params.east, params.north)) - for nid in result: - node = result[nid] - out.write(etree.tostring(node, encoding='utf-8').decode('utf-8')) - out.write('</osm>') - diff --git a/template/pages/mate/content.html b/template/pages/mate/content.html deleted file mode 100644 index 64de23d..0000000 --- a/template/pages/mate/content.html +++ /dev/null @@ -1,186 +0,0 @@ -<h2> - [ Mate ] -</h2> -<p> - Diese Karte markiert alle Orte in Leipzig (bzw. sogar ganz Deutschland: einfach herauszoomen) - an denen Club Mate zu haben ist und die bei <a href="http://www.openstreetmap.org">OpenStreetMap</a> mit dem Tag - <i>drink:club-mate=*</i> versehen wurden. Ein paar mehr Details findet Ihr - <a href="http://bitfehler.net/mate">hier</a>. Die Daten werden jede Nacht - aktualisiert. -</p> -<div id="spacer" style="margin-left: 20px;"> -<div id="mapdiv"></div> -</div> -<p style="font-size: 10px;">Javascript required. Click an icon for details. Map data -<a style="font-size: 10px;" href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a> 2011 -<a style="font-size: 10px;" href="http://www.openstreetmap.org">OpenStreetMap</a> contributors.</p> - -<script type="text/javascript" src="http://www.openlayers.org/api/OpenLayers.js"></script> -<script defer="defer" type="text/javascript"> -<!-- - -var obj, map, pois, styleMap, selectControl, selectedFeature, loadingPopup; -var numDots = 3; - -function resizeMap() { - document.getElementById("mapdiv").style.width = "100px" - document.getElementById("mapdiv").style.height = "100px"; - var c = document.getElementsByClassName("content")[0]; - var w = c.offsetWidth; - var h = c.offsetHeight; - w = Math.round(w * 0.90); - document.getElementById("mapdiv").style.width = w + "px" - document.getElementById("mapdiv").style.height = "500px"; -} - -function onPopupClose(evt) { - // 'this' is the popup. - selectControl.unselect(this.feature); -} - -// Pretty-print an amenity tag (and others actually) -function amenityPp(amenity) { - var words = amenity.split("_"); - var result = ""; - for (w in words) { - if (result != "") { - result += " "; - } - result += words[w].charAt(0).toUpperCase() + words[w].slice(1); - } - return result; -} - -function popupText(feature) { - var title = ""; - if ("name" in feature.attributes) { - title = feature.attributes["name"]; - } - else { - title = "*no name*"; - } - if ("website" in feature.attributes) { - title = '<a href="' + feature.attributes["website"] + '" rel="external">' + title + '</a>'; - } - - var desc = ""; - if ("amenity" in feature.attributes) { - desc = '<p style="font-size: smaller">' + amenityPp(feature.attributes["amenity"]) + '</p>'; - } - else if ("leisure" in feature.attributes) { - desc = '<p style="font-size: smaller">' + amenityPp(feature.attributes["leisure"]) + '</p>'; - } - else if ("shop" in feature.attributes) { - desc = '<p style="font-size: smaller">' + amenityPp(feature.attributes["shop"]) + '</p>'; - } - - var addr = ""; - if ("addr:street" in feature.attributes) { - addr += feature.attributes["addr:street"] - if ("addr:housenumber" in feature.attributes) { - addr += " " + feature.attributes["addr:housenumber"]; - } - addr += "</br>"; - } - if ("addr:city" in feature.attributes) { - if ("addr:postcode" in feature.attributes) { - addr += feature.attributes["addr:postcode"] + " "; - } - addr += feature.attributes["addr:city"]; - } - - var open = ""; - if ("opening_hours" in feature.attributes) { - open += '<p style="font-size: smaller">Open: ' + feature.attributes["opening_hours"] + '</p>'; - } - - return "<h2>" + title + "</h2>" + desc + "<p>" + addr + "</p>" + open; -} - -function onFeatureSelect(feature) { - var lst = ""; - for (var prop in feature.attributes) { - lst += prop + " "; - } - popup = new OpenLayers.Popup.FramedCloud( - "featurePopup", - feature.geometry.getBounds().getCenterLonLat(), - new OpenLayers.Size(100,100), - popupText(feature), - null, true, onPopupClose - ); - feature.popup = popup; - popup.feature = feature; - map.addPopup(popup); -} -function onFeatureUnselect(feature) { - if (feature.popup) { - popup.feature = null; - map.removePopup(feature.popup); - feature.popup.destroy(); - feature.popup = null; - } -} - -function dataCallback() { - map.removePopup(loadingPopup); -} - -resizeMap(); -window.onresize = resizeMap; - -map = new OpenLayers.Map("mapdiv"); -layer = new OpenLayers.Layer.OSM(); -layer.attribution = 0; - - -var styleMap = new OpenLayers.Style({ - externalGraphic: '/inc/mate_icon.png', - graphicWidth: 32, - graphicHeight: 32, - graphicXOffset: 0, - graphicYOffset: -32 -}); - -var pois = new OpenLayers.Layer.Vector("Marker", { - styleMap: styleMap, - eventListeners: {"featuresadded": dataCallback }, - strategies: [new OpenLayers.Strategy.Fixed], - projection:map.displayProjection, - protocol: new OpenLayers.Protocol.HTTP({ - url: "/inc/mate.xml", - format: new OpenLayers.Format.OSM, - }) -}); - -map.addLayer(layer); -map.addLayer(pois); - -//Set start centrepoint and zoom -var lonLat = new OpenLayers.LonLat(12.3903, 51.342).transform( - new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984 - map.getProjectionObject() // to Spherical Mercator Projection -); -map.setCenter(lonLat, 12); - -var lonLatPopup = new OpenLayers.LonLat(12.34, 51.36).transform( - new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984 - map.getProjectionObject() // to Spherical Mercator Projection -); - -loadingPopup = new OpenLayers.Popup("loadingPopup", - lonLatPopup, - new OpenLayers.Size(300,200), - '<p style="font-weight: bold; text-align: center; margin-top: 60px">Loading OpenStreetMap data.<br>Please wait.<br><br><span id="dots">...</span></p>', false -); -loadingPopup.opacity = 0.9; -map.addPopup(loadingPopup); - -selectControl = new OpenLayers.Control.SelectFeature(pois, { - onSelect: onFeatureSelect, - onUnselect: onFeatureUnselect -}); -map.addControl(selectControl); -selectControl.activate(); ---> -</script> diff --git a/template/pages/mate/desc_de b/template/pages/mate/desc_de deleted file mode 100644 index 989f864..0000000 --- a/template/pages/mate/desc_de +++ /dev/null @@ -1 +0,0 @@ -Orte in Leipzig an denen Club Mate erhältlich ist diff --git a/template/pages/mate/desc_en b/template/pages/mate/desc_en deleted file mode 100644 index 08bcddf..0000000 --- a/template/pages/mate/desc_en +++ /dev/null @@ -1 +0,0 @@ -Where to find Club Mate in Leipzig diff --git a/template/pages/mate/keywords b/template/pages/mate/keywords deleted file mode 100644 index ab55669..0000000 --- a/template/pages/mate/keywords +++ /dev/null @@ -1 +0,0 @@ -club mate, mate, map, leipzig, openstreetmap diff --git a/template/template/template.html b/template/template/template.html index 68b4b57..16bad39 100644 --- a/template/template/template.html +++ b/template/template/template.html @@ -34,7 +34,7 @@ <div class="image"> <p class="header"> - <span class="box header">[ <a href="/mate">mate</a> und technik ]</span> + <span class="box header">[ <a href="/wiki/Mate/">mate</a> und technik ]</span> </p> <div id="statusimage"></div> <h1> |