kopia lustrzana https://github.com/hholzgra/ocitysmap
pass renderer to the indexer to allow indexer to render extra stuff
rodzic
f45d8f1822
commit
b8cf606f0a
|
|
@ -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])
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue