maposmatic-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Maposmatic-dev] [PATCH 17/22] index for multi-page: improve page_number


From: Thomas Petazzoni
Subject: [Maposmatic-dev] [PATCH 17/22] index for multi-page: improve page_number handling
Date: Fri, 30 Mar 2012 13:00:34 +0200

The page_number is now directly given to the StreetIndex constructor,
which in turn ensures that each IndexItem it creates have it.

Signed-off-by: Thomas Petazzoni <address@hidden>
---
 ocitysmap2/indexlib/commons.py              |    4 ++--
 ocitysmap2/indexlib/indexer.py              |   12 ++++++++----
 ocitysmap2/layoutlib/multi_page_renderer.py |    5 +----
 3 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/ocitysmap2/indexlib/commons.py b/ocitysmap2/indexlib/commons.py
index 2bdd4a8..8143ebc 100644
--- a/ocitysmap2/indexlib/commons.py
+++ b/ocitysmap2/indexlib/commons.py
@@ -106,13 +106,13 @@ class IndexItem:
     location_str = None # str or None
     page_number  = None # integer or None. Only used by multi-page renderer.
 
-    def __init__(self, label, endpoint1, endpoint2):
+    def __init__(self, label, endpoint1, endpoint2, page_number=None):
         assert label is not None
         self.label        = label
         self.endpoint1    = endpoint1
         self.endpoint2    = endpoint2
         self.location_str = None
-        self.page_number  = None
+        self.page_number  = page_number
 
     def __str__(self):
         return '%s...%s' % (self.label, self.location_str)
diff --git a/ocitysmap2/indexlib/indexer.py b/ocitysmap2/indexlib/indexer.py
index 663ca52..0c17173 100644
--- a/ocitysmap2/indexlib/indexer.py
+++ b/ocitysmap2/indexlib/indexer.py
@@ -45,7 +45,7 @@ l = logging.getLogger('ocitysmap')
 
 class StreetIndex:
 
-    def __init__(self, db, polygon_wkt, i18n):
+    def __init__(self, db, polygon_wkt, i18n, page_number=None):
         """
         Prepare the index of the streets inside the given WKT. This
         constructor will perform all the SQL queries.
@@ -58,6 +58,7 @@ class StreetIndex:
         Note: All the arguments have to be provided !
         """
         self._i18n = i18n
+        self._page_number = page_number
 
         # Build the contents of the index
         self._categories = \
@@ -228,7 +229,8 @@ class StreetIndex:
             endpoint2 = coords.Point(s_endpoint2[1], s_endpoint2[0])
             current_category.items.append(commons.IndexItem(street_name,
                                                             endpoint1,
-                                                            endpoint2))
+                                                            endpoint2,
+                                                            self._page_number))
 
         return result
 
@@ -348,7 +350,8 @@ order by amenity_name""" \
                 endpoint2 = coords.Point(s_endpoint2[1], s_endpoint2[0])
                 current_category.items.append(commons.IndexItem(amenity_name,
                                                                 endpoint1,
-                                                                endpoint2))
+                                                                endpoint2,
+                                                                
self._page_number))
 
             l.debug("Got %d amenities for %s/%s."
                     % (len(current_category.items), catname, db_amenity))
@@ -414,7 +417,8 @@ order by village_name""" \
             endpoint2 = coords.Point(s_endpoint2[1], s_endpoint2[0])
             current_category.items.append(commons.IndexItem(village_name,
                                                             endpoint1,
-                                                            endpoint2))
+                                                            endpoint2,
+                                                            self._page_number))
 
         l.debug("Got %d villages for %s."
                 % (len(current_category.items), 'Villages'))
diff --git a/ocitysmap2/layoutlib/multi_page_renderer.py 
b/ocitysmap2/layoutlib/multi_page_renderer.py
index 1748ac6..df6cef6 100644
--- a/ocitysmap2/layoutlib/multi_page_renderer.py
+++ b/ocitysmap2/layoutlib/multi_page_renderer.py
@@ -218,7 +218,7 @@ class MultiPageRenderer(Renderer):
             # Create the index for the current page
             index = StreetIndex(self.db,
                                 bb_inner.as_wkt(),
-                                self.rc.i18n)
+                                self.rc.i18n, page_number=(i + 1))
 
             index.apply_grid(map_grid)
             indexes.append(index)
@@ -236,9 +236,6 @@ class MultiPageRenderer(Renderer):
         all_categories_others  = []
         for page_number, idx in enumerate(indexes):
             for cat in idx.categories:
-                # Mark each IndexItem with its page number
-                for item in cat.items:
-                    item.page_number = (page_number + 1)
                 # Split in two lists depending on the category type
                 # (street or other)
                 if cat.is_street:
-- 
1.7.4.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]