Refactoring of Place Page and Family Map Pages is should now be completed. Adjusted elements in Mapstraction style sheet.

svn: r15616
This commit is contained in:
Rob G. Healey 2010-07-05 06:26:23 +00:00
parent 24403802ac
commit 7ef7715f1c
2 changed files with 241 additions and 171 deletions

View File

@ -22,11 +22,18 @@
# $Id: $ # $Id: $
# #
# #
Maps Division section Body element
------------------------------------------------- */ ------------------------------------------------- */
div#maps { body#FamilyMap {
background-color: #FFF;
color: #000;
margin: 0 auto; margin: 0 auto;
padding: 0; width: 965px;
padding: 0px 14px 0px 14px;
}
body#FamilyMap a {
text-decoration: none;
color: #000;
} }
/* Mapstraction /* Mapstraction
@ -70,24 +77,21 @@ div#googlev3 {
Individual Family Map Individual Family Map
------------------------------------------------- */ ------------------------------------------------- */
div#familymap { div#familymap {
background-color: #FFF;
height: 1000px; height: 1000px;
width: 965px; width: 90%;
padding: 0% 14px 0% 14px; margin: 2% 5% 2% 5%;
} }
/* MiddleSection /* MiddleSection
------------------------------------------------- */ ------------------------------------------------- */
div#middlesection { div#middlesection {
float: center; float: center;
width: 90%;
margin: 1% 5% 1% 5%;
} }
/* Family GoogleV3 /* Family GoogleV3
------------------------------------------------- */ ------------------------------------------------- */
div#familygooglev3 { div#familygooglev3 {
height: 95%; height: 100%;
width: 95%; width: 100%;
border: solid 1px #000; border: double 2px #000;
} }

View File

