diff --git a/src/DataViews/GeoView.py b/src/DataViews/GeoView.py
index d6694c35b..c9c5d7a3f 100644
--- a/src/DataViews/GeoView.py
+++ b/src/DataViews/GeoView.py
@@ -38,6 +38,7 @@ import const
import gobject
import threading
import time
+import operator
#-------------------------------------------------------------------------
#
@@ -52,8 +53,6 @@ import gtk
#
#-------------------------------------------------------------------------
import logging
-LOG = logging.getLogger(".GeoView")
-#LOG.setLevel(logging.DEBUG)
#-------------------------------------------------------------------------
#
@@ -81,7 +80,6 @@ MOZIL = 2
WebKit = NOWEB
try:
import webkit
- LOG.info("Using Webkit for HtmlView")
WebKit = WEBKIT
except:
pass
@@ -89,7 +87,6 @@ except:
if WebKit == NOWEB:
try:
import gtkmozembed
- LOG.info("Using GtkMozembed for HtmlView")
WebKit = MOZIL
except:
pass
@@ -97,7 +94,6 @@ if WebKit == NOWEB:
#no interfaces present, raise Error so that options for GeoView do not show
if WebKit == NOWEB :
Config.set(Config.GEOVIEW, False)
- LOG.warning(_("GeoView not enabled, no html plugin for GTK found."))
raise ImportError, 'No GTK html plugin found'
#-------------------------------------------------------------------------
@@ -117,6 +113,7 @@ if WebKit == NOWEB :
MOZEMBED_PATH = TEMP_DIR
MOZEMBED_SUBPATH = Utils.get_empty_tempdir('mozembed_gramps')
GEOVIEW_SUBPATH = Utils.get_empty_tempdir('geoview')
+NB_MARKERS_PER_PAGE = 200
#-------------------------------------------------------------------------
#
@@ -421,30 +418,16 @@ class GeoView(HtmlView):
self.displaytype = "person"
self.external_url = False
self.need_to_resize = False
+ self.nbmarkers = 0
+ self.nbpages = 0
- # Create temporary files
- # for people
- (handle,self.htmlfileI) = tempfile.mkstemp(".html","GeoV-I-",
- GEOVIEW_SUBPATH)
- self.htmlfile=self.htmlfileI
- # for family
- (handle,self.htmlfileF) = tempfile.mkstemp(".html","GeoV-F-",
- GEOVIEW_SUBPATH)
- # for place
- (handle,self.htmlfileP) = tempfile.mkstemp(".html","GeoV-P-",
- GEOVIEW_SUBPATH)
- # for event
- (handle,self.htmlfileE) = tempfile.mkstemp(".html","GeoV-E-",
- GEOVIEW_SUBPATH)
+ self.htmlfile=self.create_start_page()
def on_delete(self):
"""
- We need to suppress the html temporary file.
+ We need to suppress temporary files here.
"""
- try:
- os.remove(self.htmlfile)
- except:
- pass
+ pass
def init_parent_signals_for_map(self, widget, event):
# required to properly bootstrap the signal handlers.
@@ -482,8 +465,8 @@ class GeoView(HtmlView):
"""
return 'gramps-geo'
- def change_map(self):
- self.renderer.execute_script("javascript:mapstraction.swap(map,'"+self.usedmap+"')");
+ def change_map(self,usedmap):
+ self.renderer.execute_script("javascript:mapstraction.swap(map,'"+usedmap+"')");
def refresh(self,button):
self.renderer.refresh();
@@ -630,81 +613,59 @@ class GeoView(HtmlView):
HtmlView.define_actions(self)
def goto_active_person(self,handle=None):
- self.geo_places(self.htmlfile,self.displaytype)
+ self.geo_places(self.displaytype)
def all_places(self,handle=None):
"""
Specifies the place for the home person to display with mapstraction.
"""
self.displaytype = "places"
- self.htmlfile=self.htmlfileP
- self.geo_places(self.htmlfile,self.displaytype)
+ self.geo_places(self.displaytype)
def person_places(self,handle=None):
"""
Specifies the person places.
"""
self.displaytype = "person"
- self.htmlfile=self.htmlfileI
- self.geo_places(self.htmlfile,self.displaytype)
+ self.geo_places(self.displaytype)
def family_places(self,handle=None):
"""
Specifies the family places to display with mapstraction.
"""
self.displaytype = "family"
- self.htmlfile=self.htmlfileF
- self.geo_places(self.htmlfile,self.displaytype)
+ self.geo_places(self.displaytype)
def event_places(self,handle=None):
"""
Specifies all event places to display with mapstraction.
"""
self.displaytype = "event"
- self.htmlfile=self.htmlfileE
- self.geo_places(self.htmlfile,self.displaytype)
+ self.geo_places(self.displaytype)
- def geo_places(self,htmlfile,displaytype):
+ def geo_places(self,displaytype):
"""
Specifies the places to display with mapstraction.
"""
self.external_url = False
- if htmlfile == None:
- htmlfile = MOZEMBED_PATH+"help.html"
- self.createHelp(htmlfile)
- else:
- self.createMapstraction(htmlfile,displaytype)
- self.open("file://"+htmlfile)
+ self.nbmarkers = 0
+ self.createMapstraction(displaytype)
+ self.open("file://"+self.htmlfile)
def select_OpenStreetMap_map(self,handle=None):
- self.usedmap = "openstreetmap"
- LOG.debug("geo_places : call %s page from select_OpenStreetMap_map\n"
- % self.usedmap)
- self.change_map()
+ self.change_map("openstreetmap")
def select_openlayers_map(self,handle=None):
- self.usedmap = "openlayers"
- LOG.debug("geo_places : call %s page from select_openlayers_map\n"
- % self.usedmap)
- self.change_map()
+ self.change_map("openlayers")
def select_google_map(self,handle=None):
- self.usedmap = "google"
- LOG.debug("geo_places : call %s page from select_google_map\n"
- % self.usedmap)
- self.change_map()
+ self.change_map("google")
def select_yahoo_map(self,handle=None):
- self.usedmap = "yahoo"
- LOG.debug("geo_places : call %s page from select_yahoo_map\n"
- % self.usedmap)
- self.change_map()
+ self.change_map("yahoo")
def select_microsoft_map(self,handle=None):
- self.usedmap = "microsoft"
- LOG.debug("geo_places : call %s page from select_microsoft_map\n"
- % self.usedmap)
- self.change_map()
+ self.change_map("microsoft")
def set_mozembed_proxy(self):
"""
@@ -753,7 +714,7 @@ class GeoView(HtmlView):
pass
pass # We don't use a proxy or the http_proxy variable is not set.
- def createMapstractionPostHeader(self):
+ def createMapstractionPostHeader(self,h3mess,h4mess,maxpages,curpage,ftype):
self.maxgen=Config.get(Config.GENERATION_DEPTH)
if self.maxyear == 0:
self.maxyear=2100
@@ -771,14 +732,33 @@ class GeoView(HtmlView):
self.yearint=( self.yearint - ( self.yearint % modulo ) )
if self.yearint == 0:
self.yearint=10
- LOG.debug("period = %d, intvl = %d, interval = %d" % (period,
- intvl, self.yearint))
self.mapview.write(" var step = %s;\n" % self.yearint)
self.mapview.write(" \n")
self.mapview.write(" \n")
self.mapview.write("
\n")
+ if maxpages > 1:
+ message = _("We have %d markers, so I split this document in %d pages of %d markers : " % (self.nbmarkers, maxpages, NB_MARKERS_PER_PAGE))
+ self.mapview.write(" %s
\n" % message)
+ if curpage != 1:
+ priorfile=GEOVIEW_SUBPATH+"/GeoV-%c-%05d.html" % (ftype,curpage-1)
+ self.mapview.write("
--" % priorfile)
+ else:
+ self.mapview.write(" --")
+ for page in range(1,maxpages+1,1):
+ if page == curpage:
+ self.mapview.write(" %d" % page)
+ else:
+ if ( page < curpage + 10 ) and ( page > curpage - 10 ):
+ nextfile=GEOVIEW_SUBPATH+"/GeoV-%c-%05d.html" % (ftype,page)
+ self.mapview.write("
%d" % (nextfile, page))
+ if curpage != maxpages:
+ nextfile=GEOVIEW_SUBPATH+"/GeoV-%c-%05d.html" % (ftype,curpage+1)
+ self.mapview.write("
++" % nextfile)
+ else:
+ self.mapview.write(" ++")
+ self.mapview.write("\n
\n")
if self.displaytype != "places":
- self.mapview.write(" \n")
+ self.mapview.write("
\n")
self.mapview.write("
\n")
+ self.mapview.write("
%s
" % h3mess)
+ if h4mess:
+ self.mapview.write("
%s
" % h4mess)
- def createMapstractionHeader(self):
- self.mapview = open(self.htmlfile,"w+")
+ def createMapstractionHeader(self,filename):
+ self.mapview = open(filename,"w+")
self.mapview.write("\n")
self.mapview.write("\n")
@@ -848,77 +831,28 @@ class GeoView(HtmlView):
self.mapview.write(" }\n")
self.mapview.write(" }\n")
- def createMapstractionTrailer(self,filename):
+ def createMapstractionTrailer(self):
self.mapview.write(" \n")
self.mapview.write("\n")
self.mapview.close()
- def createMapstraction(self,filename,displaytype):
- self.createMapstractionHeader()
- if displaytype == "places":
- self.createMapstractionPlaces(self.dbstate)
- elif displaytype == "family":
- self.createMapstractionFamily(self.dbstate)
- elif displaytype == "person":
- self.createMapstractionPerson(self.dbstate)
- elif displaytype == "event":
- self.createMapstractionEvents(self.dbstate)
- else:
- self.createMapstractionNotImplemented(self.dbstate)
- self.createMapstractionTrailer(filename)
-
- def append_to_places_list(self, Place, evttype, name, lat, long, descr, center, year):
- self.place_list.append([Place, name, evttype, lat, long, descr, int(center), year])
-
- a = float(lat)
- b = float(long)
- if not year == None:
- c = int(year)
- if c != 0:
- if c < self.minyear:
- self.minyear = c
- if c > self.maxyear:
- self.maxyear = c
-
- if self.minlat == 0.0:
- self.minlat = a
- if a < self.minlat:
- self.minlat = a
- if self.maxlat == 0.0:
- self.maxlat = a
- if a > self.maxlat:
- self.maxlat = a
-
- if self.minlon == 0.0:
- self.minlon = b
- if b < self.minlon:
- self.minlon = b
- if self.maxlon == 0.0:
- self.maxlon = b
- if b > self.maxlon:
- self.maxlon = b
-
- def isyearnotinmarker(self,allyears,year):
- ret = 1
- for y in allyears:
- if year == y:
- ret = 0
- return ret
-
- def create_markers(self,format):
+ def create_pages(self,type,h3mess,h4mess):
+ nbmarkers = 0
+ self.nbpages = 0
+ pages = ( self.nbmarkers / NB_MARKERS_PER_PAGE ) + 1
+ if (nbmarkers % NB_MARKERS_PER_PAGE) == 0:
+ try:
+ self.createMapstractionTrailer()
+ except:
+ pass
+ # Select the center of the map and the zoom
self.centered = 0
- margin = 10
- self.mapview.write("
\n" %
- ( ( self.width - margin*4 ), ( self.height * 0.74 )))
- self.mapview.write(" \n")
+ self.setattr = False
+ self.mapview.write("\n \n")
+
def createPersonMarkers(self,db,person,comment):
"""
@@ -1164,7 +1164,6 @@ class GeoView(HtmlView):
birth = db.db.get_event_from_handle(birth_ref.ref)
birthdate = birth.get_date_object()
birthyear = birthdate.get_year()
- LOG.debug("birth year = %s" % birthyear)
bplace_handle = birth.get_place_handle()
if bplace_handle:
place = db.db.get_place_from_handle(bplace_handle)
@@ -1190,7 +1189,6 @@ class GeoView(HtmlView):
death = db.db.get_event_from_handle(death_ref.ref)
deathdate = death.get_date_object()
deathyear = deathdate.get_year()
- LOG.debug("death year = %s" % deathyear)
dplace_handle = death.get_place_handle()
if dplace_handle:
place = db.db.get_place_from_handle(dplace_handle)
@@ -1240,11 +1238,11 @@ class GeoView(HtmlView):
latitude, longitude,
descr1, self.center, None)
self.center = 0
- self.createMapstractionPostHeader()
- self.mapview.write("
%s
"%_("All places in the database with coordinates."))
if self.center == 1:
- self.mapview.write("
%s
"%_("Cannot center the map. No selected location."))
- self.create_markers(1)
+ mess = _("Cannot center the map. No selected location.")
+ else:
+ mess = ""
+ self.create_pages(1,_("All places in the database with coordinates."),mess)
def createMapstractionEvents(self,db):
"""
@@ -1294,11 +1292,11 @@ class GeoView(HtmlView):
latitude, longitude,
descr2, self.center, eventyear)
self.center = 0
- self.createMapstractionPostHeader()
- self.mapview.write("
%s
"%_("All events in the database with coordinates."))
if self.center == 1:
- self.mapview.write("
%s
"%_("Cannot center the map. No selected location."))
- self.create_markers(2)
+ mess = _("Cannot center the map. No selected location.")
+ else:
+ mess = ""
+ self.create_pages(2,_("All events in the database with coordinates."),mess)
def createMapstractionFamily(self,db):
"""
@@ -1340,11 +1338,14 @@ class GeoView(HtmlView):
comment = "Id : %s : %s %d"%(child.gramps_id,
_("Child"),index)
self.createPersonMarkers(db,child,comment)
- self.createMapstractionPostHeader()
- self.mapview.write("
%s
"%_("All %s people's family places in the database with coordinates.") % _nd.display(person))
if self.center == 1:
- self.mapview.write("
%s
"%_("Cannot center the map. No selected location."))
- self.create_markers(3)
+ mess = _("Cannot center the map. No selected location.")
+ else:
+ mess = ""
+ self.create_pages(3,
+ ( _("All %s people's familiy places in the database with coordinates.") %
+ _nd.display(person) ),
+ mess)
def createMapstractionPerson(self,db):
"""
@@ -1366,7 +1367,6 @@ class GeoView(HtmlView):
self.center = 1
if person:
# For each event, if we have a place, set a marker.
- LOG.debug("event for %s" % person.gramps_id)
for event_ref in person.get_event_ref_list():
if not event_ref:
continue
@@ -1376,7 +1376,6 @@ class GeoView(HtmlView):
event = db.db.get_event_from_handle(event_ref.ref)
eventdate = event.get_date_object()
eventyear = eventdate.get_year()
- LOG.debug("event year = %s" % eventyear)
place_handle = event.get_place_handle()
if place_handle:
place = db.db.get_place_from_handle(place_handle)
@@ -1394,43 +1393,15 @@ class GeoView(HtmlView):
latitude, longitude,
descr1, self.center, eventyear)
self.center = 0
- self.createMapstractionPostHeader()
- self.mapview.write("
%s
"%_("All event places for %s.") % _nd.display(person))
if self.center == 1:
- self.mapview.write("
%s
"%_("Cannot center the map. No selected location."))
- self.create_markers(4)
+ mess = _("Cannot center the map. No selected location.")
+ else:
+ mess = ""
+ self.create_pages(4,( _("All event places for %s.") % _nd.display(person) ) ,mess)
def createMapstractionNotImplemented(self,db):
"""
This function is used to inform the user this work is not implemented.
"""
- LOG.warning('createMapstractionNotImplemented')
self.mapview.write("
%s ...
"%_("Not yet implemented"))
- def createHelp(self,filename):
- help = open(self.htmlfile,"w")
- help.write("\n")
- help.write("\n")
- help.write(" \n")
- help.write("
\n")
- help.write("
Geo Maps JavaScript API for Gramps\n")
- help.write(" \n")
- help.write(" \n")
- help.write("
\n" % 600)
- help.write("
\n")
- help.write("
")
- help.write(_("You can choose between two maps. One free and a second one."))
- help.write("
")
- help.write(_("The best choice is the free map like openstreetmap."))
- help.write("
")
- help.write(_("You should use the second map only if the first one give no results ..."))
- help.write("
")
- help.write(_("You can select Edit/Preferences to choose the second map provider."))
- help.write("
")
- help.write(_("They are : Googlemaps, Yahoo! maps, Microsoft maps and Openlayers."))
- help.write("
")
- help.write(" \n")
- help.write(" \n")
- help.write("\n")
- help.close()