[OpenLayers-Users] copy selected features and paste in the same layer

summer7310 xia-huadong at 163.com
Thu Sep 5 07:10:02 PDT 2013


I try to create a class about copy function,but it seems does not work.
 OpenLayers.Control.Copy = OpenLayers.Class(OpenLayers.Control, {
    initialize: function(vectorLayer, mousePositionCtl) {
        this.layer = vectorLayer;
        this.mousePositionCtl = mousePositionCtl;
        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, { 
                                "keydown": this.defaultKeyPress }, {
                                "keyMask": OpenLayers.Handler.MOD_CTRL
                                });
        this.activate();
    },
    defaultKeyPress: function (evt) {      
        switch(evt.keyCode) {
            case 86:
                var vector = this.layer.selectedFeatures[0];
                if(vector) {
                    var lonLat =
this.layer.map.getLonLatFromPixel(this.mousePositionCtl.lastXy);
                    var newVector = vector.clone();
                    this.layer.addFeatures([newVector]);
                    newVector.move(lonLat);
                }
        } 
    },
    CLASS_NAME: "OpenLayers.Control.Copy"
});




If any one has some suggestions ,thanks 



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/copy-selected-features-and-paste-in-the-same-layer-tp5075429p5076242.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.


More information about the Users mailing list