Fixed and updated Place Maps to work with the new google v3 maps javascript code. Error reported by Jerome Rapinet.

svn: r17942
This commit is contained in:
Rob G. Healey 2011-07-21 01:44:50 +00:00
parent 8aa8f58036
commit 924adb2a45
4 changed files with 134 additions and 142 deletions

View File

@ -2526,12 +2526,16 @@ class PlacePage(BasePage):
self.up = True
self.page_title = place.get_title()
placepage, head, body = self.write_header(_("Places"))
self.placemappages = self.report.options['placemappages']
self.googlemap = self.report.options['placemappages']
self.openstreetmap = self.report.options['openstreetmap']
# begin PlaceDetail Division
with Html("div", class_ = "content", id = "PlaceDetail") as placedetail:
body += placedetail
if self.create_media:
media_list = place.get_media_list()
thumbnail = self.display_first_image_as_thumbnail(media_list, place)
if thumbnail is not None:
@ -2572,27 +2576,23 @@ class PlacePage(BasePage):
# call_generate_page(report, title, place_handle, src_list, head, body, place, placedetail)
# add place map here
if self.placemappages:
if (place and (place.lat and place.long)):
if ((self.placemappages or self.openstreetmap) and
(place and (place.lat and place.long) ) ):
# get reallatitude and reallongitude from place
latitude, longitude = conv_lat_lon( place.lat,
place.long,
"D.D8")
# add Mapstraction CSS
fname = "/".join(["styles", "mapstraction.css"])
# add narrative-maps CSS...
fname = "/".join(["styles", "narrative-maps.css"])
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
head += Html("script", type = "text/javascript",
src = "http://maps.google.com/maps/api/js?sensor=false", inline = True)
# add mapstraction javascript code
fname = "/".join(["mapstraction", "mxn.js?(googlev3)"])
url = self.report.build_url_fname(fname, None, self.up)
head += Html("script", type = "text/javascript", src = url, inline = True)
if self.googlemap:
head += Html("script", type ="text/javascript",
src ="http://maps.googleapis.com/maps/api/js?sensor=false", inline =True)
# Place Map division
with Html("div", id = "mapstraction") as mapstraction:
@ -2605,49 +2605,53 @@ class PlacePage(BasePage):
with Html("div", id = "middle") as middle:
mapstraction += middle
if self.openstreetmap:
url = 'http://www.openstreetmap.com/?lat=%s&lon=%s&zoom=11&layers=M' % (
latitude, longitude)
middle += Html("object", data = url, inline = True)
elif self.googlemap:
# begin inline javascript code
# because jsc is a string, it does NOT have to properly indented
# because jsc is a string, it does NOT have to be properly indented
with Html("script", type = "text/javascript") as jsc:
middle += jsc
head += jsc
jsc += """
var myLatlng = new google.maps.LatLng(%s, %s);""" % (latitude, longitude)
jsc += """
var marker;
var map;
var home = new mxn.LatLonPoint(%s, %s);""" % (latitude, longitude)
jsc += """
function initialize() {
var mapOptions = {
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: myLatlng
};
map = new google.maps.Map(document.getElementById("middle"), mapOptions);
// create mxn object
map = new mxn.Mapstraction('googlev3','googlev3');
// add map controls to image
map.addControls({
pan: true,
zoom: 'large',
scale: true,
keyboardShortcuts: true,
map_type: true
marker = new google.maps.Marker({
map: map,
draggable: true,
animation: google.maps.Animation.DROP,
position: myLatlng
});
// put map on page
map.setCenterAndZoom(home, 12);
google.maps.event.addListener(marker, 'click', toggleBounce);
}
// set marker at latitude/ longitude
var marker = new mxn.Marker(home);
function toggleBounce() {
// add marker InfoBubble() place name
hrp-infoInfoBubble('%s'); """ % self.page_title
jsc += """
// add marker to map
map.addMarker(marker, true);
if (marker.getAnimation() != null) {
marker.setAnimation(null);
} else {
marker.setAnimation(google.maps.Animation.BOUNCE);
}
}"""
# there is no need to add an ending "</script>",
# as it will be added automatically!
# googlev3 division
middle += Html("div", id = "googlev3", inline = True)
# add fullclear for proper styling
middle += fullclear
@ -4048,7 +4052,6 @@ class IndividualPage(BasePage):
XCoordinates, YCoordinates = [], []
number_markers = len(place_lat_long)
if number_markers > 3:
for (lat, long, pname, handle, date) in place_lat_long:
XCoordinates.append(lat)
@ -4092,8 +4095,8 @@ class IndividualPage(BasePage):
# if active
# call_(report, up, head)
# add Mapstraction CSS
fname = "/".join(["styles", "mapstraction.css"])
# add narrative-maps.css
fname = "/".join(["styles", "narrative-maps.css"])
url = self.report.build_url_fname(fname, None, self.up)
head += Html("link", href = url, type = "text/css", media = "screen", rel = "stylesheet")
@ -4156,7 +4159,7 @@ class IndividualPage(BasePage):
function initialize() {
// create map object
map = new mxn.Mapstraction('familygooglev3', 'googlev3');
map = new mxn.Mapstraction('map_canvas', 'googlev3');
// add map controls to image
map.addControls({
@ -4217,7 +4220,8 @@ class IndividualPage(BasePage):
# as it will be added automatically!
# here is where the map is held in the CSS/ Page
middlesection += Html("div", id = "familygooglev3", inline = True)
middlesection += Html("div", id ="map_canvas",
style ='width: 1600px; height: 1200px;', inline = True)
# add fullclear for proper styling
middlesection += fullclear
@ -5833,6 +5837,15 @@ class NavWebReport(Report):
Copy all of the CSS, image, and javascript files for Narrated Web
"""
# copy screen style sheet
if CSS[self.css]["filename"]:
fname = CSS[self.css]["filename"]
self.copy_file(fname, _NARRATIVESCREEN, "styles")
# copy printer style sheet
fname = CSS["Print-Default"]["filename"]
self.copy_file(fname, _NARRATIVEPRINT, "styles")
# copy behaviour style sheet
fname = CSS["behaviour"]["filename"]
self.copy_file(fname, "behaviour.css", "styles")
@ -5842,11 +5855,6 @@ class NavWebReport(Report):
fname = CSS["ancestortree"]["filename"]
self.copy_file(fname, "ancestortree.css", "styles")
# copy screen style sheet
if CSS[self.css]["filename"]:
fname = CSS[self.css]["filename"]
self.copy_file(fname, _NARRATIVESCREEN, "styles")
# copy Navigation Menu Layout style sheet if Blue or Visually is being used
if CSS[self.css]["navigation"]:
if self.navigation == "Horizontal":
@ -5857,17 +5865,13 @@ class NavWebReport(Report):
# copy Mapstraction style sheet if using Place Maps
if self.placemappages or self.familymappages:
fname = CSS["mapstraction"]["filename"]
self.copy_file(fname, "mapstraction.css", "styles")
fname = CSS["NarrativeMaps"]["filename"]
self.copy_file(fname, "narrative-maps.css", "styles")
for from_path in CSS["mapstraction"]["javascript"]:
for from_path in CSS["NarrativeMaps"]["javascript"]:
fdir, fname = os.path.split(from_path)
self.copy_file( from_path, fname, "mapstraction" )
# copy printer style sheet
fname = CSS["Print-Default"]["filename"]
self.copy_file(fname, _NARRATIVEPRINT, "styles")
imgs = []
# Copy the Creative Commons icon if the Creative Commons
@ -6707,13 +6711,23 @@ class NavWebOptions(MenuReportOptions):
category_name = _("Place Maps")
addopt = partial(menu.add_option, category_name)
placemappages = BooleanOption(_("Include Place map on Place Pages"), False)
placemappages.set_help(_("Whether to include a place map on the Place Pages, "
self.__placemappages = BooleanOption(_("Include Place map on Place Pages (GoogleMaps)"), False)
self.__placemappages.set_help(_("Whether to include a place map on the Place Pages, "
"where Latitude/ Longitude are available."))
addopt( "placemappages", placemappages )
self.__placemappages.connect("value-changed", self.__placemap_changed)
addopt("placemappages", self.__placemappages)
familymappages = BooleanOption(_("Include Individual Page Map with "
"all places shown on map"), False)
self.__openstreetmap = BooleanOption(_("Include Place map on Place Pages (Openstreetmaps)"), False)
self.__openstreetmap.set_help(_("Whether to include a place map on the Place Pages, "
"where Latitude/ Longitude are available."))
self.__openstreetmap.connect("value-changed", self.__osm_changed)
addopt("openstreetmap", self.__openstreetmap)
self.__placemap_changed()
self.__osm_changed()
familymappages = BooleanOption(_("Include Family Map Pages with "
"all places shown on the map"), False)
familymappages.set_help(_("Whether or not to add an individual page map "
"showing all the places on this page. "
"This will allow you to see how your family "
@ -6806,6 +6820,26 @@ class NavWebOptions(MenuReportOptions):
self.__down_fname2.set_available(False)
self.__dl_descr2.set_available(False)
def __placemap_changed(self):
"""
Handles the changing nature of the place maps
"""
if self.__placemappages.get_value():
self.__openstreetmap.set_available(False)
else:
self.__openstreetmap.set_available(True)
def __osm_changed(self):
"""
Handles the changing nature of OpenStreetMap
"""
if self.__openstreetmap.get_value():
self.__placemappages.set_available(False)
else:
self.__placemappages.set_available(True)
# FIXME. Why do we need our own sorting? Why not use Sort.Sort?
def sort_people(db, handle_list):
sname_sub = defaultdict(list)

View File

@ -5,7 +5,7 @@
DATAFILES = \
GeoView.css \
Mapstraction.css \
narrative-maps.css \
ancestortree.css \
behaviour.css \
Web_Basic-Ash.css \

View File

@ -19,7 +19,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id: $
# $Id$
#
#
Body element
@ -69,45 +69,3 @@ div#middlesection {
float: center;
overflow-y: hidden;
}
/* Y Map Sizes
------------------------------------------------- */
div#largeYMap {
width: 1400px;
margin: 1%;
}
div#middleYMap {
width: 1000px;
margin: 2%;
}
div#smallYMap {
width: 800px;
margin: 0px 8% 10px 9%;
}
div#YMap {
width: 800px;
margin: 0% 8% 10px 9%;
}
/* X Map Sizes
------------------------------------------------- */
div#largeXMap {
height: 1400px;
}
div#middleXMap {
height: 1200px;
}
div#smallXMap {
height: 800px;
}
div#XMap {
height: 800px;
}
/* Family GoogleV3
------------------------------------------------- */
div#familygooglev3 {
height: 100%;
width: 100%;
border: double 4px #000;
}

View File

@ -106,8 +106,8 @@ def load_on_reg(dbstate, uistate, plugin):
["behaviour", 0, "Behaviour",
path_css('behaviour.css'), None, [], []],
# mapstraction style sheet for NarrativeWeb place maps
["mapstraction", 0, "mapstraction",
# narrative-maps style sheet for NarrativeWeb place maps
["NarrativeMaps", 0, "",
path_css("Mapstraction.css"), None, [],
[path_js("mapstraction", "mxn.core.js"),
path_js("mapstraction", "mxn.googlev3.core.js"),