275 lines
7.9 KiB
JavaScript
275 lines
7.9 KiB
JavaScript
import {
|
|
CollectionEventType_default,
|
|
Collection_default
|
|
} from "./chunk-F6XZ22ZQ.js";
|
|
import {
|
|
Base_default
|
|
} from "./chunk-S5OMZ56B.js";
|
|
import {
|
|
getIntersection
|
|
} from "./chunk-CKDBVGKM.js";
|
|
import {
|
|
assert
|
|
} from "./chunk-QFCIXVZ3.js";
|
|
import {
|
|
ObjectEventType_default,
|
|
getUid
|
|
} from "./chunk-H47PV7W6.js";
|
|
import {
|
|
EventType_default,
|
|
Event_default,
|
|
listen,
|
|
unlistenByKey
|
|
} from "./chunk-KJXIHBKT.js";
|
|
import {
|
|
clear
|
|
} from "./chunk-5RHQVMYD.js";
|
|
|
|
// node_modules/ol/layer/Group.js
|
|
var GroupEvent = class extends Event_default {
|
|
/**
|
|
* @param {GroupEventType} type The event type.
|
|
* @param {BaseLayer} layer The layer.
|
|
*/
|
|
constructor(type, layer) {
|
|
super(type);
|
|
this.layer = layer;
|
|
}
|
|
};
|
|
var Property = {
|
|
LAYERS: "layers"
|
|
};
|
|
var LayerGroup = class _LayerGroup extends Base_default {
|
|
/**
|
|
* @param {Options} [options] Layer options.
|
|
*/
|
|
constructor(options) {
|
|
options = options || {};
|
|
const baseOptions = (
|
|
/** @type {Options} */
|
|
Object.assign({}, options)
|
|
);
|
|
delete baseOptions.layers;
|
|
let layers = options.layers;
|
|
super(baseOptions);
|
|
this.on;
|
|
this.once;
|
|
this.un;
|
|
this.layersListenerKeys_ = [];
|
|
this.listenerKeys_ = {};
|
|
this.addChangeListener(Property.LAYERS, this.handleLayersChanged_);
|
|
if (layers) {
|
|
if (Array.isArray(layers)) {
|
|
layers = new Collection_default(layers.slice(), { unique: true });
|
|
} else {
|
|
assert(
|
|
typeof /** @type {?} */
|
|
layers.getArray === "function",
|
|
"Expected `layers` to be an array or a `Collection`"
|
|
);
|
|
}
|
|
} else {
|
|
layers = new Collection_default(void 0, { unique: true });
|
|
}
|
|
this.setLayers(layers);
|
|
}
|
|
/**
|
|
* @private
|
|
*/
|
|
handleLayerChange_() {
|
|
this.changed();
|
|
}
|
|
/**
|
|
* @private
|
|
*/
|
|
handleLayersChanged_() {
|
|
this.layersListenerKeys_.forEach(unlistenByKey);
|
|
this.layersListenerKeys_.length = 0;
|
|
const layers = this.getLayers();
|
|
this.layersListenerKeys_.push(
|
|
listen(layers, CollectionEventType_default.ADD, this.handleLayersAdd_, this),
|
|
listen(
|
|
layers,
|
|
CollectionEventType_default.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.registerLayerListeners_(layer);
|
|
this.dispatchEvent(new GroupEvent("addlayer", layer));
|
|
}
|
|
this.changed();
|
|
}
|
|
/**
|
|
* @param {BaseLayer} layer The layer.
|
|
*/
|
|
registerLayerListeners_(layer) {
|
|
const listenerKeys = [
|
|
listen(
|
|
layer,
|
|
ObjectEventType_default.PROPERTYCHANGE,
|
|
this.handleLayerChange_,
|
|
this
|
|
),
|
|
listen(layer, EventType_default.CHANGE, this.handleLayerChange_, this)
|
|
];
|
|
if (layer instanceof _LayerGroup) {
|
|
listenerKeys.push(
|
|
listen(layer, "addlayer", this.handleLayerGroupAdd_, this),
|
|
listen(layer, "removelayer", this.handleLayerGroupRemove_, this)
|
|
);
|
|
}
|
|
this.listenerKeys_[getUid(layer)] = listenerKeys;
|
|
}
|
|
/**
|
|
* @param {GroupEvent} event The layer group event.
|
|
*/
|
|
handleLayerGroupAdd_(event) {
|
|
this.dispatchEvent(new GroupEvent("addlayer", event.layer));
|
|
}
|
|
/**
|
|
* @param {GroupEvent} event The layer group event.
|
|
*/
|
|
handleLayerGroupRemove_(event) {
|
|
this.dispatchEvent(new GroupEvent("removelayer", event.layer));
|
|
}
|
|
/**
|
|
* @param {import("../Collection.js").CollectionEvent<import("./Base.js").default>} collectionEvent CollectionEvent.
|
|
* @private
|
|
*/
|
|
handleLayersAdd_(collectionEvent) {
|
|
const layer = collectionEvent.element;
|
|
this.registerLayerListeners_(layer);
|
|
this.dispatchEvent(new GroupEvent("addlayer", layer));
|
|
this.changed();
|
|
}
|
|
/**
|
|
* @param {import("../Collection.js").CollectionEvent<import("./Base.js").default>} collectionEvent CollectionEvent.
|
|
* @private
|
|
*/
|
|
handleLayersRemove_(collectionEvent) {
|
|
const layer = collectionEvent.element;
|
|
const key = getUid(layer);
|
|
this.listenerKeys_[key].forEach(unlistenByKey);
|
|
delete this.listenerKeys_[key];
|
|
this.dispatchEvent(new GroupEvent("removelayer", layer));
|
|
this.changed();
|
|
}
|
|
/**
|
|
* Returns the {@link module:ol/Collection~Collection collection} of {@link module:ol/layer/Layer~Layer layers}
|
|
* in this group.
|
|
* @return {!Collection<import("./Base.js").default>} Collection of
|
|
* {@link module:ol/layer/Base~BaseLayer layers} that are part of this group.
|
|
* @observable
|
|
* @api
|
|
*/
|
|
getLayers() {
|
|
return (
|
|
/** @type {!Collection<import("./Base.js").default>} */
|
|
this.get(Property.LAYERS)
|
|
);
|
|
}
|
|
/**
|
|
* Set the {@link module:ol/Collection~Collection collection} of {@link module:ol/layer/Layer~Layer layers}
|
|
* in this group.
|
|
* @param {!Collection<import("./Base.js").default>} layers Collection of
|
|
* {@link module:ol/layer/Base~BaseLayer layers} that are part of this group.
|
|
* @observable
|
|
* @api
|
|
*/
|
|
setLayers(layers) {
|
|
const collection = this.getLayers();
|
|
if (collection) {
|
|
const currentLayers = collection.getArray();
|
|
for (let i = 0, ii = currentLayers.length; i < ii; ++i) {
|
|
this.dispatchEvent(new GroupEvent("removelayer", currentLayers[i]));
|
|
}
|
|
}
|
|
this.set(Property.LAYERS, layers);
|
|
}
|
|
/**
|
|
* @param {Array<import("./Layer.js").default>} [array] Array of layers (to be modified in place).
|
|
* @return {Array<import("./Layer.js").default>} Array of layers.
|
|
* @override
|
|
*/
|
|
getLayersArray(array) {
|
|
array = array !== void 0 ? array : [];
|
|
this.getLayers().forEach(function(layer) {
|
|
layer.getLayersArray(array);
|
|
});
|
|
return array;
|
|
}
|
|
/**
|
|
* Get the layer states list and use this groups z-index as the default
|
|
* for all layers in this and nested groups, if it is unset at this point.
|
|
* If dest is not provided and this group's z-index is undefined
|
|
* 0 is used a the default z-index.
|
|
* @param {Array<import("./Layer.js").State>} [dest] Optional list
|
|
* of layer states (to be modified in place).
|
|
* @return {Array<import("./Layer.js").State>} List of layer states.
|
|
* @override
|
|
*/
|
|
getLayerStatesArray(dest) {
|
|
const states = dest !== void 0 ? dest : [];
|
|
const pos = states.length;
|
|
this.getLayers().forEach(function(layer) {
|
|
layer.getLayerStatesArray(states);
|
|
});
|
|
const ownLayerState = this.getLayerState();
|
|
let defaultZIndex = ownLayerState.zIndex;
|
|
if (!dest && ownLayerState.zIndex === void 0) {
|
|
defaultZIndex = 0;
|
|
}
|
|
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
|
|
);
|
|
layerState.minZoom = Math.max(layerState.minZoom, ownLayerState.minZoom);
|
|
layerState.maxZoom = Math.min(layerState.maxZoom, ownLayerState.maxZoom);
|
|
if (ownLayerState.extent !== void 0) {
|
|
if (layerState.extent !== void 0) {
|
|
layerState.extent = getIntersection(
|
|
layerState.extent,
|
|
ownLayerState.extent
|
|
);
|
|
} else {
|
|
layerState.extent = ownLayerState.extent;
|
|
}
|
|
}
|
|
if (layerState.zIndex === void 0) {
|
|
layerState.zIndex = defaultZIndex;
|
|
}
|
|
}
|
|
return states;
|
|
}
|
|
/**
|
|
* @return {import("../source/Source.js").State} Source state.
|
|
* @override
|
|
*/
|
|
getSourceState() {
|
|
return "ready";
|
|
}
|
|
};
|
|
var Group_default = LayerGroup;
|
|
|
|
export {
|
|
GroupEvent,
|
|
Group_default
|
|
};
|
|
//# sourceMappingURL=chunk-POHYZJBN.js.map
|