Kaydet (Commit) a7975260 authored tarafından Danilo Bargen's avatar Danilo Bargen Kaydeden (comit) Tim Graham

Fixed #28195 -- Added OSMWidget.default_zoom attribute.

üst d4d812cb
......@@ -103,10 +103,11 @@ class OSMWidget(OpenLayersWidget):
template_name = 'gis/openlayers-osm.html'
default_lon = 5
default_lat = 47
default_zoom = 12
def __init__(self, attrs=None):
super().__init__()
for key in ('default_lon', 'default_lat'):
for key in ('default_lon', 'default_lat', 'default_zoom'):
self.attrs[key] = getattr(self, key)
if attrs:
self.attrs.update(attrs)
......@@ -4,6 +4,7 @@
{% block options %}{{ block.super }}
options['default_lon'] = {{ default_lon|unlocalize }};
options['default_lat'] = {{ default_lat|unlocalize }};
options['default_zoom'] = {{ default_zoom|unlocalize }};
{% endblock %}
{% block base_layer %}
......
......@@ -185,6 +185,12 @@ Widget classes
The default center latitude and longitude are ``47`` and ``5``,
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
applies here. See also this `FAQ answer`_ about ``https`` access to map
tiles.
......
......@@ -75,6 +75,9 @@ Minor features
* Any :class:`~django.contrib.gis.geos.GEOSGeometry` imported from GeoJSON now
has its SRID set.
* Added the :attr:`.OSMWidget.default_zoom` attribute to customize the map's
default zoom level.
:mod:`django.contrib.messages`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......
......@@ -328,11 +328,14 @@ class OSMWidgetTest(SimpleTestCase):
def test_default_lat_lon(self):
self.assertEqual(forms.OSMWidget.default_lon, 5)
self.assertEqual(forms.OSMWidget.default_lat, 47)
self.assertEqual(forms.OSMWidget.default_zoom, 12)
class PointForm(forms.Form):
p = forms.PointField(
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_lat'] = 30;", rendered)
self.assertIn("options['default_zoom'] = 17;", rendered)
class GeometryWidgetTests(SimpleTestCase):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment