diff --git a/django/contrib/gis/admin/options.py b/django/contrib/gis/admin/options.py index fff1cb20a6..a1da28108d 100644 --- a/django/contrib/gis/admin/options.py +++ b/django/contrib/gis/admin/options.py @@ -64,7 +64,7 @@ class GeoModelAdmin(ModelAdmin): def get_map_widget(self, db_field): """ Returns a subclass of the OpenLayersWidget (or whatever was specified - in the `widget` attribute) using the settings from the attributes set + in the `widget` attribute) using the settings from the attributes set in this class. """ is_collection = db_field.geom_type in ('MULTIPOINT', 'MULTILINESTRING', 'MULTIPOLYGON', 'GEOMETRYCOLLECTION') @@ -111,12 +111,6 @@ class GeoModelAdmin(ModelAdmin): } return OLMap -# Using the Beta OSM in the admin requires the following: -# (1) The Google Maps Mercator projection needs to be added -# to your `spatial_ref_sys` table. You'll need at least GDAL 1.5: -# >>> from django.contrib.gis.gdal import SpatialReference -# >>> from django.contrib.gis.utils import add_postgis_srs -# >>> add_postgis_srs(SpatialReference(900913)) # Adding the Google Projection from django.contrib.gis import gdal if gdal.HAS_GDAL: class OSMGeoAdmin(GeoModelAdmin): diff --git a/django/contrib/gis/templates/gis/admin/openlayers.js b/django/contrib/gis/templates/gis/admin/openlayers.js index 93286cc464..4324693c78 100644 --- a/django/contrib/gis/templates/gis/admin/openlayers.js +++ b/django/contrib/gis/templates/gis/admin/openlayers.js @@ -1,6 +1,7 @@ {# Author: Justin Bronn, Travis Pinney & Dane Springmeyer #} {% block vars %}var {{ module }} = {}; -{{ module }}.map = null; {{ module }}.controls = null; {{ module }}.panel = null; {{ module }}.re = new RegExp("^SRID=\d+;(.+)", "i"); {{ module }}.layers = {}; +{{ module }}.map = null; {{ module }}.controls = null; {{ module }}.panel = null; {{ module }}.re = new RegExp("^SRID=\d+;(.+)", "i"); {{ module }}.layers = {}; +{{ module }}.modifiable = {{ modifiable|yesno:"true,false" }}; {{ module }}.wkt_f = new OpenLayers.Format.WKT(); {{ module }}.is_collection = {{ is_collection|yesno:"true,false" }}; {{ module }}.collection_type = '{{ collection_type }}'; @@ -43,10 +44,10 @@ {{ module }}.modify_wkt = function(event){ if ({{ module }}.is_collection){ if ({{ module }}.is_point){ - {{ module }}.add_wkt(event); + {{ module }}.add_wkt(event); return; } else { - // When modifying the selected components are added to the + // When modifying the selected components are added to the // vector layer so we only increment to the `num_geom` value. var feat = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.{{ geom_type }}()); for (var i = 0; i < {{ module }}.num_geom; i++){ @@ -69,7 +70,7 @@ {{ module }}.map.setCenter(new OpenLayers.LonLat({{ default_lon }}, {{ default_lat }}), {{ default_zoom }}); } // Add Select control -{{ module }}.addSelectControl = function(){ +{{ module }}.addSelectControl = function(){ var select = new OpenLayers.Control.SelectFeature({{ module }}.layers.vector, {'toggle' : true, 'clickout' : true}); {{ module }}.map.addControl(select); select.activate(); @@ -88,16 +89,20 @@ } else if ({{ module }}.is_point){ draw_ctl = new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Point, {'displayClass': 'olControlDrawFeaturePoint'}); } - {% if modifiable %} - var mod = new OpenLayers.Control.ModifyFeature(lyr, {'displayClass': 'olControlModifyFeature'}); - {{ module }}.controls = [nav, draw_ctl, mod]; - {% else %} - {{ module }}.controls = [nav, darw_ctl]; - {% endif %} + if ({{ module }}.modifiable){ + var mod = new OpenLayers.Control.ModifyFeature(lyr, {'displayClass': 'olControlModifyFeature'}); + {{ module }}.controls = [nav, draw_ctl, mod]; + } else { + if(!lyr.features.length){ + {{ module }}.controls = [nav, draw_ctl]; + } else { + {{ module }}.controls = [nav]; + } + } } {{ module }}.init = function(){ {% block map_options %}// The options hash, w/ zoom, resolution, and projection settings. - var options = { + var options = { {% autoescape off %}{% for item in map_options.items %} '{{ item.0 }}' : {{ item.1 }}{% if not forloop.last %},{% endif %} {% endfor %}{% endautoescape %} };{% endblock %} // The admin map for this geometry field. @@ -112,7 +117,7 @@ // Read WKT from the text field. var wkt = document.getElementById('{{ id }}').value; if (wkt){ - // After reading into geometry, immediately write back to + // After reading into geometry, immediately write back to // WKT