Transformed
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
goog.provide('ol.interaction.Select');
|
||||
|
||||
goog.require('ol');
|
||||
goog.require('ol.CollectionEventType');
|
||||
goog.require('ol.array');
|
||||
goog.require('ol.events');
|
||||
goog.require('ol.events.Event');
|
||||
goog.require('ol.events.condition');
|
||||
goog.require('ol.functions');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
goog.require('ol.interaction.Interaction');
|
||||
goog.require('ol.layer.Vector');
|
||||
goog.require('ol.obj');
|
||||
goog.require('ol.source.Vector');
|
||||
goog.require('ol.style.Style');
|
||||
|
||||
/**
|
||||
* @module ol/interaction/Select
|
||||
*/
|
||||
import _ol_ from '../index.js';
|
||||
import _ol_CollectionEventType_ from '../CollectionEventType.js';
|
||||
import _ol_array_ from '../array.js';
|
||||
import _ol_events_ from '../events.js';
|
||||
import _ol_events_Event_ from '../events/Event.js';
|
||||
import _ol_events_condition_ from '../events/condition.js';
|
||||
import _ol_functions_ from '../functions.js';
|
||||
import _ol_geom_GeometryType_ from '../geom/GeometryType.js';
|
||||
import _ol_interaction_Interaction_ from '../interaction/Interaction.js';
|
||||
import _ol_layer_Vector_ from '../layer/Vector.js';
|
||||
import _ol_obj_ from '../obj.js';
|
||||
import _ol_source_Vector_ from '../source/Vector.js';
|
||||
import _ol_style_Style_ from '../style/Style.js';
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
@@ -33,10 +33,10 @@ goog.require('ol.style.Style');
|
||||
* @fires ol.interaction.Select.Event
|
||||
* @api
|
||||
*/
|
||||
ol.interaction.Select = function(opt_options) {
|
||||
var _ol_interaction_Select_ = function(opt_options) {
|
||||
|
||||
ol.interaction.Interaction.call(this, {
|
||||
handleEvent: ol.interaction.Select.handleEvent
|
||||
_ol_interaction_Interaction_.call(this, {
|
||||
handleEvent: _ol_interaction_Select_.handleEvent
|
||||
});
|
||||
|
||||
var options = opt_options ? opt_options : {};
|
||||
@@ -46,28 +46,28 @@ ol.interaction.Select = function(opt_options) {
|
||||
* @type {ol.EventsConditionType}
|
||||
*/
|
||||
this.condition_ = options.condition ?
|
||||
options.condition : ol.events.condition.singleClick;
|
||||
options.condition : _ol_events_condition_.singleClick;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.EventsConditionType}
|
||||
*/
|
||||
this.addCondition_ = options.addCondition ?
|
||||
options.addCondition : ol.events.condition.never;
|
||||
options.addCondition : _ol_events_condition_.never;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.EventsConditionType}
|
||||
*/
|
||||
this.removeCondition_ = options.removeCondition ?
|
||||
options.removeCondition : ol.events.condition.never;
|
||||
options.removeCondition : _ol_events_condition_.never;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.EventsConditionType}
|
||||
*/
|
||||
this.toggleCondition_ = options.toggleCondition ?
|
||||
options.toggleCondition : ol.events.condition.shiftKeyOnly;
|
||||
options.toggleCondition : _ol_events_condition_.shiftKeyOnly;
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -80,7 +80,7 @@ ol.interaction.Select = function(opt_options) {
|
||||
* @type {ol.SelectFilterFunction}
|
||||
*/
|
||||
this.filter_ = options.filter ? options.filter :
|
||||
ol.functions.TRUE;
|
||||
_ol_functions_.TRUE;
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -88,14 +88,14 @@ ol.interaction.Select = function(opt_options) {
|
||||
*/
|
||||
this.hitTolerance_ = options.hitTolerance ? options.hitTolerance : 0;
|
||||
|
||||
var featureOverlay = new ol.layer.Vector({
|
||||
source: new ol.source.Vector({
|
||||
var featureOverlay = new _ol_layer_Vector_({
|
||||
source: new _ol_source_Vector_({
|
||||
useSpatialIndex: false,
|
||||
features: options.features,
|
||||
wrapX: options.wrapX
|
||||
}),
|
||||
style: options.style ? options.style :
|
||||
ol.interaction.Select.getDefaultStyleFunction(),
|
||||
_ol_interaction_Select_.getDefaultStyleFunction(),
|
||||
updateWhileAnimating: true,
|
||||
updateWhileInteracting: true
|
||||
});
|
||||
@@ -114,11 +114,11 @@ ol.interaction.Select = function(opt_options) {
|
||||
} else {
|
||||
var layers = options.layers;
|
||||
layerFilter = function(layer) {
|
||||
return ol.array.includes(layers, layer);
|
||||
return _ol_array_.includes(layers, layer);
|
||||
};
|
||||
}
|
||||
} else {
|
||||
layerFilter = ol.functions.TRUE;
|
||||
layerFilter = _ol_functions_.TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,13 +136,14 @@ ol.interaction.Select = function(opt_options) {
|
||||
this.featureLayerAssociation_ = {};
|
||||
|
||||
var features = this.featureOverlay_.getSource().getFeaturesCollection();
|
||||
ol.events.listen(features, ol.CollectionEventType.ADD,
|
||||
_ol_events_.listen(features, _ol_CollectionEventType_.ADD,
|
||||
this.addFeature_, this);
|
||||
ol.events.listen(features, ol.CollectionEventType.REMOVE,
|
||||
_ol_events_.listen(features, _ol_CollectionEventType_.REMOVE,
|
||||
this.removeFeature_, this);
|
||||
|
||||
};
|
||||
ol.inherits(ol.interaction.Select, ol.interaction.Interaction);
|
||||
|
||||
_ol_.inherits(_ol_interaction_Select_, _ol_interaction_Interaction_);
|
||||
|
||||
|
||||
/**
|
||||
@@ -150,8 +151,8 @@ ol.inherits(ol.interaction.Select, ol.interaction.Interaction);
|
||||
* @param {ol.layer.Layer} layer Layer.
|
||||
* @private
|
||||
*/
|
||||
ol.interaction.Select.prototype.addFeatureLayerAssociation_ = function(feature, layer) {
|
||||
var key = ol.getUid(feature);
|
||||
_ol_interaction_Select_.prototype.addFeatureLayerAssociation_ = function(feature, layer) {
|
||||
var key = _ol_.getUid(feature);
|
||||
this.featureLayerAssociation_[key] = layer;
|
||||
};
|
||||
|
||||
@@ -161,7 +162,7 @@ ol.interaction.Select.prototype.addFeatureLayerAssociation_ = function(feature,
|
||||
* @return {ol.Collection.<ol.Feature>} Features collection.
|
||||
* @api
|
||||
*/
|
||||
ol.interaction.Select.prototype.getFeatures = function() {
|
||||
_ol_interaction_Select_.prototype.getFeatures = function() {
|
||||
return this.featureOverlay_.getSource().getFeaturesCollection();
|
||||
};
|
||||
|
||||
@@ -171,7 +172,7 @@ ol.interaction.Select.prototype.getFeatures = function() {
|
||||
* @returns {number} Hit tolerance in pixels.
|
||||
* @api
|
||||
*/
|
||||
ol.interaction.Select.prototype.getHitTolerance = function() {
|
||||
_ol_interaction_Select_.prototype.getHitTolerance = function() {
|
||||
return this.hitTolerance_;
|
||||
};
|
||||
|
||||
@@ -185,8 +186,8 @@ ol.interaction.Select.prototype.getHitTolerance = function() {
|
||||
* @return {ol.layer.Vector} Layer.
|
||||
* @api
|
||||
*/
|
||||
ol.interaction.Select.prototype.getLayer = function(feature) {
|
||||
var key = ol.getUid(feature);
|
||||
_ol_interaction_Select_.prototype.getLayer = function(feature) {
|
||||
var key = _ol_.getUid(feature);
|
||||
return /** @type {ol.layer.Vector} */ (this.featureLayerAssociation_[key]);
|
||||
};
|
||||
|
||||
@@ -199,7 +200,7 @@ ol.interaction.Select.prototype.getLayer = function(feature) {
|
||||
* @this {ol.interaction.Select}
|
||||
* @api
|
||||
*/
|
||||
ol.interaction.Select.handleEvent = function(mapBrowserEvent) {
|
||||
_ol_interaction_Select_.handleEvent = function(mapBrowserEvent) {
|
||||
if (!this.condition_(mapBrowserEvent)) {
|
||||
return true;
|
||||
}
|
||||
@@ -215,7 +216,7 @@ ol.interaction.Select.handleEvent = function(mapBrowserEvent) {
|
||||
// Replace the currently selected feature(s) with the feature(s) at the
|
||||
// pixel, or clear the selected feature(s) if there is no feature at
|
||||
// the pixel.
|
||||
ol.obj.clear(this.featureLayerAssociation_);
|
||||
_ol_obj_.clear(this.featureLayerAssociation_);
|
||||
map.forEachFeatureAtPixel(mapBrowserEvent.pixel,
|
||||
(
|
||||
/**
|
||||
@@ -260,11 +261,11 @@ ol.interaction.Select.handleEvent = function(mapBrowserEvent) {
|
||||
function(feature, layer) {
|
||||
if (this.filter_(feature, layer)) {
|
||||
if ((add || toggle) &&
|
||||
!ol.array.includes(features.getArray(), feature)) {
|
||||
!_ol_array_.includes(features.getArray(), feature)) {
|
||||
selected.push(feature);
|
||||
this.addFeatureLayerAssociation_(feature, layer);
|
||||
} else if ((remove || toggle) &&
|
||||
ol.array.includes(features.getArray(), feature)) {
|
||||
_ol_array_.includes(features.getArray(), feature)) {
|
||||
deselected.push(feature);
|
||||
this.removeFeatureLayerAssociation_(feature);
|
||||
}
|
||||
@@ -282,10 +283,10 @@ ol.interaction.Select.handleEvent = function(mapBrowserEvent) {
|
||||
}
|
||||
if (selected.length > 0 || deselected.length > 0) {
|
||||
this.dispatchEvent(
|
||||
new ol.interaction.Select.Event(ol.interaction.Select.EventType_.SELECT,
|
||||
new _ol_interaction_Select_.Event(_ol_interaction_Select_.EventType_.SELECT,
|
||||
selected, deselected, mapBrowserEvent));
|
||||
}
|
||||
return ol.events.condition.pointerMove(mapBrowserEvent);
|
||||
return _ol_events_condition_.pointerMove(mapBrowserEvent);
|
||||
};
|
||||
|
||||
|
||||
@@ -296,7 +297,7 @@ ol.interaction.Select.handleEvent = function(mapBrowserEvent) {
|
||||
* @param {number} hitTolerance Hit tolerance in pixels.
|
||||
* @api
|
||||
*/
|
||||
ol.interaction.Select.prototype.setHitTolerance = function(hitTolerance) {
|
||||
_ol_interaction_Select_.prototype.setHitTolerance = function(hitTolerance) {
|
||||
this.hitTolerance_ = hitTolerance;
|
||||
};
|
||||
|
||||
@@ -308,14 +309,14 @@ ol.interaction.Select.prototype.setHitTolerance = function(hitTolerance) {
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
ol.interaction.Select.prototype.setMap = function(map) {
|
||||
_ol_interaction_Select_.prototype.setMap = function(map) {
|
||||
var currentMap = this.getMap();
|
||||
var selectedFeatures =
|
||||
this.featureOverlay_.getSource().getFeaturesCollection();
|
||||
if (currentMap) {
|
||||
selectedFeatures.forEach(currentMap.unskipFeature, currentMap);
|
||||
}
|
||||
ol.interaction.Interaction.prototype.setMap.call(this, map);
|
||||
_ol_interaction_Interaction_.prototype.setMap.call(this, map);
|
||||
this.featureOverlay_.setMap(map);
|
||||
if (map) {
|
||||
selectedFeatures.forEach(map.skipFeature, map);
|
||||
@@ -326,12 +327,12 @@ ol.interaction.Select.prototype.setMap = function(map) {
|
||||
/**
|
||||
* @return {ol.StyleFunction} Styles.
|
||||
*/
|
||||
ol.interaction.Select.getDefaultStyleFunction = function() {
|
||||
var styles = ol.style.Style.createDefaultEditing();
|
||||
ol.array.extend(styles[ol.geom.GeometryType.POLYGON],
|
||||
styles[ol.geom.GeometryType.LINE_STRING]);
|
||||
ol.array.extend(styles[ol.geom.GeometryType.GEOMETRY_COLLECTION],
|
||||
styles[ol.geom.GeometryType.LINE_STRING]);
|
||||
_ol_interaction_Select_.getDefaultStyleFunction = function() {
|
||||
var styles = _ol_style_Style_.createDefaultEditing();
|
||||
_ol_array_.extend(styles[_ol_geom_GeometryType_.POLYGON],
|
||||
styles[_ol_geom_GeometryType_.LINE_STRING]);
|
||||
_ol_array_.extend(styles[_ol_geom_GeometryType_.GEOMETRY_COLLECTION],
|
||||
styles[_ol_geom_GeometryType_.LINE_STRING]);
|
||||
|
||||
return function(feature, resolution) {
|
||||
if (!feature.getGeometry()) {
|
||||
@@ -346,7 +347,7 @@ ol.interaction.Select.getDefaultStyleFunction = function() {
|
||||
* @param {ol.Collection.Event} evt Event.
|
||||
* @private
|
||||
*/
|
||||
ol.interaction.Select.prototype.addFeature_ = function(evt) {
|
||||
_ol_interaction_Select_.prototype.addFeature_ = function(evt) {
|
||||
var map = this.getMap();
|
||||
if (map) {
|
||||
map.skipFeature(/** @type {ol.Feature} */ (evt.element));
|
||||
@@ -358,7 +359,7 @@ ol.interaction.Select.prototype.addFeature_ = function(evt) {
|
||||
* @param {ol.Collection.Event} evt Event.
|
||||
* @private
|
||||
*/
|
||||
ol.interaction.Select.prototype.removeFeature_ = function(evt) {
|
||||
_ol_interaction_Select_.prototype.removeFeature_ = function(evt) {
|
||||
var map = this.getMap();
|
||||
if (map) {
|
||||
map.unskipFeature(/** @type {ol.Feature} */ (evt.element));
|
||||
@@ -370,8 +371,8 @@ ol.interaction.Select.prototype.removeFeature_ = function(evt) {
|
||||
* @param {ol.Feature|ol.render.Feature} feature Feature.
|
||||
* @private
|
||||
*/
|
||||
ol.interaction.Select.prototype.removeFeatureLayerAssociation_ = function(feature) {
|
||||
var key = ol.getUid(feature);
|
||||
_ol_interaction_Select_.prototype.removeFeatureLayerAssociation_ = function(feature) {
|
||||
var key = _ol_.getUid(feature);
|
||||
delete this.featureLayerAssociation_[key];
|
||||
};
|
||||
|
||||
@@ -390,8 +391,8 @@ ol.interaction.Select.prototype.removeFeatureLayerAssociation_ = function(featur
|
||||
* @extends {ol.events.Event}
|
||||
* @constructor
|
||||
*/
|
||||
ol.interaction.Select.Event = function(type, selected, deselected, mapBrowserEvent) {
|
||||
ol.events.Event.call(this, type);
|
||||
_ol_interaction_Select_.Event = function(type, selected, deselected, mapBrowserEvent) {
|
||||
_ol_events_Event_.call(this, type);
|
||||
|
||||
/**
|
||||
* Selected features array.
|
||||
@@ -414,14 +415,14 @@ ol.interaction.Select.Event = function(type, selected, deselected, mapBrowserEve
|
||||
*/
|
||||
this.mapBrowserEvent = mapBrowserEvent;
|
||||
};
|
||||
ol.inherits(ol.interaction.Select.Event, ol.events.Event);
|
||||
_ol_.inherits(_ol_interaction_Select_.Event, _ol_events_Event_);
|
||||
|
||||
|
||||
/**
|
||||
* @enum {string}
|
||||
* @private
|
||||
*/
|
||||
ol.interaction.Select.EventType_ = {
|
||||
_ol_interaction_Select_.EventType_ = {
|
||||
/**
|
||||
* Triggered when feature(s) has been (de)selected.
|
||||
* @event ol.interaction.Select.Event#select
|
||||
@@ -429,3 +430,4 @@ ol.interaction.Select.EventType_ = {
|
||||
*/
|
||||
SELECT: 'select'
|
||||
};
|
||||
export default _ol_interaction_Select_;
|
||||
|
||||
Reference in New Issue
Block a user