Fixed #28195 -- Added OSMWidget.default_zoom attribute.

This commit is contained in:
Danilo Bargen 2017-05-14 20:31:17 +02:00 committed by Tim Graham
parent d4d812cb56
commit a7975260b5
5 changed files with 17 additions and 2 deletions

View File

@ -103,10 +103,11 @@ class OSMWidget(OpenLayersWidget):
template_name = 'gis/openlayers-osm.html' template_name = 'gis/openlayers-osm.html'
default_lon = 5 default_lon = 5
default_lat = 47 default_lat = 47
default_zoom = 12
def __init__(self, attrs=None): def __init__(self, attrs=None):
super().__init__() super().__init__()
for key in ('default_lon', 'default_lat'): for key in ('default_lon', 'default_lat', 'default_zoom'):
self.attrs[key] = getattr(self, key) self.attrs[key] = getattr(self, key)
if attrs: if attrs:
self.attrs.update(attrs) self.attrs.update(attrs)

View File

@ -4,6 +4,7 @@
{% block options %}{{ block.super }} {% block options %}{{ block.super }}
options['default_lon'] = {{ default_lon|unlocalize }}; options['default_lon'] = {{ default_lon|unlocalize }};
options['default_lat'] = {{ default_lat|unlocalize }}; options['default_lat'] = {{ default_lat|unlocalize }};
options['default_zoom'] = {{ default_zoom|unlocalize }};
{% endblock %} {% endblock %}
{% block base_layer %} {% block base_layer %}

View File

@ -185,6 +185,12 @@ Widget classes
The default center latitude and longitude are ``47`` and ``5``, The default center latitude and longitude are ``47`` and ``5``,
respectively, which is a location in eastern France. respectively, which is a location in eastern France.
.. attribute:: default_zoom
.. versionadded:: 2.0
The default map zoom is ``12``.
The :class:`OpenLayersWidget` note about JavaScript file hosting above also The :class:`OpenLayersWidget` note about JavaScript file hosting above also
applies here. See also this `FAQ answer`_ about ``https`` access to map applies here. See also this `FAQ answer`_ about ``https`` access to map
tiles. tiles.

View File

@ -75,6 +75,9 @@ Minor features
* Any :class:`~django.contrib.gis.geos.GEOSGeometry` imported from GeoJSON now * Any :class:`~django.contrib.gis.geos.GEOSGeometry` imported from GeoJSON now
has its SRID set. has its SRID set.
* Added the :attr:`.OSMWidget.default_zoom` attribute to customize the map's
default zoom level.
:mod:`django.contrib.messages` :mod:`django.contrib.messages`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -328,11 +328,14 @@ class OSMWidgetTest(SimpleTestCase):
def test_default_lat_lon(self): def test_default_lat_lon(self):
self.assertEqual(forms.OSMWidget.default_lon, 5) self.assertEqual(forms.OSMWidget.default_lon, 5)
self.assertEqual(forms.OSMWidget.default_lat, 47) self.assertEqual(forms.OSMWidget.default_lat, 47)
self.assertEqual(forms.OSMWidget.default_zoom, 12)
class PointForm(forms.Form): class PointForm(forms.Form):
p = forms.PointField( p = forms.PointField(
widget=forms.OSMWidget(attrs={ widget=forms.OSMWidget(attrs={
'default_lon': 20, 'default_lat': 30 'default_lon': 20,
'default_lat': 30,
'default_zoom': 17,
}), }),
) )
@ -341,6 +344,7 @@ class OSMWidgetTest(SimpleTestCase):
self.assertIn("options['default_lon'] = 20;", rendered) self.assertIn("options['default_lon'] = 20;", rendered)
self.assertIn("options['default_lat'] = 30;", rendered) self.assertIn("options['default_lat'] = 30;", rendered)
self.assertIn("options['default_zoom'] = 17;", rendered)
class GeometryWidgetTests(SimpleTestCase): class GeometryWidgetTests(SimpleTestCase):