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