Skip to content

Instantly share code, notes, and snippets.

@manuelep
Created November 6, 2014 21:57
Show Gist options
  • Save manuelep/e831dd99eebe035781ba to your computer and use it in GitHub Desktop.
Save manuelep/e831dd99eebe035781ba to your computer and use it in GitHub Desktop.
web2py Openstreetmap implementation example
# -*- coding: utf-8 -*-
for url in [
'http://dev.openlayers.org/theme/default/style.css',
'http://dev.openlayers.org/examples/style.css',
'http://dev.openlayers.org/OpenLayers.js'
]:
response.files.append(url)
def map():
mymap = DIV(_id="map", _class="smallmap")
response.js = """var map, layer;
function init(){
map = new OpenLayers.Map( 'map');
layer = new OpenLayers.Layer.OSM( "Simple OSM Map");
map.addLayer(layer);
map.setCenter(
new OpenLayers.LonLat(-71.147, 42.472).transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject()
), 12
);
};
init();
"""
return locals()
def index():
mymap = LOAD('test', 'map.load', ajax=True)
return locals()
@manuelep
Copy link
Author

manuelep commented Nov 6, 2014

README

Just download this file in a brand new web2py project under the controllers folder.
That's it. Now just browse the page at the url http://localhost:8000/myapp/test/index

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment