Source

moinmoin-osm / macro / OSM.py

# -*- coding: utf-8 -*-
#
#Author : Igor Támara
#Date : 11/09/2008
#Given to the public domain.

#This is a moinmoin plugin : It projects data from OSM through
#OpenLayers to your moinmoin instance.
#
#
#= Parameter description =
#<<OSM(4.65514589,-74.109660387,13,http://www.gfc.edu.co/images/marker.png,200,350)>>
#Will project an OSM map using OpenLayers centered at lan,lot (4.65514589,-74.109660387)
#with 13 zoom a marker provided by http://www.gfc.edu.co/images/marker.png on a
#200px width 350 height map.
#
# Enjoy

#Working with IE5.5 And above thanks to woakas patch, still working with Firefox and Iceweasel ;)

def parseargs(args):
    mydict={}
    mydict['lat']=args[0]
    mydict['lon']=args[1]
    keys=['lat','lon','zoom,13','marker,http://www.parroquiaemaus.org/themes/danieltheme/imapa.png','width,500','height,400']
    for i in range(2,len(args)):
        spl=keys[i].split(",")
    	mydict[spl[0]]=args[i]
    for i in range(len(args),len(keys)):
        spl=keys[i].split(",")
    	mydict[spl[0]]=spl[1]
    return mydict

def execute(macro,args):
    spl=args.split(",")
    if len(spl)<2:
    	return "Indique latitud y longitud como mínimo"
    mydict=parseargs(spl)
    return """<div style="width: %(width)spx; height: %(height)spx;"  id="map"></div>
  <script src="http://www.openlayers.org/api/2.11/OpenLayers.js"></script>
  <script>
    map = new OpenLayers.Map("map");
    map.addLayer(new OpenLayers.Layer.OSM());
 
    var lonLat = new OpenLayers.LonLat( %(lon)s ,%(lat)s )
          .transform(
            new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
            map.getProjectionObject() // to Spherical Mercator Projection
          );
 
    var zoom=%(zoom)s;
    var size = new OpenLayers.Size(21,25);
    var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
    var markers = new OpenLayers.Layer.Markers( "Markers" );
    map.addLayer(markers);
 
    markers.addMarker(new OpenLayers.Marker(lonLat,new OpenLayers.Icon('%(marker)s',size,offset)));
 
    map.setCenter (lonLat, zoom);
  </script>
"""  % mydict