geomap support

This commit is contained in:
Nils Schneider 2012-05-12 16:44:27 +02:00
commit f05e6a3a26
71 changed files with 649 additions and 8 deletions

37
bat2geomap.py Normal file
View file

@ -0,0 +1,37 @@
#!/usr/bin/env python
# TODO
# Gatewayliste
# aliases.json
import json
import fileinput
import argparse
from nodedb import NodeDB
from geomapbuilder import GeoMapBuilder
parser = argparse.ArgumentParser()
parser.add_argument('-a', '--aliases',
help='read aliases from FILE',
metavar='FILE')
parser.add_argument('batmanjson', help='output of batman vd json')
args = parser.parse_args()
options = vars(args)
db = NodeDB()
db.import_batman(list(fileinput.input(options['batmanjson'])))
if options['aliases']:
db.import_aliases(json.load(open(options['aliases'])))
db.import_wikigps("http://freifunk.metameute.de/Knoten")
m = GeoMapBuilder(db)
print(m.build())

113
geomapbuilder.py Normal file
View file

@ -0,0 +1,113 @@
class GeoMapBuilder:
kml_template = """<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Style id="virtual-link">
<LineStyle>
<color>#4f0013f8</color>
<width>2</width>
</LineStyle>
</Style>
<Style id="wifi-link">
<LineStyle>
<color>#ff13d854</color>
<width>4</width>
</LineStyle>
</Style>
<Style id="router-unknown">
<IconStyle>
<Icon>
<href>router-unknown.png</href>
<scale>1.0</scale>
</Icon>
</IconStyle>
</Style>
<Style id="router-up">
<IconStyle>
<Icon>
<href>router-up.png</href>
<scale>1.0</scale>
</Icon>
</IconStyle>
</Style>
<Style id="router-down">
<IconStyle>
<Icon>
<href>router-down.png</href>
<scale>1.0</scale>
</Icon>
</IconStyle>
</Style>
%s
</Document>
</kml>"""
def __init__(self, db):
self._db = db
def build(self):
text = []
nodes = self._db.get_nodes()
for node in nodes:
try:
text.append(GeoNode(node).render())
except:
continue
for link in self._db.get_links():
try:
text.append(GeoEdge(nodes, link).render())
except:
continue
return self.kml_template % "".join(text)
def gps_format(s):
return ",".join(s.split(" ")[::-1])
class GeoNode:
kml_template = """<Placemark>
<name>%s</name>
<styleUrl>#router-%s</styleUrl>
<Point>
<coordinates>%s,0</coordinates>
</Point>
<description>%s</description>
</Placemark>"""
def __init__(self, node):
self._node = node
def render(self):
if not self._node.gps:
raise
name = self._node.name
status = "up" if self._node.online else "down"
gps = gps_format(self._node.gps)
text = " ".join(self._node.macs)
return self.kml_template % (name, status, gps, text)
class GeoEdge:
kml_template = """<Placemark>
<LineString>
<coordinates>%s,0. %s,0.</coordinates>
</LineString>
<styleUrl>#%s</styleUrl>
</Placemark>"""
def __init__(self, nodes, link):
self._link = link
self.pair = [nodes[k] for k in link.pair]
def render(self):
if not (self.pair[0].gps and self.pair[1].gps):
raise
a = gps_format(self.pair[0].gps)
b = gps_format(self.pair[1].gps)
return self.kml_template % (a, b, "wifi-link")

122
html/geomap.html Normal file
View file

@ -0,0 +1,122 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="theme/default/style.css" type="text/css" />
<style type="text/css">
#map {
width: 100%;
height: 100%;
}
.olPopup p { margin:0px; }
</style>
<title>Freifunk Lübeck - Knotenkarte</title>
<script src="http://maps.burningsilicon.net/OpenLayers-2.8/OpenLayers.js"></script>
<script src="http://maps.burningsilicon.net/OpenLayers-2.8/cloudmade.js"></script>
<script src="http://maps.burningsilicon.net/OpenLayers-2.8/OpenStreetMap.js"></script>
<script type="text/javascript">
var map;
OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control);
function init()
{
map = new OpenLayers.Map ("map", {
controls:[
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.PanZoomBar(),
new OpenLayers.Control.LayerSwitcher(),
new OpenLayers.Control.Attribution(),
new OpenLayers.Control.Permalink(),
new OpenLayers.Control.ScaleLine(),
new OpenLayers.Control.OverviewMap(),
new OpenLayers.Control.MousePosition()],
maxResolution: 156543.0399,
numZoomLevels: 19,
units: 'm',
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326")
} );
var layerMapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik");
map.addLayer(layerMapnik);
var layerTilesAtHome = new OpenLayers.Layer.OSM.Osmarender("Osmarender");
map.addLayer(layerTilesAtHome);
var layerCycleMap = new OpenLayers.Layer.OSM.CycleMap("CycleMap");
map.addLayer(layerCycleMap);
var center = new OpenLayers.LonLat(153.02775, -27.47558).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
var zoom = 11
map.setCenter(center, zoom);
vectorLayer = new OpenLayers.Layer.GML("KML", 'geomap.kml',
{
projection: new OpenLayers.Projection("EPSG:4326"),
eventListeners: { 'loadend': kmlLoaded },
format: OpenLayers.Format.KML,
formatOptions: {
style: {strokeColor: "green", strokeWidth: 5, strokeOpacity: 0.5},
extractStyles: true,
maxDepth: 2,
extractAttributes: true
}
});
map.addLayer(vectorLayer);
selectControl = new OpenLayers.Control.SelectFeature(map.layers[3],
{onSelect: onFeatureSelect, onUnselect: onFeatureUnselect});
map.addControl(selectControl);
selectControl.activate();
var click = new OpenLayers.Control.Click();
map.addControl(click);
click.activate();
}
function onPopupClose(evt)
{
selectControl.unselect(selectedFeature);
}
function onFeatureSelect(feature)
{
selectedFeature = feature;
popup = new OpenLayers.Popup.FramedCloud("chicken",
feature.geometry.getBounds().getCenterLonLat(),
new OpenLayers.Size(100,150),
"<div style='font-size:.8em'><b>Name:</b>"+feature.attributes.name+"<br><b>Description:</b>"+feature.attributes.description+"</div>",
null, true, onPopupClose);
feature.popup = popup;
map.addPopup(popup);
}
function onFeatureUnselect(feature)
{
map.removePopup(feature.popup);
feature.popup.destroy();
feature.popup = null;
}
function kmlLoaded()
{
map.zoomToExtent(vectorLayer.getDataExtent());
}
</script>
</head>
<body onload="init()">
<h1>luebeck.freifunk.net</h1>
<ul>
<li><a href="nodes.html">Knotengraph</a></li>
<li><a href="geomap.html">Knotenkarte</a></li>
</ul>
<h2>Knotenkarte</h2>
<div id="map"></div>
</body>

BIN
html/img/blank.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 B

BIN
html/img/cloud-popup-relative.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
html/img/east-mini.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 451 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 451 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 249 B

BIN
html/img/marker-blue.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 992 B

BIN
html/img/marker-gold.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 831 B

BIN
html/img/marker-green.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 967 B

BIN
html/img/marker.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 606 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

BIN
html/img/north-mini.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 484 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

BIN
html/img/slider.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 285 B

Some files were not shown because too many files have changed in this diff Show more