better backwards compatibility -- only create the root container if
Control.SelectFeature constructor was called with an array of layers. r=crschmidt (closes #1666) git-svn-id: http://svn.openlayers.org/trunk/openlayers@9275 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -123,13 +123,16 @@ OpenLayers.Control.SelectFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
/**
|
||||
* Property: layer
|
||||
* {<OpenLayers.Layer.Vector>} The vector layer with a common renderer
|
||||
* root for all layers this control is configured with.
|
||||
* root for all layers this control is configured with (if an array of
|
||||
* layers was passed to the constructor), or the vector layer the control
|
||||
* was configured with (if a single layer was passed to the constructor).
|
||||
*/
|
||||
layer: null,
|
||||
|
||||
/**
|
||||
* Property: layers
|
||||
* {Array(<OpenLayers.Layer.Vector>} The layers this control will work on.
|
||||
* {Array(<OpenLayers.Layer.Vector>} The layers this control will work on,
|
||||
* or null if the control was configured with a single layer
|
||||
*/
|
||||
layers: null,
|
||||
|
||||
@@ -164,7 +167,8 @@ OpenLayers.Control.SelectFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
* Create a new control for selecting features.
|
||||
*
|
||||
* Parameters:
|
||||
* layers - {<OpenLayers.Layer.Vector>}, or an array of vector layers
|
||||
* layers - {<OpenLayers.Layer.Vector>}, or an array of vector layers. The
|
||||
* layer(s) this control will select features from.
|
||||
* options - {Object}
|
||||
*/
|
||||
initialize: function(layers, options) {
|
||||
@@ -174,15 +178,16 @@ OpenLayers.Control.SelectFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
OpenLayers.Control.prototype.EVENT_TYPES
|
||||
);
|
||||
OpenLayers.Control.prototype.initialize.apply(this, [options]);
|
||||
if(!(layers instanceof Array)) {
|
||||
layers = [layers];
|
||||
if(layers instanceof Array) {
|
||||
this.layers = layers;
|
||||
this.layer = new OpenLayers.Layer.Vector.RootContainer(
|
||||
this.id + "_container", {
|
||||
layers: layers
|
||||
}
|
||||
);
|
||||
} else {
|
||||
this.layer = layers;
|
||||
}
|
||||
this.layers = layers;
|
||||
this.layer = new OpenLayers.Layer.Vector.RootContainer(
|
||||
this.id + "_container", {
|
||||
layers: layers
|
||||
}
|
||||
);
|
||||
var callbacks = {
|
||||
click: this.clickFeature,
|
||||
clickout: this.clickoutFeature
|
||||
@@ -213,7 +218,9 @@ OpenLayers.Control.SelectFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
*/
|
||||
destroy: function() {
|
||||
OpenLayers.Control.prototype.destroy.apply(this, arguments);
|
||||
this.layer.destroy();
|
||||
if(this.layers) {
|
||||
this.layer.destroy();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -225,7 +232,9 @@ OpenLayers.Control.SelectFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
*/
|
||||
activate: function () {
|
||||
if (!this.active) {
|
||||
this.map.addLayer(this.layer);
|
||||
if(this.layers) {
|
||||
this.map.addLayer(this.layer);
|
||||
}
|
||||
this.handlers.feature.activate();
|
||||
if(this.box && this.handlers.box) {
|
||||
this.handlers.box.activate();
|
||||
@@ -249,7 +258,9 @@ OpenLayers.Control.SelectFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
if(this.handlers.box) {
|
||||
this.handlers.box.deactivate();
|
||||
}
|
||||
this.map.removeLayer(this.layer);
|
||||
if(this.layers) {
|
||||
this.map.removeLayer(this.layer);
|
||||
}
|
||||
}
|
||||
return OpenLayers.Control.prototype.deactivate.apply(
|
||||
this, arguments
|
||||
@@ -266,9 +277,10 @@ OpenLayers.Control.SelectFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
*/
|
||||
unselectAll: function(options) {
|
||||
// we'll want an option to supress notification here
|
||||
var layers = this.layers || [this.layer];
|
||||
var layer, feature;
|
||||
for(var l=0; l<this.layers.length; ++l) {
|
||||
layer = this.layers[l];
|
||||
for(var l=0; l<layers.length; ++l) {
|
||||
layer = layers[l];
|
||||
for(var i=layer.selectedFeatures.length-1; i>=0; --i) {
|
||||
feature = layer.selectedFeatures[i];
|
||||
if(!options || options.except != feature) {
|
||||
@@ -455,7 +467,6 @@ OpenLayers.Control.SelectFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
});
|
||||
if(cont !== false) {
|
||||
layer.selectedFeatures.push(feature);
|
||||
this.layerData = {};
|
||||
this.highlight(feature);
|
||||
layer.events.triggerEvent("featureselected", {feature: feature});
|
||||
this.onSelect.call(this.scope, feature);
|
||||
@@ -508,9 +519,10 @@ OpenLayers.Control.SelectFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
// because we're using a box, we consider we want multiple selection
|
||||
var prevMultiple = this.multiple;
|
||||
this.multiple = true;
|
||||
var layers = this.layers || [this.layer];
|
||||
var layer;
|
||||
for(var l=0; l<this.layers.length; ++l) {
|
||||
layer = this.layers[l];
|
||||
for(var l=0; l<layers.length; ++l) {
|
||||
layer = layers[l];
|
||||
for(var i=0, len = layer.features.length; i<len; ++i) {
|
||||
var feature = layer.features[i];
|
||||
if (this.geometryTypes == null || OpenLayers.Util.indexOf(
|
||||
|
||||
Reference in New Issue
Block a user