Geography : libraries : performance issue with a lot of places

svn: r19849
This commit is contained in:
Serge Noiraud 2012-06-16 09:31:29 +00:00
parent a884943ece
commit 69f7381764
2 changed files with 27 additions and 6 deletions

View File

@ -53,6 +53,14 @@ import gtk
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import const import const
import cairo import cairo
#-------------------------------------------------------------------------
#
# set up logging
#
#-------------------------------------------------------------------------
import time
import logging
_LOG = logging.getLogger("GeoGraphy.markerlayer")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -121,34 +129,39 @@ class MarkerLayer(gobject.GObject, osmgpsmap.GpsMapLayer):
max_interval = 0.01 max_interval = 0.01
if min_interval == 0: # This to avoid divide by zero if min_interval == 0: # This to avoid divide by zero
min_interval = 0.01 min_interval = 0.01
_LOG.debug("%s" % time.strftime("start drawing : "
"%a %d %b %Y %H:%M:%S", time.gmtime()))
for marker in self.markers: for marker in self.markers:
ctx.save() ctx.save()
# the icon size in 48, so the standard icon size is 0.6 * 48 = 28.8 # the icon size in 48, so the standard icon size is 0.6 * 48 = 28.8
size = 0.6 size = 0.6
if float(marker[2]) > self.nb_ref_by_places: mark = float(marker[2])
if mark > self.nb_ref_by_places:
# at maximum, we'll have an icon size = (0.6 + 0.3) * 48 = 43.2 # at maximum, we'll have an icon size = (0.6 + 0.3) * 48 = 43.2
size += (0.3 * ((float(marker[2]) - self.nb_ref_by_places) size += (0.3 * ((mark - self.nb_ref_by_places)
/ max_interval) ) / max_interval) )
else: else:
# at minimum, we'll have an icon size = (0.6 - 0.3) * 48 = 14.4 # at minimum, we'll have an icon size = (0.6 - 0.3) * 48 = 14.4
size -= (0.3 * ((self.nb_ref_by_places - float(marker[2])) size -= (0.3 * ((self.nb_ref_by_places - mark)
/ min_interval) ) / min_interval) )
conv_pt = osmgpsmap.point_new_degrees(float(marker[0][0]), conv_pt = osmgpsmap.point_new_degrees(float(marker[0][0]),
float(marker[0][1])) float(marker[0][1]))
coord_x, coord_y = gpsmap.convert_geographic_to_screen(conv_pt) coord_x, coord_y = gpsmap.convert_geographic_to_screen(conv_pt)
ctx.translate(coord_x, coord_y) ctx.translate(coord_x, coord_y)
size = float(int(size * 10)/10.0)
ctx.scale( size, size) ctx.scale( size, size)
# below, we try to place exactly the marker depending on its size. # below, we try to place exactly the marker depending on its size.
# Normaly, the left top corner of the image is set to the coordinates. # Normaly, the left top corner of the image is set to the coordinates.
# The tip of the pin which should be at the marker position is at # The tip of the pin which should be at the marker position is at
# 3/18 of the width. So we shift the image position. # 3/18 of the width and to the height of the image.
# So we shift the image position.
posY = - int( 48 * size + 0.5 ) - 10 posY = - int( 48 * size + 0.5 ) - 10
posX = - int(( 48 * size ) / 6 + 0.5 ) - 8 posX = - int(( 48 * size ) / 6 + 0.5 ) - 10
ctx.set_source_pixbuf(marker[1], posX, posY) ctx.set_source_pixbuf(marker[1], posX, posY)
ctx.paint() ctx.paint()
ctx.restore() ctx.restore()
_LOG.debug("%s" % time.strftime("end drawing : "
"%a %d %b %Y %H:%M:%S", time.gmtime()))
def do_render(self, gpsmap): def do_render(self, gpsmap):
""" """

View File

@ -35,6 +35,7 @@ import gobject
# Set up logging # Set up logging
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
import time
import logging import logging
_LOG = logging.getLogger("maps.osmgps") _LOG = logging.getLogger("maps.osmgps")
@ -311,9 +312,14 @@ class OsmGps():
def is_there_a_place_here(self, lat, lon): def is_there_a_place_here(self, lat, lon):
""" """
Is there a place at this position ? Is there a place at this position ?
If too many places, this function is very time consuming
""" """
mark_selected = [] mark_selected = []
if self.no_show_places_in_status_bar:
return mark_selected
oldplace = "" oldplace = ""
_LOG.debug("%s" % time.strftime("start is_there_a_place_here : "
"%a %d %b %Y %H:%M:%S", time.gmtime()))
for mark in self.places_found: for mark in self.places_found:
# as we are not precise with our hand, reduce the precision # as we are not precise with our hand, reduce the precision
# depending on the zoom. # depending on the zoom.
@ -348,6 +354,8 @@ class OsmGps():
lonok = True lonok = True
if latok and lonok: if latok and lonok:
mark_selected.append(mark) mark_selected.append(mark)
_LOG.debug("%s" % time.strftime(" end is_there_a_place_here : "
"%a %d %b %Y %H:%M:%S", time.gmtime()))
return mark_selected return mark_selected
def build_nav_menu(self, osm, event, lat, lon): def build_nav_menu(self, osm, event, lat, lon):