From b647d64408914f500f0a02d3a04d925dabb89ab4 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Fri, 17 Jul 2015 09:00:01 -0400 Subject: [PATCH] Fixed JavaScript "indent" violations. --- .../contrib/gis/static/gis/js/OLMapWidget.js | 697 +++++++++--------- 1 file changed, 348 insertions(+), 349 deletions(-) diff --git a/django/contrib/gis/static/gis/js/OLMapWidget.js b/django/contrib/gis/static/gis/js/OLMapWidget.js index fe799f8640..7d9c0a75f0 100644 --- a/django/contrib/gis/static/gis/js/OLMapWidget.js +++ b/django/contrib/gis/static/gis/js/OLMapWidget.js @@ -1,386 +1,385 @@ /*global OpenLayers*/ -/*eslint indent:1*/ (function() { - /** - * Transforms an array of features to a single feature with the merged - * geometry of geom_type - */ -OpenLayers.Util.properFeatures = function(features, geom_type) { + /** + * Transforms an array of features to a single feature with the merged + * geometry of geom_type + */ + OpenLayers.Util.properFeatures = function(features, geom_type) { if (features.constructor === Array) { - var geoms = []; - for (var i=0; i - */ - -OpenLayers.Format.DjangoWKT = OpenLayers.Class(OpenLayers.Format.WKT, { - initialize: function(options) { - OpenLayers.Format.WKT.prototype.initialize.apply(this, [options]); - this.regExes.justComma = /\s*,\s*/; - }, - - parse: { - 'point': function(str) { - var coords = OpenLayers.String.trim(str).split(this.regExes.spaces); - return new OpenLayers.Feature.Vector( - new OpenLayers.Geometry.Point(coords[0], coords[1]) - ); - }, - - 'multipoint': function(str) { - var point; - var points = OpenLayers.String.trim(str).split(this.regExes.justComma); - var components = []; - for(var i=0, len=points.length; i0) { - pieces.push(','); + + /** + * Class: OpenLayers.Format.DjangoWKT + * Class for reading Well-Known Text, with workarounds to successfully parse + * geometries and collections as returned by django.contrib.gis.geos. + * + * Inherits from: + * - + */ + + OpenLayers.Format.DjangoWKT = OpenLayers.Class(OpenLayers.Format.WKT, { + initialize: function(options) { + OpenLayers.Format.WKT.prototype.initialize.apply(this, [options]); + this.regExes.justComma = /\s*,\s*/; + }, + + parse: { + 'point': function(str) { + var coords = OpenLayers.String.trim(str).split(this.regExes.spaces); + return new OpenLayers.Feature.Vector( + new OpenLayers.Geometry.Point(coords[0], coords[1]) + ); + }, + + 'multipoint': function(str) { + var point; + var points = OpenLayers.String.trim(str).split(this.regExes.justComma); + var components = []; + for(var i=0, len=points.length; i0) { + pieces.push(','); + } + pieces.push(this.extractGeometry(collection[i])); + } + pieces.push(')'); + } else { + pieces.push(this.extractGeometry(features.geometry)); + } + return pieces.join(''); + }, + + CLASS_NAME: "OpenLayers.Format.DjangoWKT" + }); + + function MapWidget(options) { + this.map = null; + this.controls = null; + this.panel = null; + this.layers = {}; + this.wkt_f = new OpenLayers.Format.DjangoWKT(); + + // Mapping from OGRGeomType name to OpenLayers.Geometry name + if (options['geom_name'] === 'Unknown') { + options['geom_type'] = OpenLayers.Geometry; + } else if (options['geom_name'] === 'GeometryCollection') { + options['geom_type'] = OpenLayers.Geometry.Collection; } else { - pieces.push(this.extractGeometry(features.geometry)); + options['geom_type'] = eval('OpenLayers.Geometry.' + options['geom_name']); } - return pieces.join(''); - }, - CLASS_NAME: "OpenLayers.Format.DjangoWKT" -}); + // Default options + this.options = { + color: 'ee9900', + default_lat: 0, + default_lon: 0, + default_zoom: 4, + is_collection: new options['geom_type']() instanceof OpenLayers.Geometry.Collection, + layerswitcher: false, + map_options: {}, + map_srid: 4326, + modifiable: true, + mouse_position: false, + opacity: 0.4, + point_zoom: 12, + scale_text: false, + scrollable: true + }; -function MapWidget(options) { - this.map = null; - this.controls = null; - this.panel = null; - this.layers = {}; - this.wkt_f = new OpenLayers.Format.DjangoWKT(); + // Altering using user-provided options + for (var property in options) { + if (options.hasOwnProperty(property)) { + this.options[property] = options[property]; + } + } - // Mapping from OGRGeomType name to OpenLayers.Geometry name - if (options['geom_name'] === 'Unknown') { - options['geom_type'] = OpenLayers.Geometry; - } else if (options['geom_name'] === 'GeometryCollection') { - options['geom_type'] = OpenLayers.Geometry.Collection; - } else { - options['geom_type'] = eval('OpenLayers.Geometry.' + options['geom_name']); - } + this.map = this.create_map(); - // Default options - this.options = { - color: 'ee9900', - default_lat: 0, - default_lon: 0, - default_zoom: 4, - is_collection: new options['geom_type']() instanceof OpenLayers.Geometry.Collection, - layerswitcher: false, - map_options: {}, - map_srid: 4326, - modifiable: true, - mouse_position: false, - opacity: 0.4, - point_zoom: 12, - scale_text: false, - scrollable: true - }; + var defaults_style = { + 'fillColor': '#' + this.options.color, + 'fillOpacity': this.options.opacity, + 'strokeColor': '#' + this.options.color + }; + if (this.options.geom_name === 'LineString') { + defaults_style['strokeWidth'] = 3; + } + var styleMap = new OpenLayers.StyleMap({'default': OpenLayers.Util.applyDefaults(defaults_style, OpenLayers.Feature.Vector.style['default'])}); + this.layers.vector = new OpenLayers.Layer.Vector(" " + this.options.name, {styleMap: styleMap}); + this.map.addLayer(this.layers.vector); + var wkt = document.getElementById(this.options.id).value; + if (wkt) { + var feat = OpenLayers.Util.properFeatures(this.read_wkt(wkt), this.options.geom_type); + this.write_wkt(feat); + if (this.options.is_collection) { + for (var i=0; i 1) { - var old_feats = [this.layers.vector.features[0]]; - this.layers.vector.removeFeatures(old_feats); - this.layers.vector.destroyFeatures(old_feats); - } - this.write_wkt(event.feature); - } -}; - -MapWidget.prototype.modify_wkt = function(event) { - if (this.options.is_collection) { - if (this.options.geom_name === 'MultiPoint') { - this.add_wkt(event); - return; - } else { + MapWidget.prototype.add_wkt = function(event) { + if (this.options.is_collection) { var feat = new OpenLayers.Feature.Vector(new this.options.geom_type()); - for (var i=0; i 1) { + var old_feats = [this.layers.vector.features[0]]; + this.layers.vector.removeFeatures(old_feats); + this.layers.vector.destroyFeatures(old_feats); + } + this.write_wkt(event.feature); } - } else { - this.write_wkt(event.feature); - } -}; + }; -MapWidget.prototype.deleteFeatures = function() { - this.layers.vector.removeFeatures(this.layers.vector.features); - this.layers.vector.destroyFeatures(); -}; + MapWidget.prototype.modify_wkt = function(event) { + if (this.options.is_collection) { + if (this.options.geom_name === 'MultiPoint') { + this.add_wkt(event); + return; + } else { + var feat = new OpenLayers.Feature.Vector(new this.options.geom_type()); + for (var i=0; i= 0 || this.options.geom_name === 'GeometryCollection' || this.options.geom_name === 'Unknown') { - this.controls.push(new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Path, {'displayClass': 'olControlDrawFeaturePath'})); - } - if (this.options.geom_name.indexOf('Polygon') >= 0 || this.options.geom_name === 'GeometryCollection' || this.options.geom_name === 'Unknown') { - this.controls.push(new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Polygon, {'displayClass': 'olControlDrawFeaturePolygon'})); - } - if (this.options.geom_name.indexOf('Point') >= 0 || this.options.geom_name === 'GeometryCollection' || this.options.geom_name === 'Unknown') { - this.controls.push(new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Point, {'displayClass': 'olControlDrawFeaturePoint'})); - } - if (this.options.modifiable) { - this.controls.push(new OpenLayers.Control.ModifyFeature(layer, {'displayClass': 'olControlModifyFeature'})); - } -}; -window.MapWidget = MapWidget; + MapWidget.prototype.enableEditing = function() { + this.map.getControlsByClass('OpenLayers.Control.ModifyFeature')[0].activate(); + }; + + MapWidget.prototype.getControls = function(layer) { + this.panel = new OpenLayers.Control.Panel({'displayClass': 'olControlEditingToolbar'}); + this.controls = [new OpenLayers.Control.Navigation()]; + if (!this.options.modifiable && layer.features.length) { + return; + } + if (this.options.geom_name.indexOf('LineString') >= 0 || this.options.geom_name === 'GeometryCollection' || this.options.geom_name === 'Unknown') { + this.controls.push(new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Path, {'displayClass': 'olControlDrawFeaturePath'})); + } + if (this.options.geom_name.indexOf('Polygon') >= 0 || this.options.geom_name === 'GeometryCollection' || this.options.geom_name === 'Unknown') { + this.controls.push(new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Polygon, {'displayClass': 'olControlDrawFeaturePolygon'})); + } + if (this.options.geom_name.indexOf('Point') >= 0 || this.options.geom_name === 'GeometryCollection' || this.options.geom_name === 'Unknown') { + this.controls.push(new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Point, {'displayClass': 'olControlDrawFeaturePoint'})); + } + if (this.options.modifiable) { + this.controls.push(new OpenLayers.Control.ModifyFeature(layer, {'displayClass': 'olControlModifyFeature'})); + } + }; + window.MapWidget = MapWidget; })();