--- a/src/pyams_gis/configuration.py Wed Jan 27 15:35:38 2021 +0100
+++ b/src/pyams_gis/configuration.py Wed Jan 27 15:36:14 2021 +0100
@@ -17,8 +17,10 @@
from zope.schema.fieldproperty import FieldProperty
from pyams_gis.interfaces.configuration import IMapConfiguration, IMapConfigurationTarget
+from pyams_gis.interfaces.utility import IMapManager
from pyams_utils.adapter import adapter_config, get_annotation_adapter
from pyams_utils.factory import factory_config
+from pyams_utils.registry import get_utility
@factory_config(IMapConfiguration)
@@ -27,44 +29,54 @@
crs = FieldProperty(IMapConfiguration['crs'])
layers = FieldProperty(IMapConfiguration['layers'])
+ auto_adjust = FieldProperty(IMapConfiguration['auto_adjust'])
+ initial_center = FieldProperty(IMapConfiguration['initial_center'])
+ zoom_level = FieldProperty(IMapConfiguration['zoom_level'])
+ initial_bounds = FieldProperty(IMapConfiguration['initial_bounds'])
attribution_control = FieldProperty(IMapConfiguration['attribution_control'])
zoom_control = FieldProperty(IMapConfiguration['zoom_control'])
layer_control = FieldProperty(IMapConfiguration['layer_control'])
- initial_center = FieldProperty(IMapConfiguration['initial_center'])
- zoom_level = FieldProperty(IMapConfiguration['zoom_level'])
- initial_bounds = FieldProperty(IMapConfiguration['initial_bounds'])
keyboard = FieldProperty(IMapConfiguration['keyboard'])
scroll_wheel_zoom = FieldProperty(IMapConfiguration['scroll_wheel_zoom'])
def get_configuration(self):
result = {
'crs': self.crs,
+ 'layerControl': self.layer_control,
'attributionControl': self.attribution_control,
'zoomControl': self.zoom_control,
- 'layerControl': self.layer_control,
'keyboard': self.keyboard,
- 'scrollWheelZoom': self.scroll_wheel_zoom
+ 'scrollWheelZoom': self.scroll_wheel_zoom,
+ 'zoom': self.zoom_level
}
+ if self.auto_adjust:
+ result['adjust'] = 'auto'
if self.initial_center:
gps_location = self.initial_center.wgs_coordinates
- result['center'] = {'lat': float(gps_location[1]),
- 'lon': float(gps_location[0])}
- result['zoom'] = self.zoom_level
+ result['center'] = {
+ 'lat': float(gps_location[1]),
+ 'lon': float(gps_location[0])
+ }
elif self.initial_bounds:
point1, point2 = self.initial_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])
+ }]
else:
# Near center default location
- result['center'] = {'lat': 45,
- 'lon': 5.0}
- result['zoom'] = 2
+ result['center'] = {
+ 'lat': 45,
+ 'lon': 5.0
+ }
if self.layers:
layers = []
for name in self.layers:
- layer = self.__parent__.get(name)
+ manager = get_utility(IMapManager)
+ layer = manager.get(name)
if layer is not None:
layers.append(layer.get_configuration())
result['layers'] = layers