@ -182,7 +182,7 @@ wrapper = TextWrapper()
wrapper.break_log_words = True wrapper.break_log_words = True
wrapper.width = 20 wrapper.width = 20
_individuallist = [] _individuallist = set()
_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)
@ -2350,11 +2350,17 @@ class PlaceListPage(BasePage):
Html("td", data or " ", class_ = "Column" + colclass, inline = True) Html("td", data or " ", class_ = "Column" + colclass, inline = True)
for (colclass, data) in [ for (colclass, data) in [
["State", ml.state], ["State", ml.state],
["Country", ml.country], ["Country", ml.country] ]
["Latitude", place.lat], )
["Longitude", place.long] ] if (place and (place.lat and place.long)):
) latitude, longitude = conv_lat_lon( place.lat,
place.long,
"DEG")
else:
latitude, longitude = False, False
trow += Html("td", latitude or " ", class_ = "ColumnLatitude", inline = True)
trow += Html("td", longitude or " ", class_ = "ColumnLongitude", inline = True)
# add clearline for proper styling # add clearline for proper styling
# add footer section # add footer section
footer = self.write_footer() footer = self.write_footer()
@ -2464,57 +2470,53 @@ class PlacePage(BasePage):
middle += jsc middle += jsc
jsc += """ jsc += """
//<![CDATA[ //<![CDATA[
var map; var map;
var latlon; var latlon;
function initialize() { function initialize() {
// create mxn object // create mxn object
map = new mxn.Mapstraction('googlev3','googlev3'); map = new mxn.Mapstraction('googlev3','googlev3');
// add map controls to image // add map controls to image
map.addControls({ map.addControls({
pan: true, pan: true,
zoom: 'small', zoom: 'large',
scale: true, scale: true,
map_type: true disableDoubleClickZoom: true,
}); keyboardShortcuts: true,
scrollwheel: false,
map_type: true
});
latlon = new mxn.LatLonPoint(%s, %s);""" % (latitude, longitude) latlon = new mxn.LatLonPoint(%s, %s);""" % (latitude, longitude)
jsc += """ jsc += """
// put map on page // put map on page
map.setCenterAndZoom(latlon, 7); map.setCenterAndZoom(latlon, 10);
var marker; var marker;
// set marker at latitude/ longitude // set marker at latitude/ longitude
marker = new mxn.Marker(latlon); marker = new mxn.Marker(latlon);
// add marker InfoBubble() using place description // add marker InfoBubble() using place name
marker.setInfoBubble('<div id = "geo-info" >%s</div>'); """ % self.page_title marker.setInfoBubble('<div id = "geo-info" >%s</div>'); """ % self.page_title
jsc += """ jsc += """
// add marker to map // add marker to map
map.addMarker(marker, true); map.addMarker(marker, true);
}
map.addEventListener('click', //]]>"""
function(p) { alert('Mapstraction Event Handling - Mouse clicked at ' + p) }); # there is no need to add an ending "</script>",
} # as it will be added automatically!
//]]>"""
# there is no need to add an ending "</script>",
# as it will be added automatically!
# googlev3 division # googlev3 division
middle += Html("div", id = "googlev3", inline = True) middle += Html("div", id = "googlev3", inline = True)
# add place title to middle section
middle += Html("div", self.page_title, id = "location", inline = True)
# add javascript function call to body element # add javascript function call to body element
body.attr = 'onload = "initialize();"' body.attr = 'onload = "initialize();"'
@ -3858,14 +3860,33 @@ class IndividualPage(BasePage):
@param: person_handle -- used for naming the map file as self.html_dir/maps/ ... @param: person_handle -- used for naming the map file as self.html_dir/maps/ ...
""" """
# fields in place_lat_long = latitude, longitude, place name, and handle
global place_lat_long global place_lat_long
# 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 place_lat_long by its coordinates and not place name # 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))
BoundMinX = place_lat_long[0][0]
BoundMaxX = place_lat_long[-1][0]
# sort on Y coordinates to get min and max Y GPS Coordinates
place_lat_long = sorted(place_lat_long, key = operator.itemgetter(1, 0))
BoundMinY = place_lat_long[0][1]
BoundMaxY = place_lat_long[-1][1]
# sort place_lat_long based on place_title for placement on map and references
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
if len(place_lat_long) <= 4:
x, y = place_lat_long[0][0], place_lat_long[0][1]
else:
x, y = place_lat_long[4][0], place_lat_long[4][1]
of = self.report.create_file(person_handle, "maps") of = self.report.create_file(person_handle, "maps")
self.up = True self.up = True
@ -3885,93 +3906,121 @@ 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("script", src = url, inline = True) head += Html("script", src = url, inline = True)
# begin maps division # begin familymap division
with Html("div", class_ = "content", id = "maps") as maps: with Html("div", id = "familymap") as familymap:
body += maps body += familymap
# begin familymap division # begin middle section division
with Html("div", id = "familymap") as familymap: with Html("div", id = "middlesection") as middlesection:
maps += familymap familymap += middlesection
# begin inline javascript code
# because jsc is a string, it does NOT have to properly indented
with Html("script", type = "text/javascript") as jsc:
middlesection += jsc
# begin middle division jsc += """
with Html("div", id = "middlesection") as middlesection: var map;
familymap += middlesection var latlon;
var latitude;
var longitude;
var num;
# begin inline javascript code function initialize() {
# because jsc is a string, it does NOT have to properly indented
with Html("script", type = "text/javascript") as jsc:
middlesection += jsc
jsc += """
var map;
var latlon;
var latitude;
var longitude;
var place_name;
var num;
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,
map_type: true disableDoubleClickZoom: true,
}); keyboardShortcuts: true,
scrollwheel: false,
map_type: true
});
latlon = new mxn.LatLonPoint(%s, %s);""" % ( // set center of map based on how many markers there are being created
place_lat_long[0][0], place_lat_long[0][1]) latlon = new mxn.LatLonPoint(%s, %s);""" % (x, y)
# set Zoom level based on number of markers
if len(place_lat_long) > 10:
jsc += """ jsc += """
// center map and set zoom // center map and set zoom
map.setCenterAndZoom(latlon, 4);""" map.setCenterAndZoom(latlon, 6);"""
index = 0
for (latitude, longitude, place_name) in place_lat_long:
j = index + 1
jsc += """
// %s""" % place_name
jsc += """
add_marker(%d, %s, %s);""" % (j, latitude, longitude)
index += 1
jsc += """
}
function add_marker(num, latitude, longitude) { else:
jsc += """
// center map and set zoom
map.setCenterAndZoom(latlon, 7);"""
var marker; index = 0
for (lat, long, place_name, handle) in place_lat_long:
j = index + 1
jsc += """
// %s
add_marker(%d, %s, %s);""" % (place_name, j, lat, long)
index += 1
jsc += """
}"""
// create marker if len(place_lat_long) > 4:
marker = new mxn.Marker(latlon); jsc += """
// boundary southWest equals bottom left GPS Coordinates
var southWest = new mxn.LatLonPoint(%s, %s);""" % (BoundMaxX, BoundMaxY)
jsc += """
// boundary northEast equals top right GPS Coordinates
var northEast = new mxn.LatLonPoint(%s, %s);""" % (BoundMinX, BoundMinY)
// add title to marker jsc += """
marker.setTitle(num.toString()); var bounds = new google.maps.LatLngBounds(southWest, northEast);
map.fitBounds(bounds);"""
// add marker to map jsc += """
map.addMarker(marker, true); function add_marker(num, latitude, longitude) {
}"""
# there is no need to add an ending "</script>",
# as it will be added automatically!
# familygooglev3 division var marker;
middlesection += Html("div", id = "familygooglev3", inline = True)
# add references division and title // create latitude/ longitude point for marker
with Html("div", class_ = "subsection", id = "References") as section: latlon = new mxn.LatLonPoint(latitude, longitude);
maps += section
section += Html("h4", _("References"), inline = True)
# begin ordered list // create marker
ordered = Html("ol") marker = new mxn.Marker(latlon);
section += ordered
for (latitude, longitude, place_name) in place_lat_long: // add number to individual markers
ordered += Html("li", place_name, inline = True) marker.setLabel(num.toString());
// add marker to map
map.addMarker(marker, true);
}"""
# there is no need to add an ending "</script>",
# as it will be added automatically!
# familygooglev3 division
middlesection += Html("div", id = "familygooglev3", inline = True)
# add fullclear for proper styling
middlesection += fullclear
# add references division and title
with Html("div", class_ = "subsection", id = "References") as section:
body += section
section += Html("h4", _("References"), inline = True)
# begin ordered list
ordered = Html("ol")
section += ordered
for (lat, long, name, handle) in place_lat_long:
ordered.extend(
Html("li", self.place_link(handle, name, up = True))
)
# add body onload to initialize map # add body onload to initialize map
body.attr = 'onload = "initialize();"' body.attr = 'onload = "initialize();" id = "FamilyMap"'
# add clearline for proper styling # add clearline for proper styling
# add footer section # add footer section
@ -3986,7 +4035,6 @@ class IndividualPage(BasePage):
""" """
create the family map link create the family map link
""" """
global place_lat_long
# create family map page # create family map page
self._create_family_map(person.handle) self._create_family_map(person.handle)
@ -4553,29 +4601,30 @@ class IndividualPage(BasePage):
else: else:
first = False first = False
# get father events and places if any? # get the father
father_handle = family.get_father_handle() father_handle = family.get_father_handle()
if father_handle: if father_handle:
_get_event_places(db, father_handle)
# get mother events and places if any? # get the father's event's places for family map
mother_handle = family.get_mother_handle() if self.family_map:
if mother_handle: father = db.get_person_from_handle(father_handle)
_get_event_places(db, mother_handle) _get_event_place(db, father)
# get child events and places of event if possible
# add to global variable if any
_get_event_places(db, child_ref_list)
father_handle = family.get_father_handle()
if father_handle:
trow = Html("tr") trow = Html("tr")
table += trow table += trow
tcell1, tcell2 = self.display_parent(father_handle, _("Father"), frel) tcell1, tcell2 = self.display_parent(father_handle, _("Father"), frel)
trow += (tcell1, tcell2) trow += (tcell1, tcell2)
# get the mother
mother_handle = family.get_mother_handle() mother_handle = family.get_mother_handle()
if mother_handle: if mother_handle:
# get the mother's event's places for family map
if self.family_map:
mother = db.get_person_from_handle(mother_handle)
_get_event_place(db, mother)
trow = Html("tr") trow = Html("tr")
table += trow table += trow
@ -4590,6 +4639,13 @@ class IndividualPage(BasePage):
# now that we have all siblings in families of the person, # now that we have all siblings in families of the person,
# display them... # display them...
if sibling: if sibling:
# get the siblings event's places for family map
if self.family_map:
for handle in sibling:
child = db.get_person_from_handle(handle)
_get_event_place(db, child)
trow = Html("tr") + ( trow = Html("tr") + (
Html("td", _("Siblings"), class_ = "ColumnAttribute", inline = True) Html("td", _("Siblings"), class_ = "ColumnAttribute", inline = True)
) )
@ -4603,17 +4659,28 @@ class IndividualPage(BasePage):
if birthorder: if birthorder:
kids = sorted(add_birthdate(db, sibling)) kids = sorted(add_birthdate(db, sibling))
ordered.extend( for birth_date, child_handle in kids:
self.display_child_link(child_handle) if child_handle != self.person.handle:
for birth_date, child_handle in kids ordered.extend(
if child_handle != self.person.handle) self.display_child_link(child_handle)
)
else:
child = db.get_person_from_handle(child_handle)
ordered.extend(
self.get_name(child)
)
else: else:
ordered.extend( for child_handle in sibling:
self.display_child_link(child_handle) if child_handle != self.perso.handle:
for child_handle in sibling ordered.extend(
if child_handle != self.person.handle) self.display_child_link(child_handle)
)
else:
child = db.get_person_from_handle(child_handle)
ordered.extend(
self.get_name(child)
)
# Also try to identify half-siblings # Also try to identify half-siblings
half_siblings = set() half_siblings = set()
@ -4778,14 +4845,12 @@ class IndividualPage(BasePage):
""" """
Displays a person's relationships ... Displays a person's relationships ...
""" """
global place_lat_long
family_list = self.person.get_family_handle_list() family_list = self.person.get_family_handle_list()
if not family_list: if not family_list:
return None return None
db = self.report.database db = self.report.database
global place_lat_long
# begin families division and section title # begin families division and section title
with Html("div", class_ = "subsection", id = "families") as section: with Html("div", class_ = "subsection", id = "families") as section:
@ -4808,10 +4873,6 @@ class IndividualPage(BasePage):
) )
table += trow table += trow
# get child events and places of event if possible
# add to global variable if any
_get_event_places(db, childlist)
tcell = Html("td", class_ = "ColumnValue") tcell = Html("td", class_ = "ColumnValue")
trow += tcell trow += tcell
@ -4820,6 +4881,12 @@ class IndividualPage(BasePage):
childlist = [child_ref.ref for child_ref in childlist] childlist = [child_ref.ref for child_ref in childlist]
# add individual's children events and places to family map
if self.family_map:
for child_handle in childlist:
child = db.get_person_from_handle(child_handle)
_get_event_place(db, child)
if self.report.options['birthorder']: if self.report.options['birthorder']:
kids = sorted(add_birthdate(db, childlist)) kids = sorted(add_birthdate(db, childlist))
@ -4864,9 +4931,6 @@ class IndividualPage(BasePage):
partner_handle = ReportUtils.find_spouse(self.person, family) partner_handle = ReportUtils.find_spouse(self.person, family)
if partner_handle: if partner_handle:
# get partner events and places if any?
_get_event_places(db, partner_handle)
partner = db.get_person_from_handle(partner_handle) partner = db.get_person_from_handle(partner_handle)
partner_name = self.get_name(partner) partner_name = self.get_name(partner)
else: else:
@ -5462,7 +5526,8 @@ class NavWebReport(Report):
# Build the person list # Build the person list
ind_list = self.build_person_list() ind_list = self.build_person_list()
_individuallist = ind_list for handle in ind_list:
_individuallist.add(handle)
# copy all of the neccessary files # copy all of the neccessary files
self.copy_narrated_files() self.copy_narrated_files()
@ -6836,23 +6901,27 @@ def build_event_data(db, ind_list):
# return event_handle_list and event types to its caller # return event_handle_list and event types to its caller
return event_handle_list, event_types return event_handle_list, event_types
def _get_event_places(db, person_list): def _get_event_place(db, person):
""" """
retrieve from a list of people their events, and places of event retrieve from a a person their events, and places for family map
@param:db -- report database @param: db -- report database
@param: person_list - list of handles @param: person - person object from the database
""" """
if not person:
return
for person_handle in person_list: global _individuallist
person = db.get_person_from_handle(person_handle) # find individual from within the report database
if person: found = any(handle == person.handle for handle in _individuallist)
if found:
event_ref_list = person.get_event_ref_list() event_ref_list = person.get_event_ref_list()
for event_ref in event_ref_list: for event_ref in event_ref_list:
event = db.get_event_from_handle(event_ref.ref) event = db.get_event_from_handle(event_ref.ref)
if event: if event:
place_handle = event.get_place_handle() place_handle = event.get_place_handle()
if place_handle:
place = db.get_place_from_handle(place_handle) place = db.get_place_from_handle(place_handle)
place_exists(db, place) place_exists(db, place)
@ -6863,17 +6932,14 @@ def place_exists(db, place):
place_title = ReportUtils.place_name(db, place.handle) place_title = ReportUtils.place_name(db, place.handle)
# if place is not already in the list, add it?
found = any(p[2] == place_title for p in place_lat_long) found = any(p[2] == place_title for p in place_lat_long)
if not found: if not found:
# if place has latitude and longitude, continue? # if place and it has latitude and longitude, continue?
if (place and (place.lat and place.long)): if (place and (place.lat and place.long)):
# get reallatitude and reallongitude from place object
latitude, longitude = conv_lat_lon( place.lat, latitude, longitude = conv_lat_lon( place.lat,
place.long, place.long,
"D.D8") "D.D8")
# add it to the list place_lat_long.append([latitude, longitude, place_title, place.handle])
place_lat_long.append([latitude, longitude, place_title])