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

Jachym Cepicky jachym.cepicky at gmail.com
Wed Jul 11 09:34:42 EDT 2007


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
-- 
Jachym Cepicky
e-mail: jachym.cepicky at gmail.com
URL: http://les-ejk.cz
GPG: http://www.les-ejk.cz/pgp/jachym_cepicky-gpg.pub

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Toto je =?UTF-8?Q?digit=C3=A1ln=C4=9B?=
	=?ISO-8859-1?Q?_podepsan=E1?= =?UTF-8?Q?_=C4=8D=C3=A1st?=
	=?ISO-8859-1?Q?_zpr=E1vy?=
Url : http://lists.osgeo.org/pipermail/openlayers-users/attachments/20070711/3c94092f/attachment.bin


More information about the Users mailing list