geography : added the possibility to show kml files.

This commit is contained in:
SNoiraud 2015-02-27 20:50:02 +01:00
parent deba8169bb
commit 09fa42dd94
3 changed files with 42 additions and 0 deletions

View File

@ -780,6 +780,25 @@ class GeoGraphyView(OsmGps, NavigationView):
mnam = _nd.display(mother) if mother else _("Unknown") mnam = _nd.display(mother) if mother else _("Unknown")
return ( fnam, mnam ) return ( fnam, mnam )
#-------------------------------------------------------------------------
#
# KML functionalities
#
#-------------------------------------------------------------------------
def load_kml_files(self, obj):
"""
obj can be an event, a person or a place
"""
media_list = obj.get_media_list()
if media_list:
for media_ref in media_list:
object_handle = media_ref.get_reference_handle()
media_obj = self.dbstate.db.get_object_from_handle(object_handle)
path = media_obj.get_path()
name, extension = os.path.splitext(path)
if extension == ".kml":
self.kml_layer.add_kml(path)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Printing functionalities # Printing functionalities

View File

@ -58,6 +58,7 @@ from .lifewaylayer import LifeWayLayer
from .markerlayer import MarkerLayer from .markerlayer import MarkerLayer
from .datelayer import DateLayer from .datelayer import DateLayer
from .messagelayer import MessageLayer from .messagelayer import MessageLayer
from .kmllayer import KmlLayer
from gramps.gen.const import GRAMPS_LOCALE as glocale from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.sgettext _ = glocale.translation.sgettext
from gramps.gen.config import config from gramps.gen.config import config
@ -90,6 +91,7 @@ class OsmGps():
self.marker_layer = None self.marker_layer = None
self.date_layer = None self.date_layer = None
self.message_layer = None self.message_layer = None
self.kml_layer = None
self.context_id = 0 self.context_id = 0
self.begin_selection = None self.begin_selection = None
self.end_selection = None self.end_selection = None
@ -149,6 +151,7 @@ class OsmGps():
self.osm.layer_add(current_map) self.osm.layer_add(current_map)
self.osm.layer_add(DummyLayer()) self.osm.layer_add(DummyLayer())
self.selection_layer = self.add_selection_layer() self.selection_layer = self.add_selection_layer()
self.kml_layer = self.add_kml_layer()
self.lifeway_layer = self.add_lifeway_layer() self.lifeway_layer = self.add_lifeway_layer()
self.marker_layer = self.add_marker_layer() self.marker_layer = self.add_marker_layer()
self.date_layer = self.add_date_layer() self.date_layer = self.add_date_layer()
@ -204,6 +207,20 @@ class OsmGps():
""" """
return self.selection_layer return self.selection_layer
def add_kml_layer(self):
"""
add the kml layer to the map
"""
kml_layer = KmlLayer()
self.osm.layer_add(kml_layer)
return kml_layer
def get_kml_layer(self):
"""
get the kml layer
"""
return self.kml_layer
def add_message_layer(self): def add_message_layer(self):
""" """
add the message layer to the map add the message layer to the map

View File

@ -302,15 +302,18 @@ class GeoPerson(GeoGraphyView):
latitude = "" latitude = ""
longitude = "" longitude = ""
self.message_layer.clear_messages() self.message_layer.clear_messages()
self.kml_layer.clear()
person_handle = self.uistate.get_active('Person') person_handle = self.uistate.get_active('Person')
person = dbstate.db.get_person_from_handle(person_handle) person = dbstate.db.get_person_from_handle(person_handle)
if person is not None: if person is not None:
# For each event, if we have a place, set a marker. # For each event, if we have a place, set a marker.
self.load_kml_files(person)
self.message_layer.add_message(_("Person places for %s") % _nd.display(person)) self.message_layer.add_message(_("Person places for %s") % _nd.display(person))
for event_ref in person.get_event_ref_list(): for event_ref in person.get_event_ref_list():
if not event_ref: if not event_ref:
continue continue
event = dbstate.db.get_event_from_handle(event_ref.ref) event = dbstate.db.get_event_from_handle(event_ref.ref)
self.load_kml_files(event)
role = event_ref.get_role() role = event_ref.get_role()
eyear = str("%04d" % event.get_date_object().to_calendar(self.cal).get_year()) + \ eyear = str("%04d" % event.get_date_object().to_calendar(self.cal).get_year()) + \
str("%02d" % event.get_date_object().to_calendar(self.cal).get_month()) + \ str("%02d" % event.get_date_object().to_calendar(self.cal).get_month()) + \
@ -328,6 +331,7 @@ class GeoPerson(GeoGraphyView):
descr1 = _("%(eventtype)s : %(name)s") % { descr1 = _("%(eventtype)s : %(name)s") % {
'eventtype': evt, 'eventtype': evt,
'name': _nd.display(person)} 'name': _nd.display(person)}
self.load_kml_files(place)
# place.get_longitude and place.get_latitude return # place.get_longitude and place.get_latitude return
# one string. We have coordinates when the two values # one string. We have coordinates when the two values
# contains non null string. # contains non null string.
@ -363,6 +367,7 @@ class GeoPerson(GeoGraphyView):
for event_ref in family.get_event_ref_list(): for event_ref in family.get_event_ref_list():
if event_ref: if event_ref:
event = dbstate.db.get_event_from_handle(event_ref.ref) event = dbstate.db.get_event_from_handle(event_ref.ref)
self.load_kml_files(event)
role = event_ref.get_role() role = event_ref.get_role()
if event.get_place_handle(): if event.get_place_handle():
place_handle = event.get_place_handle() place_handle = event.get_place_handle()
@ -378,6 +383,7 @@ class GeoPerson(GeoGraphyView):
eyear = str("%04d" % event.get_date_object().to_calendar(self.cal).get_year()) + \ eyear = str("%04d" % event.get_date_object().to_calendar(self.cal).get_year()) + \
str("%02d" % event.get_date_object().to_calendar(self.cal).get_month()) + \ str("%02d" % event.get_date_object().to_calendar(self.cal).get_month()) + \
str("%02d" % event.get_date_object().to_calendar(self.cal).get_day()) str("%02d" % event.get_date_object().to_calendar(self.cal).get_day())
self.load_kml_files(place)
if ( longitude and latitude ): if ( longitude and latitude ):
self._append_to_places_list(descr, self._append_to_places_list(descr,
evt, _nd.display(person), evt, _nd.display(person),