Ticket #1005 (closed feature: wontfix)

Opened 6 years ago

Last modified 4 years ago

allow customization of the tools that appear in the editing toolbar

Reported by: brentp Owned by: crschmidt
Priority: minor Milestone: 2.8 Release
Component: Control Version: 2.4
Keywords: Cc:
State:

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 Download (1.4 KB) - added by brentp 6 years ago.
start of tests for Editing toolbar
toolbar.patch Download (1.8 KB) - added by tlpinney 5 years ago.
Patch described in the ticket
test_EditingToolbar.2.html Download (2.3 KB) - added by tlpinney 5 years ago.
Added more tests.

Change History

Changed 6 years ago by crschmidt

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

Changed 6 years ago by brentp

start of tests for Editing toolbar

Changed 5 years ago by crschmidt

  • keywords needstests removed
  • state set to Needs More Work

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

Changed 5 years ago 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.

Changed 5 years ago by tlpinney

Patch described in the ticket

Changed 5 years ago by tlpinney

Added more tests.

Changed 5 years ago by euzuro

  • state changed from Needs More Work to Review

Changed 5 years ago by crschmidt

  • owner set to crschmidt
  • status changed from new to assigned

Changed 5 years ago by crschmidt

  • milestone changed from 2.7 Release to 2.8 Release

Changed 4 years ago by crschmidt

  • status changed from assigned to closed
  • state Review deleted
  • resolution set to wontfix

I know this is 18 months later, but I've thought for a while that this would be better solved by better documentation, I just didn't have a way to fix that. The reason is that people want more from the editing toolbar than just draw controls -- for example, SelectFeature and modify feature are common requests. So although this was an interesting set of work, it's insufficient for many of the common cases. Instead, I've added  http://docs.openlayers.org/library/controls#customizing-an-existing-panel , which documents how to recreate an existing panel with your own code -- and it falls under the 'under 10 lines of code' distinction I usually use to decide whether something is library-worthy or example worthy.

Thanks for the motivation to get this done, and sorry it took more than a year to do this.

Changed 4 years ago by tylere

There is a typo in the URL that points to the documentation on creating an editing toolbar. The correct URL is:  http://docs.openlayers.org/library/controls.html#customizing-an-existing-panel

Note: See TracTickets for help on using tickets.