Attachment 'osm-1.9.py'
Download 1 # -*- coding: utf-8 -*-
2 """
3 MoinMoin - OSM map with many markers
4 Given to the public domain, if you have issues
5 with this type of contribution let me know to
6 consider it
7 """
8
9 from MoinMoin import wikiutil, i18n
10
11 Dependencies = []
12
13 class Parser:
14 """
15 Outputs an OpenStreetMap with markers, the first marker
16 is the center of the map, you must provide the proper
17 zoom to make the markers appear in the map
18 """
19 Dependencies = []
20
21 def __init__(self, raw, request, **kw):
22 self.raw = raw
23 self.request = request
24 self.form = request.form
25 self._ = request.getText
26 self.defaults = {
27 "icon" : "http://open78layers.org/dev/img/marker.png",
28 "centermap" : (4.65514589,-74.109660387),
29 "mapzoom" : 6,
30 "divname" : "map",
31 "width" : 500,
32 "height" : 300,
33 }
34 try :
35 args=kw.get('format_args','').split(",")
36 for pair in args:
37 k,val = pair.split("=")
38 self.defaults[k]=val
39 except:
40 """If the user does not pass properly formatted params, we omit them"""
41 pass
42
43 def format(self, formatter):
44 """ Send the text. """
45 markers=[]
46 try:
47 i=0
48 for latlon in self.raw.split("\n"):
49 try :
50 lat,lon = latlon.split(",")
51 float(lat),float(lon) #Make sure we have numbers
52 markers.append("d[%d]={'lat':%s,'lon':%s};" % (i,lat,lon))
53 i+=1
54 except:
55 pass
56 self.defaults.update({'listmarkers':"\n".join(markers)})
57 self.request.write("""<script
58 src="http://ikks.github.io/js/moinmoin-osm/jquery-latest.min.js"
59 type="text/javascript"></script><script
60 src="http://openlayers.org/api/2.10/OpenLayers.js"
61 type="text/javascript"></script><script
62 src="http://openstreetmap.org/openlayers/OpenStreetMap.js"
63 type="text/javascript"></script><script
64 src="http://ikks.github.io/js/moinmoin-osm/map.js"
65 type="text/javascript"></script><script type="text/javascript">
66 jQuery(document).ready(function () {
67 var d= Array();
68 %(listmarkers)s
69 var %(divname)s = my_map('id_%(divname)s',d,'%(icon)s',%(mapzoom)s);
70 });
71
72 </script>
73 <div style="width: %(width)spx; height: %(height)spx;" id="id_%(divname)s"></div>
74 """ % self.defaults)
75 except:
76 self.request.write(formatter.sysmsg(1) +
77 formatter.text(self._('Error while trying to parse blockquote')) +
78 formatter.sysmsg(0))
79
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.