--- 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
--- a/src/pyams_gis/interfaces/configuration.py Wed Jan 27 15:35:38 2021 +0100
+++ b/src/pyams_gis/interfaces/configuration.py Wed Jan 27 15:36:14 2021 +0100
@@ -10,18 +10,14 @@
# FOR A PARTICULAR PURPOSE.
#
-__docformat__ = 'restructuredtext'
+from zope.interface import Interface
+from zope.schema import Bool, Choice, Int, List
+
+from pyams_gis.interfaces import LAYER_CRS, LAYER_CRS_VOCABULARY, WGS84WM
+from pyams_gis.schema import GeoAreaField, GeoPointField
-# import standard library
-
-# import interfaces
-from pyams_gis.interfaces import LAYER_CRS, LAYER_CRS_VOCABULARY, WGS84WM
-
-# import packages
-from pyams_gis.schema import GeoPointField, GeoAreaField
-from zope.interface import Interface
-from zope.schema import Choice, Bool, Int, List
+__docformat__ = 'restructuredtext'
from pyams_gis import _
@@ -40,6 +36,28 @@
value_type=Choice(vocabulary='PyAMS map layers'),
required=False)
+ auto_adjust = Bool(title=_("Adjust bounds to markers layer"),
+ description=_("If 'yes', map area will be automatically adjusted "
+ "to markers layer(s), if any"),
+ required=True,
+ default=True)
+
+ initial_center = GeoPointField(title=_("Initial center"),
+ description=_("Initial map location center"),
+ required=False)
+
+ zoom_level = Int(title=_("Initial zoom level"),
+ description=_("Zoom level at which to display map, if auto-adjust is "
+ "disabled or if there is only one marker"),
+ min=0,
+ max=18,
+ required=False)
+
+ initial_bounds = GeoAreaField(title=_("Initial bounds"),
+ description=_("Initial map location bounds, if auto-adjust or "
+ "initial center are disabled"),
+ required=False)
+
attribution_control = Bool(title=_("Attribution control?"),
description=_("If 'yes', an attribution control is added to map"),
required=True,
@@ -55,28 +73,15 @@
required=True,
default=False)
- initial_center = GeoPointField(title=_("Initial center"),
- description=_("Initial map location center"),
- required=False)
-
- zoom_level = Int(title=_("Initial zoom level"),
- description=_("Zoom level at which to display map"),
- min=0,
- max=18,
- required=False)
-
- initial_bounds = GeoAreaField(title=_("Initial bounds"),
- description=_("Initial map location bounds"),
- required=False)
-
keyboard = Bool(title=_("Keyboard navigation?"),
- description=_("If 'yes', makes the map focusable and allows users to navigate with "
- "keyboard arrows and +/- keys"),
+ description=_("If 'yes', makes the map focusable and allows users to "
+ "navigate with keyboard arrows and +/- keys"),
required=True,
default=True)
scroll_wheel_zoom = Bool(title=_("Scroll wheel zoom?"),
- description=_("If 'yes', the map can be zoomed using the mouse wheel"),
+ description=_("If 'yes', the map can be zoomed using the mouse "
+ "wheel"),
required=True,
default=True)