pass renderer to the indexer to allow indexer to render extra stuff

pull/81/head
Hartmut Holzgraefe 2022-09-19 21:52:15 +00:00
rodzic f45d8f1822
commit b8cf606f0a
9 zmienionych plików z 27 dodań i 56 usunięć

Wyświetl plik

@ -48,7 +48,7 @@ PAGE_NUMBER_MARGIN_PT = UTILS.convert_mm_to_pt(10)
class GeneralIndex:
def __init__(self, db, bounding_box, polygon_wkt, i18n, page_number=None):
def __init__(self, db, renderer, bounding_box, polygon_wkt, i18n, page_number=None):
"""
Prepare the index of the items inside the given WKT. This
constructor will perform all the SQL queries.
@ -57,6 +57,8 @@ class GeneralIndex:
----------
db : psycopg2 DB) handle
The GIS database
renderer: ocitysmap.Renderer
The renderer that called us
bounding_box : ocitysmap.BoundingBox
The bounding box of the map area
polygon_wkt : str
@ -66,6 +68,7 @@ class GeneralIndex:
page_number : int, optional
Page number to show when creating multi page index pages
"""
self._renderer = renderer
self._bounding_box = bounding_box
self._polygon_wkt = polygon_wkt
self._i18n = i18n
@ -245,8 +248,8 @@ SELECT %(columns)s,
s_endpoint1, s_endpoint2 = map(lambda s: s.split(),
linestring[11:-1].split(','))
except (ValueError, TypeError):
LOG.exception("Error parsing %s for %s/%s/%s"
% (repr(linestring), catname, db_amenity,
LOG.exception("Error parsing %s for %s"
% (repr(linestring),
repr(amenity_name)))
continue
endpoint1 = Point(s_endpoint1[1], s_endpoint1[0])

Wyświetl plik

@ -34,26 +34,12 @@ PAGE_NUMBER_MARGIN_PT = UTILS.convert_mm_to_pt(10)
# FIXME: make truely configurable
MAX_INDEX_CATEGORY_ITEMS = 300
class HealthIndexCategory(GeneralIndexCategory):
"""
The IndexCategory represents a set of index items that belong to the same
category, here e.g. having the same 'healthcare=...' value.
"""
def __init__(self, name, items=None, is_street=False):
GeneralIndexCategory.__init__(self, name, items, is_street)
class HealthIndexItem(GeneralIndexItem):
"""
"""
class HealthIndex(GeneralIndex):
name = "Health"
description = "Health related facilities"
def __init__(self, db, bbox, polygon_wkt, i18n, page_number=None):
GeneralIndex.__init__(self, db, bbox, polygon_wkt, i18n, page_number)
def __init__(self, db, renderer, bbox, polygon_wkt, i18n, page_number=None):
GeneralIndex.__init__(self, db, renderer, bbox, polygon_wkt, i18n, page_number)
# Build the contents of the index
self._categories = (self._list_amenities(db))

Wyświetl plik

@ -44,8 +44,8 @@ class NotesIndex(GeneralIndex):
name = "Notes"
description = "OSM Notes index"
def __init__(self, db, bounding_box, polygon_wkt, i18n, page_number=None):
GeneralIndex.__init__(self, db, bounding_box, polygon_wkt, i18n, page_number)
def __init__(self, db, renderer, bounding_box, polygon_wkt, i18n, page_number=None):
GeneralIndex.__init__(self, db, renderer, bounding_box, polygon_wkt, i18n, page_number)
# Build the contents of the index
self._categories = self._list_amenities(db)

Wyświetl plik

@ -57,19 +57,12 @@ class StreetIndexCategory(GeneralIndexCategory):
GeneralIndexCategory.__init__(self, name, items, is_street)
class StreetIndexItem(GeneralIndexItem):
"""
An IndexItem represents one item in the index (a street or a POI). It
contains the item label (street name, POI name or description) and the
humanized squares description.
"""
class StreetIndex(GeneralIndex):
name = "Street"
description = "Streets and selected amenities"
def __init__(self, db, bbox, polygon_wkt, i18n, page_number=None):
GeneralIndex.__init__(self, db, bbox, polygon_wkt, i18n, page_number)
def __init__(self, db, renderer, bbox, polygon_wkt, i18n, page_number=None):
GeneralIndex.__init__(self, db, renderer, bbox, polygon_wkt, i18n, page_number)
# Build the contents of the index
self._categories = \
@ -170,10 +163,10 @@ class StreetIndex(GeneralIndex):
raise
endpoint1 = ocitysmap.coords.Point(s_endpoint1[1], s_endpoint1[0])
endpoint2 = ocitysmap.coords.Point(s_endpoint2[1], s_endpoint2[0])
current_category.items.append(StreetIndexItem(street_name,
endpoint1,
endpoint2,
self._page_number))
current_category.items.append(GeneralIndexItem(street_name,
endpoint1,
endpoint2,
self._page_number))
return result

Wyświetl plik

@ -34,26 +34,12 @@ PAGE_NUMBER_MARGIN_PT = UTILS.convert_mm_to_pt(10)
# FIXME: make truely configurable
MAX_INDEX_CATEGORY_ITEMS = 300
class TreeIndexCategory(GeneralIndexCategory):
"""
The IndexCategory represents a set of index items that belong to the same
category, here e.g. having the same 'healthcare=...' value.
"""
def __init__(self, name, items=None, is_street=False):
GeneralIndexCategory.__init__(self, name, items, is_street)
class TreeIndexItem(GeneralIndexItem):
"""
"""
class TreeIndex(GeneralIndex):
name = "Tree"
description = "Tree genus / species index"
def __init__(self, db, bbox, polygon_wkt, i18n, page_number=None):
GeneralIndex.__init__(self, db, bbox, polygon_wkt, i18n, page_number)
def __init__(self, db, renderer, bbox, polygon_wkt, i18n, page_number=None):
GeneralIndex.__init__(self, renderer, db, bbox, polygon_wkt, i18n, page_number)
# Build the contents of the index
self._categories = (self._list_amenities(db))

Wyświetl plik

@ -34,9 +34,9 @@ if __name__ == '__main__':
from ocitysmap import i18n, coords
from ocitysmap.maplib.grid import Grid
from StreetIndex import StreetIndex, StreetIndexRenderer, StreetIndexCategory, StreetIndexItem
from HealthIndex import HealthIndex, HealthIndexCategiry, HealthIndexItem
from TreeIndex import TreeIndex, TreeIndexCategiry, TreeIndexItem
from StreetIndex import StreetIndex, StreetIndexRenderer, StreetIndexCategory
from HealthIndex import HealthIndex
from TreeIndex import TreeIndex
logging.basicConfig(level=logging.DEBUG)
random.seed(42)

Wyświetl plik

@ -177,8 +177,8 @@ if __name__ == "__main__":
fheight = ((font_metric.get_ascent() + font_metric.get_descent())
/ Pango.SCALE)
first_item = StreetIndexItem('First Item', None, None)
second_item = StreetIndexItem('Second Item', None, None)
first_item = GeneralIndexItem('First Item', None, None)
second_item = GeneralIndexItem('Second Item', None, None)
category = StreetIndexCategory('Hello world !', [first_item, second_item])
category.draw(False, ctx, pc, layout, fascent, fheight,

Wyświetl plik

@ -434,6 +434,7 @@ class MultiPageRenderer(Renderer):
LOG.warning("Indexer class '%s' not found" % self.rc.indexer)
else:
index = indexer_class(self.db,
self,
bb_inner,
inside_contour_wkt,
self.rc.i18n, page_number=(i + self._first_map_page_number))

Wyświetl plik

@ -118,9 +118,11 @@ class SinglePageRenderer(Renderer):
self.index_position = None
else:
self.street_index = indexer_class(db,
self,
rc.bounding_box,
rc.polygon_wkt,
rc.i18n)
rc.i18n,
)
if not self.street_index.categories:
LOG.warning("Designated area leads to an empty index")