[OpenLayers-Users] ctrl-z behaviour while editing linestring

Richard Duivenvoorde rdmailings at duif.net
Wed Jul 11 11:16:12 EDT 2007


Hi Jachym,

My problem is a little easier then yours I think. I know for sure there 
is always just one linestring in my drawinglayer/handler.

The clue from your code was that the handler has the current geometry 
you are drawing, couldn't find that myself :-o

I'm not a javascript guru either, but my (probably not so faulttolerant) 
little hack now is:

   var feature = myLineControl.handler.line;
   if(feature.geometry.components.length >1){
     var lineidx = feature.geometry.components.length-1;
     feature.geometry.removeComponent(
	feature.geometry.components[lineidx]);
     lineControl.handler.modifyFeature();
     lineControl.handler.drawFeature();
  }

It's maybe more clean to do it your way: make a new control.

Thanks for your help!

Richard Duivenvoorde

Jachym Cepicky wrote:
> Hi,
> 
> I have this - using [backspace] or [delete] buttons, which is IMHO more
> intuitive for normal users, than ctrl+anything
> 
> here part of the code:
> 
> [...]
> map.addControl(new OpenLayers.Control.KeyboardActions());
> 
> [...]
> 
> OpenLayers.Control.KeyboardActions = OpenLayers.Class.create();
> OpenLayers.Control.KeyboardActions.prototype =
> OpenLayers.Class.inherit( OpenLayers.Control, {
> 
>     /**
>      * @constructor
>      */
>     initialize: function() {
>         OpenLayers.Control.prototype.initialize.apply(this, arguments);
>     },
>     
>     /**
>      * 
>      */
>     destroy: function() {
>         if (this.handler) {
>             this.handler.destroy();
>         }        
>         this.handler = null;
>         
>         OpenLayers.Control.prototype.destroy.apply(this, arguments);
>     },
>     
>     /**
>      * 
>      */
>     draw: function() {
>         this.handler = new OpenLayers.Handler.Keyboard( this, { 
>                                 "keypress": this.defaultKeyPress });
>         this.activate();
>     },
>     
>     /**
>     * @param {Integer} code
>     */
>     defaultKeyPress: function (code) {
>         switch(code) {
>             case OpenLayers.Event.KEY_BACKSPACE:
>                 this.onBackspace();
>                 break;
>             case OpenLayers.Event.KEY_DELETE:
>                 this.onBackspace();
>                 break;
>             case OpenLayers.Event.KEY_ESC:
>                 this.onEsc();
>                 break;
>         } 
>     },
> 
>     onBackspace: function () {
> 
>         // are we digitizing something?
>         if (BNInfoButtons.polygonQuery.active) {
>             var feature = BNInfoButtons.polygonQuery.handler.polygon;
>             var polyidx = feature.geometry.components.length-1;
>             var pointidx =
> feature.geometry.components[polyidx].components.length-2;
>             var point =
> feature.geometry.components[polyidx].components[pointidx];
> 
> BNInfoButtons.polygonQuery.handler.line.geometry.removeComponent(point);
> 
> BNInfoButtons.polygonQuery.handler.polygon.geometry.removeComponent(point);
>             BNInfoButtons.polygonQuery.handler.drawFeature();
>         }
>     },
> 
>     onEsc: function () {
> 
>         // are we digitizing something?
>         if (BNInfoButtons.polygonQuery.active) {
>             BNQueryPanel.activateControl(BNInfoButtons.navigation);
>             BNQueryPanel.activateControl(BNInfoButtons.polygonQuery);
>         }
>     },
>     
>     /** @final @type String */
>     CLASS_NAME: "OpenLayers.Control.KeyboardActions"
> });
> 
> 
> Since I'm not a JavaScript coder (I'm actually no coder at all), I will
> be thankful for any comments.
> 
> Jachym
> 
> Richard Duivenvoorde píše v Út 10. 07. 2007 v 19:01 +0200:
>> Hi all,
>> while the editing of a feature is not yet available in 2.4 (by the way: 
>> any roadmap available for editing an excisting feature?), I thought it 
>> would be nice to have some 'undo' functionality. So while somebody is 
>> drawing a (sometimes rather large) linestring and does ctrl-Z or 
>> something like that, I want to grab the current linestring being edited, 
>> remove the last added point and draw the (one point shorter) linestring 
>> again.
>>
>> I thought this would be easy, but it isn't (  for me :-( ).
>> The Vector layer doesn't have the feature/geometry in it's hands while 
>> you are drawing it, and the point-callback get's a 'Point' as argument 
>> (instead of the Linestring?).
>> Have been looking into the source of the DrawFeature control and Path 
>> Handler, but couldn't find a hook.
>>
>> Somebody an idea for implementing this?
>>
>> TIA
>>
>> Richard Duivenvoorde
>> _______________________________________________
>> Users mailing list
>> Users at openlayers.org
>> http://openlayers.org/mailman/listinfo/users




More information about the Users mailing list