Added extra features to OpenStreetMap in Place Maps.

svn: r17966
This commit is contained in:
Rob G. Healey 2011-07-26 05:12:15 +00:00
parent 59c793608c
commit 888e464700
3 changed files with 42 additions and 48 deletions

View File

@ -121,33 +121,32 @@ _COPY_OPTIONS = [
# NarrativeWeb javascript code for PlacePage's "Open Street Map"...
openstreet_jsc = """
var marker;
var map;
OpenLayers.Lang.setCode("%s");
OpenLayers.Lang.setCode("%s");
function initialize() {
map = new OpenLayers.Map("map_canvas");
map.addLayer(new OpenLayers.Layer.OSM());
function initialize(){
map = new OpenLayers.Map("map_canvas");
var center = new OpenLayers.LonLat(%s, %s);
var zoom = 11;
map.setCenter(center, zoom);
var osm = new OpenLayers.Layer.OSM("OpenStreetMap");
var markers = new OpenLayers.Layer.Markers("Markers");
markers.addMarker(new OpenLayers.Marker(marker));
map.addLayers([osm, markers]);
// add overview control
map.addControl(new OpenLayers.Control.OverviewMap());
// add a layer switcher
map.addControl(new OpenLayers.Control.LayerSwitcher());
var lonLat = new OpenLayers.LonLat(%s, %s)
.transform(
new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
map.getProjectionObject() // to Spherical Mercator Projection
);
var zoom =16;
map.setCenter(lonLat, zoom);
map.zoomToMaxExtent();
var osm = new OpenLayers.Layer.OSM("OpenStreetMap");
var markers = new OpenLayers.Layer.Markers( "Markers" );
markers.addMarker(new OpenLayers.Marker(lonLat));
map.addLayers([osm, markers]);
}"""
// add overview control
map.addControl(new OpenLayers.Control.OverviewMap());
// add a layer switcher
map.addControl(new OpenLayers.Control.LayerSwitcher());
}"""
# NarrativeWeb javascript code for PlacePage's "Google Maps"...
google_jsc = """

View File

@ -1134,16 +1134,15 @@ class BasePage(object):
# Header constants
xmllang = Utils.xml_lang()
_META1 = 'name="generator" content="%s %s %s"' % (
_META1 = 'name ="viewport" content ="width=device-width, initial-scale=1.0, user-scalable=yes" '
_META2 = 'name="generator" content="%s %s %s"' % (
const.PROGRAM_NAME, const.VERSION, const.URL_HOMEPAGE)
_META2 = 'name="author" content="%s"' % self.author
_META3 = 'name ="viewport" content ="width=device-width, initial-scale=1.0, user-scalable=yes" '
_META3 = 'name="author" content="%s"' % self.author
page, head, body = Html.page('%s - %s' %
(html_escape(self.title_str),
(html_escape(self.title_str.strip()),
html_escape(title)),
self.report.encoding, xmllang )
self.report.encoding, xmllang)
# temporary fix for .php parsing error
if self.ext in [".php", ".php3", ".cgi"]:
@ -2592,13 +2591,11 @@ class PlacePage(BasePage):
url = self.report.build_url_fname(fname, None, self.up)
head += Html("link", href = url, type = "text/css", media = "screen", rel = "stylesheet")
# add googlev3 specific javascript code
# add MapService specific javascript code
if self.mapservice == "Google":
head += Html("script", type ="text/javascript",
src ="http://maps.googleapis.com/maps/api/js?sensor=false", inline =True)
# try to add OpenLayers specific javascript code ...
if self.mapservice == "OpenStreetMap":
else:
head += Html("script", type ="text/javascript",
src ="http://www.openlayers.org/api/OpenLayers.js", inline =True)
@ -2609,27 +2606,16 @@ class PlacePage(BasePage):
with Html("div", id ="map_canvas") as canvas:
placedetail += canvas
if self.mapservice == "OpenStreetMap":
url = 'http://www.openstreetmap.com/?lat=%s&lon=%s&zoom=11&layers=M' % (
latitude, longitude)
canvas += Html("object", type ="text/html", width ="98%", height ="98%",
data =url)
# begin inline javascript code
# because jsc is a string, it does NOT have to be properly indented
# because jsc is a docstring, it does NOT have to be properly indented
with Html("script", type = "text/javascript") as jsc:
if self.mapservice == "Google":
head += jsc
head += jsc
# in Google Maps, they use Latitude before Longitude
if self.mapservice == "Google":
jsc += google_jsc % (latitude, longitude)
else:
canvas += jsc
# in OpenStreetMap, they use Longitude before Latitude
jsc += openstreet_jsc % (Utils.xml_lang()[3:5].lower(),
longitude, latitude)
longitude, latitude)
# there is no need to add an ending "</script>",
# as it will be added automatically!

View File

@ -69,3 +69,12 @@ div#middlesection {
float: center;
overflow-y: hidden;
}
/* map_canvas-- place map holder
------------------------------------------------- */
div#map_canvas {
margin-left: 30px;
border: solid 4px #000;
width: 900px;
height: 600px;
}