give grid cells for spaces and areas as well
This commit is contained in:
parent
f861fecee5
commit
0ef08ad61b
3 changed files with 34 additions and 0 deletions
|
@ -11,6 +11,10 @@ class AbstractGrid(ABC):
|
||||||
def get_cell_for_point(self, x, y) -> Optional[str]:
|
def get_cell_for_point(self, x, y) -> Optional[str]:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def get_cells_for_bounds(self, bounds) -> Optional[str]:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Grid(AbstractGrid):
|
class Grid(AbstractGrid):
|
||||||
def __init__(self, rows, cols):
|
def __init__(self, rows, cols):
|
||||||
|
@ -49,11 +53,32 @@ class Grid(AbstractGrid):
|
||||||
|
|
||||||
return '%s%d' % (string.ascii_uppercase[x-1], y)
|
return '%s%d' % (string.ascii_uppercase[x-1], y)
|
||||||
|
|
||||||
|
def get_cells_for_bounds(self, bounds):
|
||||||
|
minx, miny, maxx, maxy = bounds
|
||||||
|
|
||||||
|
if self.invert_x:
|
||||||
|
minx, maxx = maxx, minx
|
||||||
|
if self.invert_y:
|
||||||
|
miny, maxy = maxy, miny
|
||||||
|
|
||||||
|
min_cell = self.get_cell_for_point(minx, miny)
|
||||||
|
max_cell = self.get_cell_for_point(maxx, maxy)
|
||||||
|
|
||||||
|
if not min_cell or not max_cell:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if min_cell == max_cell:
|
||||||
|
return min_cell
|
||||||
|
return '%s-%s' % (min_cell, max_cell)
|
||||||
|
|
||||||
|
|
||||||
class DummyGrid(AbstractGrid):
|
class DummyGrid(AbstractGrid):
|
||||||
def get_cell_for_point(self, x, y):
|
def get_cell_for_point(self, x, y):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def get_cells_for_bounds(self, bounds):
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
if settings.GRID_COLS and settings.GRID_ROWS:
|
if settings.GRID_COLS and settings.GRID_ROWS:
|
||||||
grid = Grid(settings.GRID_ROWS.split(','), settings.GRID_COLS.split(','))
|
grid = Grid(settings.GRID_ROWS.split(','), settings.GRID_COLS.split(','))
|
||||||
|
|
|
@ -17,6 +17,7 @@ from shapely.geometry.polygon import orient
|
||||||
from shapely.ops import unary_union
|
from shapely.ops import unary_union
|
||||||
|
|
||||||
from c3nav.mapdata.fields import GeometryField, I18nField
|
from c3nav.mapdata.fields import GeometryField, I18nField
|
||||||
|
from c3nav.mapdata.grid import grid
|
||||||
from c3nav.mapdata.models import Level
|
from c3nav.mapdata.models import Level
|
||||||
from c3nav.mapdata.models.access import AccessRestrictionMixin
|
from c3nav.mapdata.models.access import AccessRestrictionMixin
|
||||||
from c3nav.mapdata.models.geometry.base import GeometryMixin
|
from c3nav.mapdata.models.geometry.base import GeometryMixin
|
||||||
|
@ -128,6 +129,10 @@ class Space(LevelGeometryMixin, SpecificLocation, models.Model):
|
||||||
result['height'] = None if self.height is None else float(str(self.height))
|
result['height'] = None if self.height is None else float(str(self.height))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@property
|
||||||
|
def grid_cell(self):
|
||||||
|
return grid.get_cells_for_bounds(self.geometry.bounds) or ''
|
||||||
|
|
||||||
def details_display(self, editor_url=True, **kwargs):
|
def details_display(self, editor_url=True, **kwargs):
|
||||||
result = super().details_display(**kwargs)
|
result = super().details_display(**kwargs)
|
||||||
result['display'].extend([
|
result['display'].extend([
|
||||||
|
|
|
@ -126,6 +126,10 @@ class Area(SpaceGeometryMixin, SpecificLocation, models.Model):
|
||||||
result = super()._serialize(**kwargs)
|
result = super()._serialize(**kwargs)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@property
|
||||||
|
def grid_cell(self):
|
||||||
|
return grid.get_cells_for_bounds(self.geometry.bounds) or ''
|
||||||
|
|
||||||
def details_display(self, editor_url=True, **kwargs):
|
def details_display(self, editor_url=True, **kwargs):
|
||||||
result = super().details_display(**kwargs)
|
result = super().details_display(**kwargs)
|
||||||
if editor_url:
|
if editor_url:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue