Raise layer that's being modified
This commit is contained in:
@@ -277,6 +277,13 @@ OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
* Take care of things that are not handled in superclass.
|
* Take care of things that are not handled in superclass.
|
||||||
*/
|
*/
|
||||||
destroy: function() {
|
destroy: function() {
|
||||||
|
if (this.map) {
|
||||||
|
this.map.events.un({
|
||||||
|
"removelayer": this.handleMapEvents,
|
||||||
|
"changelayer": this.handleMapEvents,
|
||||||
|
scope: this
|
||||||
|
});
|
||||||
|
}
|
||||||
this.layer = null;
|
this.layer = null;
|
||||||
OpenLayers.Control.prototype.destroy.apply(this, []);
|
OpenLayers.Control.prototype.destroy.apply(this, []);
|
||||||
},
|
},
|
||||||
@@ -289,6 +296,12 @@ OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
* {Boolean} Successfully activated the control.
|
* {Boolean} Successfully activated the control.
|
||||||
*/
|
*/
|
||||||
activate: function() {
|
activate: function() {
|
||||||
|
this.moveLayerToTop();
|
||||||
|
this.map.events.on({
|
||||||
|
"removelayer": this.handleMapEvents,
|
||||||
|
"changelayer": this.handleMapEvents,
|
||||||
|
scope: this
|
||||||
|
});
|
||||||
return (this.handlers.keyboard.activate() &&
|
return (this.handlers.keyboard.activate() &&
|
||||||
this.handlers.drag.activate() &&
|
this.handlers.drag.activate() &&
|
||||||
OpenLayers.Control.prototype.activate.apply(this, arguments));
|
OpenLayers.Control.prototype.activate.apply(this, arguments));
|
||||||
@@ -305,6 +318,12 @@ OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
var deactivated = false;
|
var deactivated = false;
|
||||||
// the return from the controls is unimportant in this case
|
// the return from the controls is unimportant in this case
|
||||||
if(OpenLayers.Control.prototype.deactivate.apply(this, arguments)) {
|
if(OpenLayers.Control.prototype.deactivate.apply(this, arguments)) {
|
||||||
|
this.moveLayerBack();
|
||||||
|
this.map.events.un({
|
||||||
|
"removelayer": this.handleMapEvents,
|
||||||
|
"changelayer": this.handleMapEvents,
|
||||||
|
scope: this
|
||||||
|
});
|
||||||
this.layer.removeFeatures(this.vertices, {silent: true});
|
this.layer.removeFeatures(this.vertices, {silent: true});
|
||||||
this.layer.removeFeatures(this.virtualVertices, {silent: true});
|
this.layer.removeFeatures(this.virtualVertices, {silent: true});
|
||||||
this.vertices = [];
|
this.vertices = [];
|
||||||
@@ -750,6 +769,45 @@ OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
OpenLayers.Control.prototype.setMap.apply(this, arguments);
|
OpenLayers.Control.prototype.setMap.apply(this, arguments);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: handleMapEvents
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* evt - {Object}
|
||||||
|
*/
|
||||||
|
handleMapEvents: function(evt) {
|
||||||
|
if (evt.type == "removelayer" || evt.property == "order") {
|
||||||
|
this.moveLayerToTop();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: moveLayerToTop
|
||||||
|
* Moves the layer for this handler to the top, so mouse events can reach
|
||||||
|
* it.
|
||||||
|
*/
|
||||||
|
moveLayerToTop: function() {
|
||||||
|
var index = Math.max(this.map.Z_INDEX_BASE['Feature'] - 1,
|
||||||
|
this.layer.getZIndex()) + 1;
|
||||||
|
this.layer.setZIndex(index);
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: moveLayerBack
|
||||||
|
* Moves the layer back to the position determined by the map's layers
|
||||||
|
* array.
|
||||||
|
*/
|
||||||
|
moveLayerBack: function() {
|
||||||
|
var index = this.layer.getZIndex() - 1;
|
||||||
|
if (index >= this.map.Z_INDEX_BASE['Feature']) {
|
||||||
|
this.layer.setZIndex(index);
|
||||||
|
} else {
|
||||||
|
this.map.setLayerZIndex(this.layer,
|
||||||
|
this.map.getLayerIndex(this.layer));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
CLASS_NAME: "OpenLayers.Control.ModifyFeature"
|
CLASS_NAME: "OpenLayers.Control.ModifyFeature"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -802,6 +802,20 @@
|
|||||||
control.destroy();
|
control.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_moveLayerToTop_moveLayerBack(t) {
|
||||||
|
t.plan(2);
|
||||||
|
var map = new OpenLayers.Map("map");
|
||||||
|
var layer1 = new OpenLayers.Layer.Vector();
|
||||||
|
var layer2 = new OpenLayers.Layer.Vector();
|
||||||
|
map.addLayers([layer1, layer2]);
|
||||||
|
var control = new OpenLayers.Control.ModifyFeature(layer1);
|
||||||
|
map.addControl(control);
|
||||||
|
control.activate();
|
||||||
|
t.ok(layer1.div.style.zIndex > layer2.div.style.zIndex, "layer raised so events don't get swallowed");
|
||||||
|
control.deactivate();
|
||||||
|
t.ok(layer1.div.style.zIndex < layer2.div.style.zIndex, 'layer order restored on deactivation');
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
Reference in New Issue
Block a user