cache GeometryMapItem.to_geojson()
This commit is contained in:
parent
48b0695a07
commit
32d6033301
1 changed files with 10 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from shapely.geometry.geo import mapping, shape
|
from shapely.geometry.geo import mapping, shape
|
||||||
|
@ -25,6 +26,7 @@ class GeometryMapItem(MapItem, metaclass=GeometryMapItemMeta):
|
||||||
A map feature
|
A map feature
|
||||||
"""
|
"""
|
||||||
geometry = GeometryField()
|
geometry = GeometryField()
|
||||||
|
cached_geojson = {}
|
||||||
|
|
||||||
geomtype = None
|
geomtype = None
|
||||||
|
|
||||||
|
@ -62,6 +64,14 @@ class GeometryMapItem(MapItem, metaclass=GeometryMapItemMeta):
|
||||||
))
|
))
|
||||||
|
|
||||||
def to_geojson(self):
|
def to_geojson(self):
|
||||||
|
if settings.DIRECT_EDITING:
|
||||||
|
return self._to_geojson()
|
||||||
|
key = (self.__class__, self.name)
|
||||||
|
if key not in self.cached_geojson:
|
||||||
|
self.cached_geojson[key] = self._to_geojson()
|
||||||
|
return self.cached_geojson[key]
|
||||||
|
|
||||||
|
def _to_geojson(self):
|
||||||
return [OrderedDict((
|
return [OrderedDict((
|
||||||
('type', 'Feature'),
|
('type', 'Feature'),
|
||||||
('properties', self.get_geojson_properties()),
|
('properties', self.get_geojson_properties()),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue