diff --git a/django/contrib/gis/static/gis/js/OLMapWidget.js b/django/contrib/gis/static/gis/js/OLMapWidget.js index 0736779370..c1a56d2f36 100644 --- a/django/contrib/gis/static/gis/js/OLMapWidget.js +++ b/django/contrib/gis/static/gis/js/OLMapWidget.js @@ -184,7 +184,7 @@ default_lat: 0, default_lon: 0, default_zoom: 4, - is_collection: new options.geom_type() instanceof OpenLayers.Geometry.Collection, + is_collection: options.geom_name.indexOf('Multi') > -1 || options.geom_name.indexOf('Collection') > -1, layerswitcher: false, map_options: {}, map_srid: 4326, diff --git a/js_tests/gis/mapwidget.test.js b/js_tests/gis/mapwidget.test.js index c46823c9b9..716e6eca8b 100644 --- a/js_tests/gis/mapwidget.test.js +++ b/js_tests/gis/mapwidget.test.js @@ -44,3 +44,35 @@ test('MapWidget.getControls', function(assert) { assert.equal(widget.controls[1].displayClass, 'olControlDrawFeaturePoint', 'Draw control'); assert.equal(widget.controls[2].displayClass, 'olControlModifyFeature', 'Modify control'); }); + +test('MapWidget.IsCollection', function(assert) { + var options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'}; + var widget = new MapWidget(options); + assert.notOk(widget.options.is_collection); + // Empty the default initial Point + document.getElementById('id_point').value = ""; + + options.geom_name = 'Polygon'; + widget = new MapWidget(options); + assert.notOk(widget.options.is_collection); + + options.geom_name = 'LineString'; + widget = new MapWidget(options); + assert.notOk(widget.options.is_collection); + + options.geom_name = 'MultiPoint'; + widget = new MapWidget(options); + assert.ok(widget.options.is_collection); + + options.geom_name = 'MultiPolygon'; + widget = new MapWidget(options); + assert.ok(widget.options.is_collection); + + options.geom_name = 'MultiLineString'; + widget = new MapWidget(options); + assert.ok(widget.options.is_collection); + + options.geom_name = 'GeometryCollection'; + widget = new MapWidget(options); + assert.ok(widget.options.is_collection); +});