ciao!
I hope not to be too mutch out of topic... this time I have a question
related to javascript and it's integration with web2py.
Here under you'll find the only way I found to run this simple
openlayers example
http://openlayers.org/dev/examples/osm.html
* controllers/plugin_map.py
def map():
return dict()
* views/plugin_map/map.html
{{# here I load the necessary openlayers library and style sheets
start = 0
for idx,source in enumerate((
'OpenLayers-2.11/OpenLayers.js',
'OpenLayers-2.11/theme/default/style.css',
'OpenLayers-2.11/style.css',
)):
#
response.files.insert(start+idx,URL(request.application,'static',source))
response.files.append(URL(request.application,'static',source))
pass}}
<script type="text/javascript"><!--
// here is the map definition
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
);
}
//--></script>
{{extend 'layout.html'}}
<!-- here is where I want to place my map -->
<div id="map" class="smallmap"></div>
<script>init();</script>
and off course I downloaded the necessary Openlayers library in my
static folder.
Do you think there's a more "elegant" or correct way to do it?
What I don't like is that, as you can see here:
view-source:http://manuele.pythonanywhere.com/test_openlayers/plugin_map/map
the javascrit is written in the top part of the resulting html before
any tag definition... id est outside <html>
any othe code position results in a white page with no map in it.
Please foregive my javascript ignorance... I've looked around ansking
solutions to google but without results.
Thank you very mutch
Manuele