Commits

Igor Támara  committed f880d32

Added parser for multiple markers

  • Participants
  • Parent commits 6e8981a

Comments (0)

Files changed (2)

-This is a moinmoin macro to embed an openstreetmap with
-a marker in a MoinMoin instance
+We offer plugins for moinmoin to embed an openstreetmap with
+markers in a MoinMoin instance
+
+As a macro you can create a simple map with one marker
 
 For example :
 
    <<OSM(4.65514589,-74.109660387,13,http://www.gfc.edu.co/images/marker.png,200,350)>>
+
+For a set of markers we offer a parser that can be used like:
+
+    {{{#!osm icon=http://tatica.fedorapeople.org/varios/glifo-mapa.png,mapzoom=5,divname=map2
+    4.65514589,-74.109660387
+    3.42766,-76.54992
+    }}}

File parser/osm.py

+# -*- coding: utf-8 -*-
+"""
+    MoinMoin - OSM map with many markers
+    Given to the public domain, if you have issues
+    with this type of contribution let me know to
+    consider it
+"""
+
+from MoinMoin import wikiutil, i18n
+
+Dependencies = []
+
+class Parser:
+    """
+        Outputs an OpenStreetMap with markers, the first marker
+        is the center of the map, you must provide the proper
+        zoom to make the markers appear in the map
+    """
+    Dependencies = []
+    
+    def __init__(self, raw, request, **kw):
+        self.raw = raw
+        self.request = request
+        self.form = request.form
+        self._ = request.getText
+        self.defaults = {
+            "icon" : "http://open78layers.org/dev/img/marker.png",
+            "centermap" : (4.65514589,-74.109660387),
+            "mapzoom" : 6,
+            "divname" : "map",
+            "width" : 500,
+            "height" : 300,
+            }
+        try :
+            args=kw.get('format_args','').split(",")
+            for pair in args:
+                k,val = pair.split("=")
+                self.defaults[k]=val
+        except:
+            """If the user does not pass properly formatted params, we omit them"""
+            pass
+
+    def format(self, formatter):
+        """ Send the text. """
+        markers=[]
+        try:
+            i=0
+            for latlon in self.raw.split("\n"):
+                try :
+                    lat,lon = latlon.split(",")
+                    float(lat)
+                    float(lon)
+                    markers.append("d[%d]={'lat':%s,'lon':%s};" % (i,lat,lon))
+                    
+                    i+=1
+                except:
+                    raise
+            self.defaults.update({'listmarkers':"\n".join(markers)})
+            self.request.write("""<script
+    src="http://static.slec.net/slecstats/js/jquery-latest.min.js"
+    type="text/javascript"></script><script
+    src="http://openlayers.org/api/2.10/OpenLayers.js"
+    type="text/javascript"></script><script
+    src="http://openstreetmap.org/openlayers/OpenStreetMap.js"
+    type="text/javascript"></script><script
+    src="http://static.slec.net/slecstats/js/map.js"
+    type="text/javascript"></script><script type="text/javascript">
+    jQuery(document).ready(function () {
+       var d= Array();
+       %(listmarkers)s
+       var %(divname)s = my_map('id_%(divname)s',d,'%(icon)s',%(mapzoom)s);
+    });
+
+</script>
+   <div style="width: %(width)spx; height: %(height)spx;" id="id_%(divname)s"></div>
+   """ % self.defaults)
+        except:
+            self.request.write(formatter.sysmsg(1) + 
+                formatter.text(self._('Error while trying to parse blockquote')) +
+                formatter.sysmsg(0))
+