Code

Ticket #14886: geomodeladmin_format_patch.diff

File geomodeladmin_format_patch.diff, 2.0 KB (added by slinkp, 3 years ago)

this version of the patch allows passing arbitrary options to the WMS layer constructor

Line 
1Index: django/contrib/gis/admin/options.py
2===================================================================
3--- django/contrib/gis/admin/options.py (revision 14851)
4+++ django/contrib/gis/admin/options.py (working copy)
5@@ -37,6 +37,7 @@
6     wms_url = 'http://labs.metacarta.com/wms/vmap0'
7     wms_layer = 'basic'
8     wms_name = 'OpenLayers WMS'
9+    wms_options = {'format': 'image/jpeg'}
10     debug = False
11     widget = OpenLayersWidget
12 
13@@ -77,6 +78,11 @@
14         class OLMap(self.widget):
15             template = self.map_template
16             geom_type = db_field.geom_type
17+            wms_options = ''
18+            if self.wms_options:
19+                wms_options = ["%s: '%s'" % pair for pair in self.wms_options.items()]
20+                wms_options = ', '.join(wms_options)
21+                wms_options = ', ' + wms_options
22             params = {'default_lon' : self.default_lon,
23                       'default_lat' : self.default_lat,
24                       'default_zoom' : self.default_zoom,
25Index: django/contrib/gis/templates/gis/admin/openlayers.js
26===================================================================
27--- django/contrib/gis/templates/gis/admin/openlayers.js        (revision 14851)
28+++ django/contrib/gis/templates/gis/admin/openlayers.js        (working copy)
29@@ -108,7 +108,7 @@
30     // The admin map for this geometry field.
31     {{ module }}.map = new OpenLayers.Map('{{ id }}_map', options);
32     // Base Layer
33-    {{ module }}.layers.base = {% block base_layer %}new OpenLayers.Layer.WMS( "{{ wms_name }}", "{{ wms_url }}", {layers: '{{ wms_layer }}'} );{% endblock %}
34+    {{ module }}.layers.base = {% block base_layer %}new OpenLayers.Layer.WMS( "{{ wms_name }}", "{{ wms_url }}", {layers: '{{ wms_layer }}' {{ wms_options|safe }} }  );{% endblock %}
35     {{ module }}.map.addLayer({{ module }}.layers.base);
36     {% block extra_layers %}{% endblock %}
37     {% if is_linestring %}OpenLayers.Feature.Vector.style["default"]["strokeWidth"] = 3; // Default too thin for linestrings. {% endif %}