(function() { /** * 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(','); } 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(); // Default options this.options = { base_layer: new OpenLayers.Layer.WMS('OpenLayers WMS', 'http://vmap0.tiles.osgeo.org/wms/vmap0', {layers: 'basic'}), color: 'ee9900', default_lat: 0, default_lon: 0, default_zoom: 4, is_collection: false, is_linestring: false, is_point: false, is_polygon: false, layerswitcher: false, map_options: {}, map_srid: 4326, modifiable: true, mouse_position: false, opacity: 0.4, point_zoom: 12, scale_text: false, scrollable: true }; // Altering using user-provied options for (var property in options) { if (options.hasOwnProperty(property)) { this.options[property] = options[property]; } } this.map = new OpenLayers.Map(this.options.map_id, this.options.map_options); this.layers.base = this.options.base_layer; this.map.addLayer(this.layers.base); var defaults_style = { 'fillColor': '#' + this.options.color, 'fillOpacity': this.options.opacity, 'strokeColor': '#' + this.options.color }; if (this.options.is_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); 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) { 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.is_point) { this.add_wkt(event); return; } else { var feat = new OpenLayers.Feature.Vector(new this.options.geom_type()); for (var i=0; i