Automated class transform
npx lebab --replace src --transform class
This commit is contained in:
+172
-178
@@ -51,198 +51,192 @@ const Property = {
|
||||
* @param {module:ol/layer/Group~Options=} opt_options Layer options.
|
||||
* @api
|
||||
*/
|
||||
const LayerGroup = function(opt_options) {
|
||||
class LayerGroup {
|
||||
constructor(opt_options) {
|
||||
|
||||
const options = opt_options || {};
|
||||
const baseOptions = /** @type {module:ol/layer/Group~Options} */ (assign({}, options));
|
||||
delete baseOptions.layers;
|
||||
const options = opt_options || {};
|
||||
const baseOptions = /** @type {module:ol/layer/Group~Options} */ (assign({}, options));
|
||||
delete baseOptions.layers;
|
||||
|
||||
let layers = options.layers;
|
||||
let layers = options.layers;
|
||||
|
||||
BaseLayer.call(this, baseOptions);
|
||||
BaseLayer.call(this, baseOptions);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<module:ol/events~EventsKey>}
|
||||
*/
|
||||
this.layersListenerKeys_ = [];
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<module:ol/events~EventsKey>}
|
||||
*/
|
||||
this.layersListenerKeys_ = [];
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Object.<string, Array.<module:ol/events~EventsKey>>}
|
||||
*/
|
||||
this.listenerKeys_ = {};
|
||||
/**
|
||||
* @private
|
||||
* @type {Object.<string, Array.<module:ol/events~EventsKey>>}
|
||||
*/
|
||||
this.listenerKeys_ = {};
|
||||
|
||||
listen(this,
|
||||
getChangeEventType(Property.LAYERS),
|
||||
this.handleLayersChanged_, this);
|
||||
listen(this,
|
||||
getChangeEventType(Property.LAYERS),
|
||||
this.handleLayersChanged_, this);
|
||||
|
||||
if (layers) {
|
||||
if (Array.isArray(layers)) {
|
||||
layers = new Collection(layers.slice(), {unique: true});
|
||||
if (layers) {
|
||||
if (Array.isArray(layers)) {
|
||||
layers = new Collection(layers.slice(), {unique: true});
|
||||
} else {
|
||||
assert(layers instanceof Collection,
|
||||
43); // Expected `layers` to be an array or a `Collection`
|
||||
layers = layers;
|
||||
}
|
||||
} else {
|
||||
assert(layers instanceof Collection,
|
||||
43); // Expected `layers` to be an array or a `Collection`
|
||||
layers = layers;
|
||||
layers = new Collection(undefined, {unique: true});
|
||||
}
|
||||
} else {
|
||||
layers = new Collection(undefined, {unique: true});
|
||||
|
||||
this.setLayers(layers);
|
||||
|
||||
}
|
||||
|
||||
this.setLayers(layers);
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
handleLayerChange_() {
|
||||
this.changed();
|
||||
}
|
||||
|
||||
};
|
||||
/**
|
||||
* @param {module:ol/events/Event} event Event.
|
||||
* @private
|
||||
*/
|
||||
handleLayersChanged_(event) {
|
||||
this.layersListenerKeys_.forEach(unlistenByKey);
|
||||
this.layersListenerKeys_.length = 0;
|
||||
|
||||
const layers = this.getLayers();
|
||||
this.layersListenerKeys_.push(
|
||||
listen(layers, CollectionEventType.ADD, this.handleLayersAdd_, this),
|
||||
listen(layers, CollectionEventType.REMOVE, this.handleLayersRemove_, this)
|
||||
);
|
||||
|
||||
for (const id in this.listenerKeys_) {
|
||||
this.listenerKeys_[id].forEach(unlistenByKey);
|
||||
}
|
||||
clear(this.listenerKeys_);
|
||||
|
||||
const layersArray = layers.getArray();
|
||||
for (let i = 0, ii = layersArray.length; i < ii; i++) {
|
||||
const layer = layersArray[i];
|
||||
this.listenerKeys_[getUid(layer).toString()] = [
|
||||
listen(layer, ObjectEventType.PROPERTYCHANGE, this.handleLayerChange_, this),
|
||||
listen(layer, EventType.CHANGE, this.handleLayerChange_, this)
|
||||
];
|
||||
}
|
||||
|
||||
this.changed();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {module:ol/Collection~CollectionEvent} collectionEvent CollectionEvent.
|
||||
* @private
|
||||
*/
|
||||
handleLayersAdd_(collectionEvent) {
|
||||
const layer = /** @type {module:ol/layer/Base} */ (collectionEvent.element);
|
||||
const key = getUid(layer).toString();
|
||||
this.listenerKeys_[key] = [
|
||||
listen(layer, ObjectEventType.PROPERTYCHANGE, this.handleLayerChange_, this),
|
||||
listen(layer, EventType.CHANGE, this.handleLayerChange_, this)
|
||||
];
|
||||
this.changed();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {module:ol/Collection~CollectionEvent} collectionEvent CollectionEvent.
|
||||
* @private
|
||||
*/
|
||||
handleLayersRemove_(collectionEvent) {
|
||||
const layer = /** @type {module:ol/layer/Base} */ (collectionEvent.element);
|
||||
const key = getUid(layer).toString();
|
||||
this.listenerKeys_[key].forEach(unlistenByKey);
|
||||
delete this.listenerKeys_[key];
|
||||
this.changed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link module:ol/Collection collection} of {@link module:ol/layer/Layer~Layer layers}
|
||||
* in this group.
|
||||
* @return {!module:ol/Collection.<module:ol/layer/Base>} Collection of
|
||||
* {@link module:ol/layer/Base layers} that are part of this group.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
getLayers() {
|
||||
return (
|
||||
/** @type {!module:ol/Collection.<module:ol/layer/Base>} */ (this.get(Property.LAYERS))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@link module:ol/Collection collection} of {@link module:ol/layer/Layer~Layer layers}
|
||||
* in this group.
|
||||
* @param {!module:ol/Collection.<module:ol/layer/Base>} layers Collection of
|
||||
* {@link module:ol/layer/Base layers} that are part of this group.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
setLayers(layers) {
|
||||
this.set(Property.LAYERS, layers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
getLayersArray(opt_array) {
|
||||
const array = opt_array !== undefined ? opt_array : [];
|
||||
this.getLayers().forEach(function(layer) {
|
||||
layer.getLayersArray(array);
|
||||
});
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
getLayerStatesArray(opt_states) {
|
||||
const states = opt_states !== undefined ? opt_states : [];
|
||||
|
||||
const pos = states.length;
|
||||
|
||||
this.getLayers().forEach(function(layer) {
|
||||
layer.getLayerStatesArray(states);
|
||||
});
|
||||
|
||||
const ownLayerState = this.getLayerState();
|
||||
for (let i = pos, ii = states.length; i < ii; i++) {
|
||||
const layerState = states[i];
|
||||
layerState.opacity *= ownLayerState.opacity;
|
||||
layerState.visible = layerState.visible && ownLayerState.visible;
|
||||
layerState.maxResolution = Math.min(
|
||||
layerState.maxResolution, ownLayerState.maxResolution);
|
||||
layerState.minResolution = Math.max(
|
||||
layerState.minResolution, ownLayerState.minResolution);
|
||||
if (ownLayerState.extent !== undefined) {
|
||||
if (layerState.extent !== undefined) {
|
||||
layerState.extent = getIntersection(layerState.extent, ownLayerState.extent);
|
||||
} else {
|
||||
layerState.extent = ownLayerState.extent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return states;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
getSourceState() {
|
||||
return SourceState.READY;
|
||||
}
|
||||
}
|
||||
|
||||
inherits(LayerGroup, BaseLayer);
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
LayerGroup.prototype.handleLayerChange_ = function() {
|
||||
this.changed();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {module:ol/events/Event} event Event.
|
||||
* @private
|
||||
*/
|
||||
LayerGroup.prototype.handleLayersChanged_ = function(event) {
|
||||
this.layersListenerKeys_.forEach(unlistenByKey);
|
||||
this.layersListenerKeys_.length = 0;
|
||||
|
||||
const layers = this.getLayers();
|
||||
this.layersListenerKeys_.push(
|
||||
listen(layers, CollectionEventType.ADD, this.handleLayersAdd_, this),
|
||||
listen(layers, CollectionEventType.REMOVE, this.handleLayersRemove_, this)
|
||||
);
|
||||
|
||||
for (const id in this.listenerKeys_) {
|
||||
this.listenerKeys_[id].forEach(unlistenByKey);
|
||||
}
|
||||
clear(this.listenerKeys_);
|
||||
|
||||
const layersArray = layers.getArray();
|
||||
for (let i = 0, ii = layersArray.length; i < ii; i++) {
|
||||
const layer = layersArray[i];
|
||||
this.listenerKeys_[getUid(layer).toString()] = [
|
||||
listen(layer, ObjectEventType.PROPERTYCHANGE, this.handleLayerChange_, this),
|
||||
listen(layer, EventType.CHANGE, this.handleLayerChange_, this)
|
||||
];
|
||||
}
|
||||
|
||||
this.changed();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {module:ol/Collection~CollectionEvent} collectionEvent CollectionEvent.
|
||||
* @private
|
||||
*/
|
||||
LayerGroup.prototype.handleLayersAdd_ = function(collectionEvent) {
|
||||
const layer = /** @type {module:ol/layer/Base} */ (collectionEvent.element);
|
||||
const key = getUid(layer).toString();
|
||||
this.listenerKeys_[key] = [
|
||||
listen(layer, ObjectEventType.PROPERTYCHANGE, this.handleLayerChange_, this),
|
||||
listen(layer, EventType.CHANGE, this.handleLayerChange_, this)
|
||||
];
|
||||
this.changed();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {module:ol/Collection~CollectionEvent} collectionEvent CollectionEvent.
|
||||
* @private
|
||||
*/
|
||||
LayerGroup.prototype.handleLayersRemove_ = function(collectionEvent) {
|
||||
const layer = /** @type {module:ol/layer/Base} */ (collectionEvent.element);
|
||||
const key = getUid(layer).toString();
|
||||
this.listenerKeys_[key].forEach(unlistenByKey);
|
||||
delete this.listenerKeys_[key];
|
||||
this.changed();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns the {@link module:ol/Collection collection} of {@link module:ol/layer/Layer~Layer layers}
|
||||
* in this group.
|
||||
* @return {!module:ol/Collection.<module:ol/layer/Base>} Collection of
|
||||
* {@link module:ol/layer/Base layers} that are part of this group.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
LayerGroup.prototype.getLayers = function() {
|
||||
return (
|
||||
/** @type {!module:ol/Collection.<module:ol/layer/Base>} */ (this.get(Property.LAYERS))
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the {@link module:ol/Collection collection} of {@link module:ol/layer/Layer~Layer layers}
|
||||
* in this group.
|
||||
* @param {!module:ol/Collection.<module:ol/layer/Base>} layers Collection of
|
||||
* {@link module:ol/layer/Base layers} that are part of this group.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
LayerGroup.prototype.setLayers = function(layers) {
|
||||
this.set(Property.LAYERS, layers);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
LayerGroup.prototype.getLayersArray = function(opt_array) {
|
||||
const array = opt_array !== undefined ? opt_array : [];
|
||||
this.getLayers().forEach(function(layer) {
|
||||
layer.getLayersArray(array);
|
||||
});
|
||||
return array;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
LayerGroup.prototype.getLayerStatesArray = function(opt_states) {
|
||||
const states = opt_states !== undefined ? opt_states : [];
|
||||
|
||||
const pos = states.length;
|
||||
|
||||
this.getLayers().forEach(function(layer) {
|
||||
layer.getLayerStatesArray(states);
|
||||
});
|
||||
|
||||
const ownLayerState = this.getLayerState();
|
||||
for (let i = pos, ii = states.length; i < ii; i++) {
|
||||
const layerState = states[i];
|
||||
layerState.opacity *= ownLayerState.opacity;
|
||||
layerState.visible = layerState.visible && ownLayerState.visible;
|
||||
layerState.maxResolution = Math.min(
|
||||
layerState.maxResolution, ownLayerState.maxResolution);
|
||||
layerState.minResolution = Math.max(
|
||||
layerState.minResolution, ownLayerState.minResolution);
|
||||
if (ownLayerState.extent !== undefined) {
|
||||
if (layerState.extent !== undefined) {
|
||||
layerState.extent = getIntersection(layerState.extent, ownLayerState.extent);
|
||||
} else {
|
||||
layerState.extent = ownLayerState.extent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return states;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
LayerGroup.prototype.getSourceState = function() {
|
||||
return SourceState.READY;
|
||||
};
|
||||
|
||||
export default LayerGroup;
|
||||
|
||||
Reference in New Issue
Block a user