OpenLayers OpenLayers

Ticket #1005 (new feature)

Opened 11 months ago

Last modified 7 months ago

allow customization of the tools that appear in the editing toolbar

Reported by: brentp Assigned to:
Priority: minor Milestone: 2.7 Release
Component: Control Version: 2.4
Keywords: Cc:
State: Needs More Work

Description

in trunk, all tools (Polygon, Point, Path) appear in the toolbar by defautl, this patch allows specification of which controls are to appear in teh options of the constructor:

var editbar = new OpenLayers.Control.EditingToolbar(vlayer,{'tools':['Point','Polygon']})

will only show the Point and Polygon tools.

$ svn diff lib/OpenLayers/Control/EditingToolbar.js 
Index: lib/OpenLayers/Control/EditingToolbar.js
===================================================================
--- lib/OpenLayers/Control/EditingToolbar.js    (revision 4394)
+++ lib/OpenLayers/Control/EditingToolbar.js    (working copy)
@@ -24,19 +24,26 @@
      * layer - {<OpenLayers.Layer.Vector>} 
      * options - {Object} 
      */
+    DEFAULT_TOOLS : ['Point', 'Path', 'Polygon'],
+
     initialize: function(layer, options) {
         OpenLayers.Control.Panel.prototype.initialize.apply(this, [options]);
         
         this.addControls(
           [ new OpenLayers.Control.Navigation() ]
         );  
-        var controls = [
-          new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Point, {'displayClass': 'olControlDrawFeaturePoint'}),
-          new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Path, {'displayClass': 'olControlDrawFeaturePath'}),
-          new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Polygon, {'displayClass': 'olControlDrawFeaturePolygon'})
-        ];
-        for (var i = 0; i < controls.length; i++) {
-            controls[i].featureAdded = function(feature) { feature.state = OpenLayers.State.INSERT; }
+        var tools = options && options.tools 
+                  || OpenLayers.Control.EditingToolbar.prototype.DEFAULT_TOOLS
+        controls = [];
+        var ctl;
+        for(var i=0;ctl=tools[i];++i){
+           var drawfeat = new OpenLayers.Control.DrawFeature(layer,
+                    OpenLayers.Handler[ctl], 
+                    {'displayClass': 'olControlDrawFeature' + ctl });
+           drawfeat.featureAdded = function(feature){ 
+                    feature.state = OpenLayers.State.INSERT;
+           };
+           controls.push(drawfeat);
         }
         this.addControls(controls);
     },

Attachments

test_EditingToolbar.html (1.4 kB) - added by brentp on 09/20/07 18:18:11.
start of tests for Editing toolbar
toolbar.patch (1.8 kB) - added by tlpinney on 02/04/08 19:13:04.
Patch described in the ticket
test_EditingToolbar.2.html (2.3 kB) - added by tlpinney on 02/10/08 00:36:52.
Added more tests.

Change History

09/19/07 15:02:14 changed by crschmidt

  • keywords changed from Editing, Toolbar to needstests.
  • version changed from 2.5 RC1 to 2.4.
  • milestone set to 2.6 Release.

09/20/07 18:18:11 changed by brentp

  • attachment test_EditingToolbar.html added.

start of tests for Editing toolbar

12/14/07 17:30:19 changed by crschmidt

  • keywords deleted.
  • state set to Needs More Work.

Hm, I just realized there isn't actually a patch here -- can we get a patchfile on it?

01/22/08 17:37:20 changed by crschmidt

  • milestone changed from 2.6 Release to 2.7 Release.

Mass ticket move to 2.7 post dev meeting. If you are actively working on this task, please update this ticket with information and change the milestone to 2.6. At the time of the next IRC meeting (most likely 1-31-08), this will mean the ticket can *not* be brought back into 2.6 unless there is further feedback.

02/04/08 19:13:04 changed by tlpinney

  • attachment toolbar.patch added.

Patch described in the ticket

02/10/08 00:36:52 changed by tlpinney

  • attachment test_EditingToolbar.2.html added.

Added more tests.