Add 'getLayer()' method to 'ol.interaction.Select'
This commit is contained in:
committed by
Andreas Hocevar
parent
094f8d5391
commit
85163bceb6
@@ -179,9 +179,9 @@ ol.interaction.Select = function(opt_options) {
|
|||||||
* An association between selected feature (key)
|
* An association between selected feature (key)
|
||||||
* and layer (value)
|
* and layer (value)
|
||||||
* @private
|
* @private
|
||||||
* @type {Array.<ol.layer.Vector>}
|
* @type {Object.<number, ol.layer.Layer>}
|
||||||
*/
|
*/
|
||||||
this.featureLayerAssociation_ = [];
|
this.featureLayerAssociation_ = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@@ -217,9 +217,7 @@ goog.inherits(ol.interaction.Select, ol.interaction.Interaction);
|
|||||||
ol.interaction.Select.prototype.addFeatureLayerAssociation_ =
|
ol.interaction.Select.prototype.addFeatureLayerAssociation_ =
|
||||||
function(feature, layer) {
|
function(feature, layer) {
|
||||||
var key = goog.getUid(feature);
|
var key = goog.getUid(feature);
|
||||||
var obj = {};
|
this.featureLayerAssociation_[key] = layer;
|
||||||
obj[key] = layer;
|
|
||||||
this.featureLayerAssociation_.push(obj);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -243,14 +241,8 @@ ol.interaction.Select.prototype.getFeatures = function() {
|
|||||||
ol.interaction.Select.prototype.getLayer = function(feature) {
|
ol.interaction.Select.prototype.getLayer = function(feature) {
|
||||||
goog.asserts.assertInstanceof(feature, ol.Feature,
|
goog.asserts.assertInstanceof(feature, ol.Feature,
|
||||||
'feature should be an ol.Feature');
|
'feature should be an ol.Feature');
|
||||||
var key = goog.getUid(feature).toString();
|
var key = goog.getUid(feature);
|
||||||
var found = goog.array.find(this.featureLayerAssociation_, function(each) {
|
return /** @type {ol.layer.Vector} */ (this.featureLayerAssociation_[key]);
|
||||||
if (key == goog.object.getKeys(each)[0]) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
return /** @type {ol.layer.Vector} */ (goog.object.getValues(found)[0]);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -301,9 +293,9 @@ ol.interaction.Select.handleEvent = function(mapBrowserEvent) {
|
|||||||
features.clear();
|
features.clear();
|
||||||
}
|
}
|
||||||
features.extend(selected);
|
features.extend(selected);
|
||||||
// Modify array featureLayerAssociation_
|
// Modify object this.featureLayerAssociation_
|
||||||
if (selected.length === 0) {
|
if (selected.length === 0) {
|
||||||
this.featureLayerAssociation_.length = 0;
|
goog.object.clear(this.featureLayerAssociation_);
|
||||||
} else {
|
} else {
|
||||||
if (deselected.length > 0) {
|
if (deselected.length > 0) {
|
||||||
deselected.forEach(function(feature) {
|
deselected.forEach(function(feature) {
|
||||||
@@ -426,12 +418,5 @@ ol.interaction.Select.prototype.removeFeature_ = function(evt) {
|
|||||||
ol.interaction.Select.prototype.removeFeatureLayerAssociation_ =
|
ol.interaction.Select.prototype.removeFeatureLayerAssociation_ =
|
||||||
function(feature) {
|
function(feature) {
|
||||||
var key = goog.getUid(feature);
|
var key = goog.getUid(feature);
|
||||||
var index = goog.array.findIndex(this.featureLayerAssociation_,
|
delete this.featureLayerAssociation_[key];
|
||||||
function(each) {
|
|
||||||
if (key == goog.object.getKeys(each)[0]) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
this.featureLayerAssociation_.splice(index, 1);
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user