Added OpenStreetMap and GoogleMap javascript code into the library for easier processing and usability. Updated NarrativeWeb as needed.
svn: r17946
This commit is contained in:
parent
a232e644a3
commit
2b222cb92a
@ -1,3 +1,5 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#!/usr/bin/python
|
||||||
#
|
#
|
||||||
# Gramps - a GTK+/GNOME based genealogy program
|
# Gramps - a GTK+/GNOME based genealogy program
|
||||||
#
|
#
|
||||||
@ -7,7 +9,7 @@
|
|||||||
# Copyright (C) 2007-2009 Stephane Charette <stephanecharette@gmail.com>
|
# Copyright (C) 2007-2009 Stephane Charette <stephanecharette@gmail.com>
|
||||||
# Copyright (C) 2008 Brian G. Matherly
|
# Copyright (C) 2008 Brian G. Matherly
|
||||||
# Copyright (C) 2008 Jason M. Simanek <jason@bohemianalps.com>
|
# Copyright (C) 2008 Jason M. Simanek <jason@bohemianalps.com>
|
||||||
# Copyright (C) 2008-2009 Rob G. Healey <robhealey1@gmail.com>
|
# Copyright (C) 2008-2011 Rob G. Healey <robhealey1@gmail.com>
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
@ -116,3 +118,65 @@ _COPY_OPTIONS = [
|
|||||||
|
|
||||||
_('No copyright notice'),
|
_('No copyright notice'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# NarrativeWeb javascript code for PlacePage's "Open Street Map"...
|
||||||
|
openstreet_jsc = """
|
||||||
|
var marker;
|
||||||
|
var map;
|
||||||
|
|
||||||
|
OpenLayers.Lang.setCode("%s");
|
||||||
|
|
||||||
|
function mapInit(){
|
||||||
|
map = createMap("map");
|
||||||
|
|
||||||
|
map.dataLayer = new OpenLayers.Layer("Données", { "visibility": false });
|
||||||
|
map.dataLayer.events.register("visibilitychanged", map.dataLayer, toggleData);
|
||||||
|
map.addLayer(map.dataLayer);
|
||||||
|
|
||||||
|
var centre = new OpenLayers.LonLat({$our lon}, {$our lat});
|
||||||
|
var zoom = 11;
|
||||||
|
|
||||||
|
setMapCenter(centre, zoom);
|
||||||
|
|
||||||
|
updateLocation();
|
||||||
|
|
||||||
|
setMapLayers("M");
|
||||||
|
|
||||||
|
map.events.register("moveend", map, updateLocation);
|
||||||
|
map.events.register("changelayer", map, updateLocation);
|
||||||
|
|
||||||
|
handleResize();
|
||||||
|
}"""
|
||||||
|
|
||||||
|
# NarrativeWeb javascript code for PlacePage's "Google Maps"...
|
||||||
|
google_jsc = """
|
||||||
|
var myLatlng = new google.maps.LatLng(%s, %s);
|
||||||
|
var marker;
|
||||||
|
var map;
|
||||||
|
|
||||||
|
function initialize() {
|
||||||
|
var mapOptions = {
|
||||||
|
zoom: 13,
|
||||||
|
mapTypeId: google.maps.MapTypeId.ROADMAP,
|
||||||
|
center: myLatlng
|
||||||
|
};
|
||||||
|
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
|
||||||
|
|
||||||
|
marker = new google.maps.Marker({
|
||||||
|
map: map,
|
||||||
|
draggable: true,
|
||||||
|
animation: google.maps.Animation.DROP,
|
||||||
|
position: myLatlng
|
||||||
|
});
|
||||||
|
|
||||||
|
google.maps.event.addListener(marker, 'click', toggleBounce);
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleBounce() {
|
||||||
|
|
||||||
|
if (marker.getAnimation() != null) {
|
||||||
|
marker.setAnimation(null);
|
||||||
|
} else {
|
||||||
|
marker.setAnimation(google.maps.Animation.BOUNCE);
|
||||||
|
}
|
||||||
|
}"""
|
||||||
|
@ -101,6 +101,9 @@ from DateHandler import displayer as _dd
|
|||||||
from gen.proxy import PrivateProxyDb, LivingProxyDb
|
from gen.proxy import PrivateProxyDb, LivingProxyDb
|
||||||
from libhtmlconst import _CHARACTER_SETS, _CC, _COPY_OPTIONS
|
from libhtmlconst import _CHARACTER_SETS, _CC, _COPY_OPTIONS
|
||||||
|
|
||||||
|
# import for Place Map Pages...
|
||||||
|
from libhtmlconst import openstreet_jsc, google_jsc
|
||||||
|
|
||||||
# import HTML Class from
|
# import HTML Class from
|
||||||
# src/plugins/lib/libhtml.py
|
# src/plugins/lib/libhtml.py
|
||||||
from libhtml import Html
|
from libhtml import Html
|
||||||
@ -202,6 +205,7 @@ wrapper.width = 20
|
|||||||
PLUGMAN = GuiPluginManager.get_instance()
|
PLUGMAN = GuiPluginManager.get_instance()
|
||||||
CSS = PLUGMAN.process_plugin_data('WEBSTUFF')
|
CSS = PLUGMAN.process_plugin_data('WEBSTUFF')
|
||||||
|
|
||||||
|
|
||||||
_html_dbl_quotes = re.compile(r'([^"]*) " ([^"]*) " (.*)', re.VERBOSE)
|
_html_dbl_quotes = re.compile(r'([^"]*) " ([^"]*) " (.*)', re.VERBOSE)
|
||||||
_html_sng_quotes = re.compile(r"([^']*) ' ([^']*) ' (.*)", re.VERBOSE)
|
_html_sng_quotes = re.compile(r"([^']*) ' ([^']*) ' (.*)", re.VERBOSE)
|
||||||
|
|
||||||
@ -2530,8 +2534,7 @@ class PlacePage(BasePage):
|
|||||||
placepage, head, body = self.write_header(_("Places"))
|
placepage, head, body = self.write_header(_("Places"))
|
||||||
|
|
||||||
self.placemappages = self.report.options['placemappages']
|
self.placemappages = self.report.options['placemappages']
|
||||||
self.googlemap = self.report.options['placemappages']
|
self.mapservice = self.report.options['mapservice']
|
||||||
self.openstreetmap = self.report.options['openstreetmap']
|
|
||||||
|
|
||||||
# begin PlaceDetail Division
|
# begin PlaceDetail Division
|
||||||
with Html("div", class_ = "content", id = "PlaceDetail") as placedetail:
|
with Html("div", class_ = "content", id = "PlaceDetail") as placedetail:
|
||||||
@ -2544,10 +2547,10 @@ class PlacePage(BasePage):
|
|||||||
placedetail += thumbnail
|
placedetail += thumbnail
|
||||||
|
|
||||||
# add section title
|
# add section title
|
||||||
placedetail += Html("h5", html_escape(self.page_title), inline = True)
|
placedetail += Html("h5", html_escape(self.page_title), inline =True)
|
||||||
|
|
||||||
# begin summaryarea division and places table
|
# begin summaryarea division and places table
|
||||||
with Html("div", id = 'summaryarea') as summaryarea:
|
with Html("div", id ='summaryarea') as summaryarea:
|
||||||
placedetail += summaryarea
|
placedetail += summaryarea
|
||||||
|
|
||||||
with Html("table", class_ = "infolist place") as table:
|
with Html("table", class_ = "infolist place") as table:
|
||||||
@ -2578,13 +2581,11 @@ class PlacePage(BasePage):
|
|||||||
# call_generate_page(report, title, place_handle, src_list, head, body, place, placedetail)
|
# call_generate_page(report, title, place_handle, src_list, head, body, place, placedetail)
|
||||||
|
|
||||||
# add place map here
|
# add place map here
|
||||||
if ((self.placemappages or self.openstreetmap) and
|
if self.placemappages:
|
||||||
(place and (place.lat and place.long) ) ):
|
if (place and (place.lat and place.long)):
|
||||||
|
|
||||||
# get reallatitude and reallongitude from place
|
# get reallatitude and reallongitude from place
|
||||||
latitude, longitude = conv_lat_lon( place.lat,
|
latitude, longitude = conv_lat_lon(place.lat, place.long, "D.D8")
|
||||||
place.long,
|
|
||||||
"D.D8")
|
|
||||||
|
|
||||||
# add narrative-maps CSS...
|
# add narrative-maps CSS...
|
||||||
fname = "/".join(["styles", "narrative-maps.css"])
|
fname = "/".join(["styles", "narrative-maps.css"])
|
||||||
@ -2592,73 +2593,41 @@ class PlacePage(BasePage):
|
|||||||
head += Html("link", href = url, type = "text/css", media = "screen", rel = "stylesheet")
|
head += Html("link", href = url, type = "text/css", media = "screen", rel = "stylesheet")
|
||||||
|
|
||||||
# add googlev3 specific javascript code
|
# add googlev3 specific javascript code
|
||||||
if self.googlemap:
|
if self.mapservice == "Google":
|
||||||
head += Html("script", type ="text/javascript",
|
head += Html("script", type ="text/javascript",
|
||||||
src ="http://maps.googleapis.com/maps/api/js?sensor=false", inline =True)
|
src ="http://maps.googleapis.com/maps/api/js?sensor=false", inline =True)
|
||||||
|
|
||||||
# Place Map division
|
|
||||||
with Html("div", id = "mapstraction") as mapstraction:
|
|
||||||
placedetail += mapstraction
|
|
||||||
|
|
||||||
# section title
|
# section title
|
||||||
mapstraction += Html("h4", _("Place Map"), inline = True)
|
placedetail += Html("h4", _("Place Map"), inline =True)
|
||||||
|
|
||||||
# begin middle division
|
# begin map_canvas division
|
||||||
with Html("div", id = "middle") as middle:
|
with Html("div", id ="map_canvas") as canvas:
|
||||||
mapstraction += middle
|
placedetail += canvas
|
||||||
|
|
||||||
if self.openstreetmap:
|
if self.mapservice == "OpenStreetMap":
|
||||||
url = 'http://www.openstreetmap.com/?lat=%s&lon=%s&zoom=11&layers=M' % (
|
url = 'http://www.openstreetmap.com/?lat=%s&lon=%s&zoom=11&layers=M' % (
|
||||||
latitude, longitude)
|
latitude, longitude)
|
||||||
middle += Html("object", data = url, inline = True)
|
canvas += Html("object", type ="'text/html'", width ="98%", height ="98%",
|
||||||
|
data =url)
|
||||||
|
|
||||||
elif self.googlemap:
|
|
||||||
# begin inline javascript code
|
# begin inline javascript code
|
||||||
# because jsc is a string, it does NOT have to be properly indented
|
# because jsc is a string, it does NOT have to be properly indented
|
||||||
with Html("script", type = "text/javascript") as jsc:
|
with Html("script", type = "text/javascript") as jsc:
|
||||||
|
if self.mapservice == "Google":
|
||||||
head += jsc
|
head += jsc
|
||||||
|
jsc += google_jsc % (latitude, longitude)
|
||||||
|
else:
|
||||||
|
canvas += jsc
|
||||||
|
jsc += openstreet_jsc % Utils.xml_lang()[3:5].lower()
|
||||||
|
|
||||||
jsc += """
|
|
||||||
var myLatlng = new google.maps.LatLng(%s, %s);""" % (latitude, longitude)
|
|
||||||
|
|
||||||
jsc += """
|
|
||||||
var marker;
|
|
||||||
var map;
|
|
||||||
|
|
||||||
function initialize() {
|
|
||||||
var mapOptions = {
|
|
||||||
zoom: 13,
|
|
||||||
mapTypeId: google.maps.MapTypeId.ROADMAP,
|
|
||||||
center: myLatlng
|
|
||||||
};
|
|
||||||
map = new google.maps.Map(document.getElementById("middle"), mapOptions);
|
|
||||||
|
|
||||||
marker = new google.maps.Marker({
|
|
||||||
map: map,
|
|
||||||
draggable: true,
|
|
||||||
animation: google.maps.Animation.DROP,
|
|
||||||
position: myLatlng
|
|
||||||
});
|
|
||||||
|
|
||||||
google.maps.event.addListener(marker, 'click', toggleBounce);
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleBounce() {
|
|
||||||
|
|
||||||
if (marker.getAnimation() != null) {
|
|
||||||
marker.setAnimation(null);
|
|
||||||
} else {
|
|
||||||
marker.setAnimation(google.maps.Animation.BOUNCE);
|
|
||||||
}
|
|
||||||
}"""
|
|
||||||
# there is no need to add an ending "</script>",
|
# there is no need to add an ending "</script>",
|
||||||
# as it will be added automatically!
|
# as it will be added automatically!
|
||||||
|
|
||||||
# add fullclear for proper styling
|
# add fullclear for proper styling
|
||||||
middle += fullclear
|
canvas += fullclear
|
||||||
|
|
||||||
# add javascript function call to body element
|
# add javascript function call to body element
|
||||||
body.attr = 'onload = "initialize();"'
|
body.attr ='onload ="initialize();" '
|
||||||
|
|
||||||
# source references
|
# source references
|
||||||
srcrefs = self.display_ind_sources(place)
|
srcrefs = self.display_ind_sources(place)
|
||||||
@ -4050,9 +4019,7 @@ class IndividualPage(BasePage):
|
|||||||
if not place_lat_long:
|
if not place_lat_long:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.placemappages = self.report.options['placemappages']
|
self.familymappages = self.report.options['familymappages']
|
||||||
self.googlemap = self.report.options['placemappages']
|
|
||||||
self.openstreetmap = self.report.options['openstreetmap']
|
|
||||||
|
|
||||||
minX, maxX = "0.00000001", "0.00000001"
|
minX, maxX = "0.00000001", "0.00000001"
|
||||||
minY, maxY = "0.00000001", "0.00000001"
|
minY, maxY = "0.00000001", "0.00000001"
|
||||||
@ -4110,7 +4077,7 @@ class IndividualPage(BasePage):
|
|||||||
url = self.report.build_url_fname(fname, None, self.up)
|
url = self.report.build_url_fname(fname, None, self.up)
|
||||||
head += Html("link", href =url, type ="text/css", media ="screen", rel ="stylesheet")
|
head += Html("link", href =url, type ="text/css", media ="screen", rel ="stylesheet")
|
||||||
|
|
||||||
if self.placemappages:
|
if self.familymappages:
|
||||||
head += Html("script", type ="text/javascript",
|
head += Html("script", type ="text/javascript",
|
||||||
src ="http://maps.googleapis.com/maps/api/js?sensor=false", inline =True)
|
src ="http://maps.googleapis.com/maps/api/js?sensor=false", inline =True)
|
||||||
|
|
||||||
@ -5647,8 +5614,7 @@ class NavWebReport(Report):
|
|||||||
|
|
||||||
# Place Map tab options
|
# Place Map tab options
|
||||||
self.placemappages = self.options['placemappages']
|
self.placemappages = self.options['placemappages']
|
||||||
self.googlemap = self.options['placemappages']
|
self.mapservice = self.options['mapservice']
|
||||||
self.openstreetmap = self.options['openstreetmap']
|
|
||||||
self.familymappages = self.options['familymappages']
|
self.familymappages = self.options['familymappages']
|
||||||
|
|
||||||
if self.use_home:
|
if self.use_home:
|
||||||
@ -6684,34 +6650,38 @@ class NavWebOptions(MenuReportOptions):
|
|||||||
addopt( "inc_addressbook", inc_addressbook )
|
addopt( "inc_addressbook", inc_addressbook )
|
||||||
|
|
||||||
def __add_place_map_options(self, menu):
|
def __add_place_map_options(self, menu):
|
||||||
|
"""
|
||||||
category_name = _("Place Maps")
|
options for the Place Map tab.
|
||||||
|
"""
|
||||||
|
category_name = _("Place Map Options")
|
||||||
addopt = partial(menu.add_option, category_name)
|
addopt = partial(menu.add_option, category_name)
|
||||||
|
|
||||||
self.__placemappages = BooleanOption(_("Include Place map on Place Pages (Google maps)"), False)
|
self.__placemappages = BooleanOption(_("Include Place map on Place Pages"), False)
|
||||||
self.__placemappages.set_help(_("Whether to include a Google map on the Place Pages, "
|
self.__placemappages.set_help(_("Whether to include a place map on the Place Pages, "
|
||||||
"where Latitude/ Longitude are available."))
|
"where Latitude/ Longitude are available."))
|
||||||
self.__placemappages.connect("value-changed", self.__placemaps_changed)
|
self.__placemappages.connect("value-changed", self.__placemap_changed)
|
||||||
addopt( "placemappages", self.__placemappages)
|
addopt("placemappages", self.__placemappages)
|
||||||
|
|
||||||
self.__openstreetmap = BooleanOption(_("Include Place map on Place Pages (OpenStreetMap)"), False)
|
mapopts = [
|
||||||
self.__openstreetmap.set_help(_("Whether to include a OpenStreet map on the Place Pages, "
|
[_("Google"), "Google"],
|
||||||
"where Latitude/ Longitude are available."))
|
[_("OpenStreetMap"), "OpenStreetMap"] ]
|
||||||
self.__openstreetmap.connect("value-changed", self.__openstreetmap_changed)
|
self.__mapservice = EnumeratedListOption(_("Map Service"), mapopts[0][1])
|
||||||
addopt("openstreetmap", self.__openstreetmap)
|
for opts in mapopts:
|
||||||
|
self.__mapservice.add_item(opts[0], opts[1])
|
||||||
|
self.__mapservice.set_help(_("Choose your choice of map service for "
|
||||||
|
"creating the Place Map Pages."))
|
||||||
|
addopt("mapservice", self.__mapservice)
|
||||||
|
|
||||||
self.__placemaps_changed()
|
self.__placemap_changed()
|
||||||
self.__openstreetmap_changed()
|
|
||||||
|
|
||||||
familymappages = BooleanOption(_("Include Individual Page Map with "
|
familymappages = BooleanOption(_("Include Family Map Pages with "
|
||||||
"all places shown on map (Google Maps)"), False)
|
"all places shown on the map"), False)
|
||||||
familymappages.set_help(_("Whether or not to add an individual Google map "
|
familymappages.set_help(_("Whether or not to add an individual page map "
|
||||||
"showing all the places on this page. "
|
"showing all the places on this page. "
|
||||||
"This will allow you to see how your family "
|
"This will allow you to see how your family "
|
||||||
"traveled around the country."))
|
"traveled around the country."))
|
||||||
addopt( "familymappages", familymappages )
|
addopt( "familymappages", familymappages )
|
||||||
|
|
||||||
|
|
||||||
def __archive_changed(self):
|
def __archive_changed(self):
|
||||||
"""
|
"""
|
||||||
Update the change of storage: archive or directory
|
Update the change of storage: archive or directory
|
||||||
@ -6812,6 +6782,16 @@ class NavWebOptions(MenuReportOptions):
|
|||||||
else:
|
else:
|
||||||
self.__placemappages.set_available(True)
|
self.__placemappages.set_available(True)
|
||||||
|
|
||||||
|
def __placemap_changed(self):
|
||||||
|
"""
|
||||||
|
Handles the changing nature of the place maps
|
||||||
|
"""
|
||||||
|
|
||||||
|
if self.__placemappages.get_value():
|
||||||
|
self.__mapservice.set_available(True)
|
||||||
|
else:
|
||||||
|
self.__mapservice.set_available(False)
|
||||||
|
|
||||||
# FIXME. Why do we need our own sorting? Why not use Sort.Sort?
|
# FIXME. Why do we need our own sorting? Why not use Sort.Sort?
|
||||||
def sort_people(db, handle_list):
|
def sort_people(db, handle_list):
|
||||||
sname_sub = defaultdict(list)
|
sname_sub = defaultdict(list)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user