Ticket #14886: 14886-2.diff

File 14886-2.diff, 3.9 KB (added by claudep, 3 years ago)

Patch with tests

  • django/contrib/gis/admin/options.py

    diff --git a/django/contrib/gis/admin/options.py b/django/contrib/gis/admin/options.py
    index 4732e73..42e5f53 100644
    a b class GeoModelAdmin(ModelAdmin): 
    3636    wms_url = 'http://labs.metacarta.com/wms/vmap0'
    3737    wms_layer = 'basic'
    3838    wms_name = 'OpenLayers WMS'
     39    wms_options = {'format': 'image/jpeg'}
    3940    debug = False
    4041    widget = OpenLayersWidget
    4142
    class GeoModelAdmin(ModelAdmin): 
    7677        class OLMap(self.widget):
    7778            template = self.map_template
    7879            geom_type = db_field.geom_type
     80
     81            wms_options = ''
     82            if self.wms_options:
     83                wms_options = ["%s: '%s'" % pair for pair in self.wms_options.items()]
     84                wms_options = ', %s' % ', '.join(wms_options)
     85
    7986            params = {'default_lon' : self.default_lon,
    8087                      'default_lat' : self.default_lat,
    8188                      'default_zoom' : self.default_zoom,
    class GeoModelAdmin(ModelAdmin): 
    106113                      'wms_url' : self.wms_url,
    107114                      'wms_layer' : self.wms_layer,
    108115                      'wms_name' : self.wms_name,
     116                      'wms_options' : wms_options,
    109117                      'debug' : self.debug,
    110118                      }
    111119        return OLMap
  • django/contrib/gis/templates/gis/admin/openlayers.js

    diff --git a/django/contrib/gis/templates/gis/admin/openlayers.js b/django/contrib/gis/templates/gis/admin/openlayers.js
    index 4f34b6b..102adfb 100644
    a b OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:3857", OpenLayers.Layer.Sp 
    111111    // The admin map for this geometry field.
    112112    {{ module }}.map = new OpenLayers.Map('{{ id }}_map', options);
    113113    // Base Layer
    114     {{ module }}.layers.base = {% block base_layer %}new OpenLayers.Layer.WMS( "{{ wms_name }}", "{{ wms_url }}", {layers: '{{ wms_layer }}'} );{% endblock %}
     114    {{ module }}.layers.base = {% block base_layer %}new OpenLayers.Layer.WMS("{{ wms_name }}", "{{ wms_url }}", {layers: '{{ wms_layer }}'{{ wms_options|safe }}});{% endblock %}
    115115    {{ module }}.map.addLayer({{ module }}.layers.base);
    116116    {% block extra_layers %}{% endblock %}
    117117    {% if is_linestring %}OpenLayers.Feature.Vector.style["default"]["strokeWidth"] = 3; // Default too thin for linestrings. {% endif %}
  • django/contrib/gis/tests/geoadmin/tests.py

    diff --git a/django/contrib/gis/tests/geoadmin/tests.py b/django/contrib/gis/tests/geoadmin/tests.py
    index aa07c2c..1f104b2 100644
    a b from __future__ import absolute_import 
    22
    33from django.test import TestCase
    44from django.contrib.gis import admin
     5from django.contrib.gis.geos import Point
    56
    67from .models import City
    78
    class GeoAdminTest(TestCase): 
    1415        admin_js = geoadmin.media.render_js()
    1516        self.assertTrue(any([geoadmin.openlayers_url in js for js in admin_js]))
    1617
     18    def test_olmap_OSM_rendering(self):
     19        geoadmin = admin.site._registry[City]
     20        result = geoadmin.get_map_widget(City._meta.get_field('point'))(
     21            ).render('point', Point(-79.460734, 40.18476))
     22        self.assertIn(
     23            """geodjango_point.layers.base = new OpenLayers.Layer.OSM("OpenStreetMap (Mapnik)");""",
     24            result)
     25
     26    def test_olmap_WMS_rendering(self):
     27        admin.site.unregister(City)
     28        admin.site.register(City, admin.GeoModelAdmin)
     29
     30        geoadmin = admin.site._registry[City]
     31        result = geoadmin.get_map_widget(City._meta.get_field('point'))(
     32            ).render('point', Point(-79.460734, 40.18476))
     33        self.assertIn(
     34            """geodjango_point.layers.base = new OpenLayers.Layer.WMS("OpenLayers WMS", "http://labs.metacarta.com/wms/vmap0", {layers: \'basic\', format: 'image/jpeg'});""",
     35            result)
Back to Top