NarrativeWeb: Re-aligned the javascript code output to match how Google displays theirs.

svn: r15625
This commit is contained in:
Rob G. Healey 2010-07-08 07:22:34 +00:00
parent c31bd0bfa5
commit 0193bbb459

View File

@ -3868,15 +3868,14 @@ class IndividualPage(BasePage):
# if there is no latitude/ longitude data, then return # if there is no latitude/ longitude data, then return
if not place_lat_long: if not place_lat_long:
return return
db = self.report.database
# sort on X coordinates to get min and max X GPS Coordinates # sort on X coordinates to get min and max X GPS Coordinates
place_lat_long = sorted(place_lat_long, key = operator.itemgetter(0, 1)) place_lat_long = sorted(place_lat_long, key = operator.itemgetter(0, 1, 2, 3))
BoundMinX = place_lat_long[0][0] BoundMinX = place_lat_long[0][0]
BoundMaxX = place_lat_long[-1][0] BoundMaxX = place_lat_long[-1][0]
# sort on Y coordinates to get min and max Y GPS Coordinates # sort on Y coordinates to get min and max Y GPS Coordinates
place_lat_long = sorted(place_lat_long, key = operator.itemgetter(1, 0)) place_lat_long = sorted(place_lat_long, key = operator.itemgetter(1, 0, 2, 3))
BoundMinY = place_lat_long[0][1] BoundMinY = place_lat_long[0][1]
BoundMaxY = place_lat_long[-1][1] BoundMaxY = place_lat_long[-1][1]
@ -3884,10 +3883,12 @@ class IndividualPage(BasePage):
place_lat_long = sorted(place_lat_long, key = operator.itemgetter(2, 0, 1, 3)) place_lat_long = sorted(place_lat_long, key = operator.itemgetter(2, 0, 1, 3))
# set map center based on how many markers there will be created # set map center based on how many markers there will be created
if len(place_lat_long) <= 4: if len(place_lat_long) > 5:
x, y = place_lat_long[0][0], place_lat_long[0][1] center = int(len(place_lat_long) / 3)
else: else:
x, y = place_lat_long[4][0], place_lat_long[4][1] center = 0
centerX, centerY = place_lat_long[center][0], place_lat_long[center][1]
center_place_name = place_lat_long[center][2]
of = self.report.create_file(person_handle, "maps") of = self.report.create_file(person_handle, "maps")
self.up = True self.up = True
@ -3921,81 +3922,80 @@ class IndividualPage(BasePage):
middlesection += jsc middlesection += jsc
jsc += """ jsc += """
var map; var map;
var latlon; var latlon;
var latitude;
var longitude;
var num;
function initialize() { function initialize() {
// create map object // create map object
map = new mxn.Mapstraction('familygooglev3', 'googlev3'); map = new mxn.Mapstraction('familygooglev3', 'googlev3');
// add map controls to image // add map controls to image
map.addControls({ map.addControls({
pan: true, pan: true,
zoom: 'large', zoom: 'large',
scale: true, scale: true,
disableDoubleClickZoom: true, disableDoubleClickZoom: true,
keyboardShortcuts: true, keyboardShortcuts: true,
scrollwheel: false, scrollwheel: false,
map_type: true map_type: true
}); });
// set center of map based on how many markers there are being created // set center of map based on how many markers there are being created
latlon = new mxn.LatLonPoint(%s, %s);""" % (x, y) // Center place name: %s
latlon = new mxn.LatLonPoint(%s, %s);""" % ( center_place_name,
centerX, centerY )
# set Zoom level based on number of markers # set Zoom level based on number of markers
if len(place_lat_long) > 10: if len(place_lat_long) > 10:
jsc += """ jsc += """
// center map and set zoom // center map and set zoom
map.setCenterAndZoom(latlon, 6);""" map.setCenterAndZoom(latlon, 7);"""
else: else:
jsc += """ jsc += """
// center map and set zoom // center map and set zoom
map.setCenterAndZoom(latlon, 7);""" map.setCenterAndZoom(latlon, 9);"""
index = 0 index = 0
for (lat, long, place_name, handle) in place_lat_long: for (lat, long, placename, handle) in place_lat_long:
j = index + 1 j = index + 1
jsc += """ jsc += """
// %s // Place name: %s
add_marker(%d, %s, %s);""" % (place_name, j, lat, long) add_marker(%d, %s, %s);""" % ( placename,
j, lat, long )
index += 1 index += 1
jsc += """ jsc += """
}""" }"""
if len(place_lat_long) > 6:
if len(place_lat_long) > 4:
jsc += """ jsc += """
// boundary southWest equals bottom left GPS Coordinates // boundary southWest equals bottom left GPS Coordinates
var southWest = new mxn.LatLonPoint(%s, %s);""" % (BoundMaxX, BoundMaxY) var southWest = new mxn.LatLonPoint(%s, %s);""" % (BoundMaxX, BoundMaxY)
jsc += """ jsc += """
// boundary northEast equals top right GPS Coordinates // boundary northEast equals top right GPS Coordinates
var northEast = new mxn.LatLonPoint(%s, %s);""" % (BoundMinX, BoundMinY) var northEast = new mxn.LatLonPoint(%s, %s);""" % (BoundMinX, BoundMinY)
jsc += """ jsc += """
var bounds = new google.maps.LatLngBounds(southWest, northEast); var bounds = new google.maps.LatLngBounds(southWest, northEast);
map.fitBounds(bounds);""" map.fitBounds(bounds);"""
jsc += """ jsc += """
function add_marker(num, latitude, longitude) { function add_marker(num, latitude, longitude) {
var marker; var marker;
// create latitude/ longitude point for marker // create latitude/ longitude point for marker
latlon = new mxn.LatLonPoint(latitude, longitude); latlon = new mxn.LatLonPoint(latitude, longitude);
// create marker // create marker
marker = new mxn.Marker(latlon); marker = new mxn.Marker(latlon);
// add number to individual markers // add number to individual markers
marker.setLabel(num.toString()); marker.setLabel(num.toString());
// add marker to map // add marker to map
map.addMarker(marker, true); map.addMarker(marker, true);
}"""
}"""
# 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!