# HG changeset patch # User Thierry Florac # Date 1611758240 -3600 # Node ID d9ee6f8ddb7694ceb7dee7ae5b121274dd6e90ce # Parent 032947e7ef0c1e9dec80e128b2880a94dd8ad121 Added GeoJSON layer type diff -r 032947e7ef0c -r d9ee6f8ddb76 src/pyams_gis/interfaces/layer.py --- a/src/pyams_gis/interfaces/layer.py Wed Jan 27 15:36:14 2021 +0100 +++ b/src/pyams_gis/interfaces/layer.py Wed Jan 27 15:37:20 2021 +0100 @@ -10,22 +10,18 @@ # FOR A PARTICULAR PURPOSE. # -__docformat__ = 'restructuredtext' +from zope.annotation.interfaces import IAttributeAnnotatable +from zope.interface import Attribute +from zope.location.interfaces import IContained +from zope.schema import Bool, Choice, Int, Text, TextLine +from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary + +from pyams_gis.interfaces import LAYER_CRS_VOCABULARY +from pyams_gis.schema import GeoAreaField +from pyams_i18n.schema import I18nTextLineField -# import standard library - -# import interfaces -from pyams_gis.interfaces import LAYER_CRS_VOCABULARY -from zope.annotation.interfaces import IAttributeAnnotatable -from zope.location.interfaces import IContained - -# import packages -from pyams_gis.schema import GeoAreaField -from pyams_i18n.schema import I18nTextLineField -from zope.interface import Attribute -from zope.schema import Bool, Choice, Int, TextLine -from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm +__docformat__ = 'restructuredtext' from pyams_gis import _ @@ -64,6 +60,18 @@ """Get layer configuration mapping""" +class IGeoJSONLayer(IMapLayer): + """GeoJSON map layer interface""" + + url = TextLine(title=_("Layer URL"), + description=_("URL used to get access to JSON data"), + required=True) + + style = Text(title=_("Layer style"), + description=_("Layer style, provided in Leaflet JSON format"), + required=False) + + class IBaseTileMapLayer(IMapLayer): """Base tile map layer interface""" diff -r 032947e7ef0c -r d9ee6f8ddb76 src/pyams_gis/layer.py --- a/src/pyams_gis/layer.py Wed Jan 27 15:36:14 2021 +0100 +++ b/src/pyams_gis/layer.py Wed Jan 27 15:37:20 2021 +0100 @@ -16,7 +16,10 @@ # import standard library # import interfaces -from pyams_gis.interfaces.layer import IMapLayer, IBaseTileMapLayer, ITileMapLayer, IWMSMapLayer, IGeoportalMapLayer, \ +import json + +from pyams_gis.interfaces.layer import IGeoJSONLayer, IMapLayer, IBaseTileMapLayer, ITileMapLayer, \ + IWMSMapLayer, IGeoportalMapLayer, \ IEsriFeatureMapLayer, IGoogleMapLayer from pyams_i18n.interfaces import II18n @@ -46,8 +49,10 @@ def get_configuration(self): """Get configuration mapping""" - result = {'name': self.name, - 'title': II18n(self).query_attribute('title')} + result = { + 'name': self.name, + 'title': II18n(self).query_attribute('title') + } update_dict(result, 'factory', self.factory) update_dict(result, 'minZoom', self.min_zoom) update_dict(result, 'maxZoom', self.max_zoom) @@ -59,6 +64,23 @@ return result +class GeoJSONLayer(MapLayer): + """GeoJSON layer""" + + factory = 'PyAMS_GIS.factory.GeoJSON' + layer_type = _("GeoJSON") + + url = FieldProperty(IGeoJSONLayer['url']) + style = FieldProperty(IGeoJSONLayer['style']) + + def get_configuration(self): + result = super(GeoJSONLayer, self).get_configuration() + update_dict(result, 'url', self.url) + if self.style: + update_dict(result, 'style', json.loads(self.style)) + return result + + class BaseTileMapLayer(MapLayer): """Base tile map layer""" @@ -70,10 +92,13 @@ update_dict(result, 'attribution', self.attribution) if self.bounds: point1, point2 = self.bounds.wgs_coordinates - result['bounds'] = [{'lat': float(point1[1]), - 'lon': float(point1[0])}, - {'lat': float(point2[1]), - 'lon': float(point2[0])}] + result['bounds'] = [{ + 'lat': float(point1[1]), + 'lon': float(point1[0]) + }, { + 'lat': float(point2[1]), + 'lon': float(point2[0]) + }] return result