Automated class transform
npx lebab --replace src --transform class
This commit is contained in:
+205
-218
@@ -37,232 +37,219 @@ import {assign} from '../obj.js';
|
||||
* @param {module:ol/layer/Base~Options} options Layer options.
|
||||
* @api
|
||||
*/
|
||||
const BaseLayer = function(options) {
|
||||
class BaseLayer {
|
||||
constructor(options) {
|
||||
|
||||
BaseObject.call(this);
|
||||
BaseObject.call(this);
|
||||
|
||||
/**
|
||||
* @type {Object.<string, *>}
|
||||
*/
|
||||
const properties = assign({}, options);
|
||||
properties[LayerProperty.OPACITY] =
|
||||
options.opacity !== undefined ? options.opacity : 1;
|
||||
properties[LayerProperty.VISIBLE] =
|
||||
options.visible !== undefined ? options.visible : true;
|
||||
properties[LayerProperty.Z_INDEX] =
|
||||
options.zIndex !== undefined ? options.zIndex : 0;
|
||||
properties[LayerProperty.MAX_RESOLUTION] =
|
||||
options.maxResolution !== undefined ? options.maxResolution : Infinity;
|
||||
properties[LayerProperty.MIN_RESOLUTION] =
|
||||
options.minResolution !== undefined ? options.minResolution : 0;
|
||||
/**
|
||||
* @type {Object.<string, *>}
|
||||
*/
|
||||
const properties = assign({}, options);
|
||||
properties[LayerProperty.OPACITY] =
|
||||
options.opacity !== undefined ? options.opacity : 1;
|
||||
properties[LayerProperty.VISIBLE] =
|
||||
options.visible !== undefined ? options.visible : true;
|
||||
properties[LayerProperty.Z_INDEX] =
|
||||
options.zIndex !== undefined ? options.zIndex : 0;
|
||||
properties[LayerProperty.MAX_RESOLUTION] =
|
||||
options.maxResolution !== undefined ? options.maxResolution : Infinity;
|
||||
properties[LayerProperty.MIN_RESOLUTION] =
|
||||
options.minResolution !== undefined ? options.minResolution : 0;
|
||||
|
||||
this.setProperties(properties);
|
||||
this.setProperties(properties);
|
||||
|
||||
/**
|
||||
* @type {module:ol/layer/Layer~State}
|
||||
* @private
|
||||
*/
|
||||
this.state_ = /** @type {module:ol/layer/Layer~State} */ ({
|
||||
layer: /** @type {module:ol/layer/Layer} */ (this),
|
||||
managed: true
|
||||
});
|
||||
/**
|
||||
* @type {module:ol/layer/Layer~State}
|
||||
* @private
|
||||
*/
|
||||
this.state_ = /** @type {module:ol/layer/Layer~State} */ ({
|
||||
layer: /** @type {module:ol/layer/Layer} */ (this),
|
||||
managed: true
|
||||
});
|
||||
|
||||
/**
|
||||
* The layer type.
|
||||
* @type {module:ol/LayerType}
|
||||
* @protected;
|
||||
*/
|
||||
this.type;
|
||||
/**
|
||||
* The layer type.
|
||||
* @type {module:ol/LayerType}
|
||||
* @protected;
|
||||
*/
|
||||
this.type;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the layer type (used when creating a layer renderer).
|
||||
* @return {module:ol/LayerType} The layer type.
|
||||
*/
|
||||
getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {module:ol/layer/Layer~State} Layer state.
|
||||
*/
|
||||
getLayerState() {
|
||||
this.state_.opacity = clamp(this.getOpacity(), 0, 1);
|
||||
this.state_.sourceState = this.getSourceState();
|
||||
this.state_.visible = this.getVisible();
|
||||
this.state_.extent = this.getExtent();
|
||||
this.state_.zIndex = this.getZIndex();
|
||||
this.state_.maxResolution = this.getMaxResolution();
|
||||
this.state_.minResolution = Math.max(this.getMinResolution(), 0);
|
||||
|
||||
return this.state_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {Array.<module:ol/layer/Layer>=} opt_array Array of layers (to be
|
||||
* modified in place).
|
||||
* @return {Array.<module:ol/layer/Layer>} Array of layers.
|
||||
*/
|
||||
getLayersArray(opt_array) {}
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {Array.<module:ol/layer/Layer~State>=} opt_states Optional list of layer
|
||||
* states (to be modified in place).
|
||||
* @return {Array.<module:ol/layer/Layer~State>} List of layer states.
|
||||
*/
|
||||
getLayerStatesArray(opt_states) {}
|
||||
|
||||
/**
|
||||
* Return the {@link module:ol/extent~Extent extent} of the layer or `undefined` if it
|
||||
* will be visible regardless of extent.
|
||||
* @return {module:ol/extent~Extent|undefined} The layer extent.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
getExtent() {
|
||||
return (
|
||||
/** @type {module:ol/extent~Extent|undefined} */ (this.get(LayerProperty.EXTENT))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the maximum resolution of the layer.
|
||||
* @return {number} The maximum resolution of the layer.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
getMaxResolution() {
|
||||
return /** @type {number} */ (this.get(LayerProperty.MAX_RESOLUTION));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the minimum resolution of the layer.
|
||||
* @return {number} The minimum resolution of the layer.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
getMinResolution() {
|
||||
return /** @type {number} */ (this.get(LayerProperty.MIN_RESOLUTION));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the opacity of the layer (between 0 and 1).
|
||||
* @return {number} The opacity of the layer.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
getOpacity() {
|
||||
return /** @type {number} */ (this.get(LayerProperty.OPACITY));
|
||||
}
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @return {module:ol/source/State} Source state.
|
||||
*/
|
||||
getSourceState() {}
|
||||
|
||||
/**
|
||||
* Return the visibility of the layer (`true` or `false`).
|
||||
* @return {boolean} The visibility of the layer.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
getVisible() {
|
||||
return /** @type {boolean} */ (this.get(LayerProperty.VISIBLE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Z-index of the layer, which is used to order layers before
|
||||
* rendering. The default Z-index is 0.
|
||||
* @return {number} The Z-index of the layer.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
getZIndex() {
|
||||
return /** @type {number} */ (this.get(LayerProperty.Z_INDEX));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the extent at which the layer is visible. If `undefined`, the layer
|
||||
* will be visible at all extents.
|
||||
* @param {module:ol/extent~Extent|undefined} extent The extent of the layer.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
setExtent(extent) {
|
||||
this.set(LayerProperty.EXTENT, extent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the maximum resolution at which the layer is visible.
|
||||
* @param {number} maxResolution The maximum resolution of the layer.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
setMaxResolution(maxResolution) {
|
||||
this.set(LayerProperty.MAX_RESOLUTION, maxResolution);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the minimum resolution at which the layer is visible.
|
||||
* @param {number} minResolution The minimum resolution of the layer.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
setMinResolution(minResolution) {
|
||||
this.set(LayerProperty.MIN_RESOLUTION, minResolution);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the opacity of the layer, allowed values range from 0 to 1.
|
||||
* @param {number} opacity The opacity of the layer.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
setOpacity(opacity) {
|
||||
this.set(LayerProperty.OPACITY, opacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the visibility of the layer (`true` or `false`).
|
||||
* @param {boolean} visible The visibility of the layer.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
setVisible(visible) {
|
||||
this.set(LayerProperty.VISIBLE, visible);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Z-index of the layer, which is used to order layers before rendering.
|
||||
* The default Z-index is 0.
|
||||
* @param {number} zindex The z-index of the layer.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
setZIndex(zindex) {
|
||||
this.set(LayerProperty.Z_INDEX, zindex);
|
||||
}
|
||||
}
|
||||
|
||||
inherits(BaseLayer, BaseObject);
|
||||
|
||||
|
||||
/**
|
||||
* Get the layer type (used when creating a layer renderer).
|
||||
* @return {module:ol/LayerType} The layer type.
|
||||
*/
|
||||
BaseLayer.prototype.getType = function() {
|
||||
return this.type;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {module:ol/layer/Layer~State} Layer state.
|
||||
*/
|
||||
BaseLayer.prototype.getLayerState = function() {
|
||||
this.state_.opacity = clamp(this.getOpacity(), 0, 1);
|
||||
this.state_.sourceState = this.getSourceState();
|
||||
this.state_.visible = this.getVisible();
|
||||
this.state_.extent = this.getExtent();
|
||||
this.state_.zIndex = this.getZIndex();
|
||||
this.state_.maxResolution = this.getMaxResolution();
|
||||
this.state_.minResolution = Math.max(this.getMinResolution(), 0);
|
||||
|
||||
return this.state_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {Array.<module:ol/layer/Layer>=} opt_array Array of layers (to be
|
||||
* modified in place).
|
||||
* @return {Array.<module:ol/layer/Layer>} Array of layers.
|
||||
*/
|
||||
BaseLayer.prototype.getLayersArray = function(opt_array) {};
|
||||
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {Array.<module:ol/layer/Layer~State>=} opt_states Optional list of layer
|
||||
* states (to be modified in place).
|
||||
* @return {Array.<module:ol/layer/Layer~State>} List of layer states.
|
||||
*/
|
||||
BaseLayer.prototype.getLayerStatesArray = function(opt_states) {};
|
||||
|
||||
|
||||
/**
|
||||
* Return the {@link module:ol/extent~Extent extent} of the layer or `undefined` if it
|
||||
* will be visible regardless of extent.
|
||||
* @return {module:ol/extent~Extent|undefined} The layer extent.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
BaseLayer.prototype.getExtent = function() {
|
||||
return (
|
||||
/** @type {module:ol/extent~Extent|undefined} */ (this.get(LayerProperty.EXTENT))
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the maximum resolution of the layer.
|
||||
* @return {number} The maximum resolution of the layer.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
BaseLayer.prototype.getMaxResolution = function() {
|
||||
return /** @type {number} */ (this.get(LayerProperty.MAX_RESOLUTION));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the minimum resolution of the layer.
|
||||
* @return {number} The minimum resolution of the layer.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
BaseLayer.prototype.getMinResolution = function() {
|
||||
return /** @type {number} */ (this.get(LayerProperty.MIN_RESOLUTION));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the opacity of the layer (between 0 and 1).
|
||||
* @return {number} The opacity of the layer.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
BaseLayer.prototype.getOpacity = function() {
|
||||
return /** @type {number} */ (this.get(LayerProperty.OPACITY));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @return {module:ol/source/State} Source state.
|
||||
*/
|
||||
BaseLayer.prototype.getSourceState = function() {};
|
||||
|
||||
|
||||
/**
|
||||
* Return the visibility of the layer (`true` or `false`).
|
||||
* @return {boolean} The visibility of the layer.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
BaseLayer.prototype.getVisible = function() {
|
||||
return /** @type {boolean} */ (this.get(LayerProperty.VISIBLE));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the Z-index of the layer, which is used to order layers before
|
||||
* rendering. The default Z-index is 0.
|
||||
* @return {number} The Z-index of the layer.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
BaseLayer.prototype.getZIndex = function() {
|
||||
return /** @type {number} */ (this.get(LayerProperty.Z_INDEX));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the extent at which the layer is visible. If `undefined`, the layer
|
||||
* will be visible at all extents.
|
||||
* @param {module:ol/extent~Extent|undefined} extent The extent of the layer.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
BaseLayer.prototype.setExtent = function(extent) {
|
||||
this.set(LayerProperty.EXTENT, extent);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the maximum resolution at which the layer is visible.
|
||||
* @param {number} maxResolution The maximum resolution of the layer.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
BaseLayer.prototype.setMaxResolution = function(maxResolution) {
|
||||
this.set(LayerProperty.MAX_RESOLUTION, maxResolution);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the minimum resolution at which the layer is visible.
|
||||
* @param {number} minResolution The minimum resolution of the layer.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
BaseLayer.prototype.setMinResolution = function(minResolution) {
|
||||
this.set(LayerProperty.MIN_RESOLUTION, minResolution);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the opacity of the layer, allowed values range from 0 to 1.
|
||||
* @param {number} opacity The opacity of the layer.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
BaseLayer.prototype.setOpacity = function(opacity) {
|
||||
this.set(LayerProperty.OPACITY, opacity);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the visibility of the layer (`true` or `false`).
|
||||
* @param {boolean} visible The visibility of the layer.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
BaseLayer.prototype.setVisible = function(visible) {
|
||||
this.set(LayerProperty.VISIBLE, visible);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set Z-index of the layer, which is used to order layers before rendering.
|
||||
* The default Z-index is 0.
|
||||
* @param {number} zindex The z-index of the layer.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
BaseLayer.prototype.setZIndex = function(zindex) {
|
||||
this.set(LayerProperty.Z_INDEX, zindex);
|
||||
};
|
||||
export default BaseLayer;
|
||||
|
||||
+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;
|
||||
|
||||
+191
-198
@@ -73,97 +73,215 @@ const DEFAULT_GRADIENT = ['#00f', '#0ff', '#0f0', '#ff0', '#f00'];
|
||||
* @param {module:ol/layer/Heatmap~Options=} opt_options Options.
|
||||
* @api
|
||||
*/
|
||||
const Heatmap = function(opt_options) {
|
||||
const options = opt_options ? opt_options : {};
|
||||
class Heatmap {
|
||||
constructor(opt_options) {
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
const baseOptions = assign({}, options);
|
||||
const baseOptions = assign({}, options);
|
||||
|
||||
delete baseOptions.gradient;
|
||||
delete baseOptions.radius;
|
||||
delete baseOptions.blur;
|
||||
delete baseOptions.shadow;
|
||||
delete baseOptions.weight;
|
||||
VectorLayer.call(this, /** @type {module:ol/layer/Vector~Options} */ (baseOptions));
|
||||
delete baseOptions.gradient;
|
||||
delete baseOptions.radius;
|
||||
delete baseOptions.blur;
|
||||
delete baseOptions.shadow;
|
||||
delete baseOptions.weight;
|
||||
VectorLayer.call(this, /** @type {module:ol/layer/Vector~Options} */ (baseOptions));
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Uint8ClampedArray}
|
||||
*/
|
||||
this.gradient_ = null;
|
||||
/**
|
||||
* @private
|
||||
* @type {Uint8ClampedArray}
|
||||
*/
|
||||
this.gradient_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.shadow_ = options.shadow !== undefined ? options.shadow : 250;
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.shadow_ = options.shadow !== undefined ? options.shadow : 250;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string|undefined}
|
||||
*/
|
||||
this.circleImage_ = undefined;
|
||||
/**
|
||||
* @private
|
||||
* @type {string|undefined}
|
||||
*/
|
||||
this.circleImage_ = undefined;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<Array.<module:ol/style/Style>>}
|
||||
*/
|
||||
this.styleCache_ = null;
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<Array.<module:ol/style/Style>>}
|
||||
*/
|
||||
this.styleCache_ = null;
|
||||
|
||||
listen(this,
|
||||
getChangeEventType(Property.GRADIENT),
|
||||
this.handleGradientChanged_, this);
|
||||
listen(this,
|
||||
getChangeEventType(Property.GRADIENT),
|
||||
this.handleGradientChanged_, this);
|
||||
|
||||
this.setGradient(options.gradient ? options.gradient : DEFAULT_GRADIENT);
|
||||
this.setGradient(options.gradient ? options.gradient : DEFAULT_GRADIENT);
|
||||
|
||||
this.setBlur(options.blur !== undefined ? options.blur : 15);
|
||||
this.setBlur(options.blur !== undefined ? options.blur : 15);
|
||||
|
||||
this.setRadius(options.radius !== undefined ? options.radius : 8);
|
||||
this.setRadius(options.radius !== undefined ? options.radius : 8);
|
||||
|
||||
listen(this,
|
||||
getChangeEventType(Property.BLUR),
|
||||
this.handleStyleChanged_, this);
|
||||
listen(this,
|
||||
getChangeEventType(Property.RADIUS),
|
||||
this.handleStyleChanged_, this);
|
||||
listen(this,
|
||||
getChangeEventType(Property.BLUR),
|
||||
this.handleStyleChanged_, this);
|
||||
listen(this,
|
||||
getChangeEventType(Property.RADIUS),
|
||||
this.handleStyleChanged_, this);
|
||||
|
||||
this.handleStyleChanged_();
|
||||
this.handleStyleChanged_();
|
||||
|
||||
const weight = options.weight ? options.weight : 'weight';
|
||||
let weightFunction;
|
||||
if (typeof weight === 'string') {
|
||||
weightFunction = function(feature) {
|
||||
return feature.get(weight);
|
||||
};
|
||||
} else {
|
||||
weightFunction = weight;
|
||||
const weight = options.weight ? options.weight : 'weight';
|
||||
let weightFunction;
|
||||
if (typeof weight === 'string') {
|
||||
weightFunction = function(feature) {
|
||||
return feature.get(weight);
|
||||
};
|
||||
} else {
|
||||
weightFunction = weight;
|
||||
}
|
||||
|
||||
this.setStyle(function(feature, resolution) {
|
||||
const weight = weightFunction(feature);
|
||||
const opacity = weight !== undefined ? clamp(weight, 0, 1) : 1;
|
||||
// cast to 8 bits
|
||||
const index = (255 * opacity) | 0;
|
||||
let style = this.styleCache_[index];
|
||||
if (!style) {
|
||||
style = [
|
||||
new Style({
|
||||
image: new Icon({
|
||||
opacity: opacity,
|
||||
src: this.circleImage_
|
||||
})
|
||||
})
|
||||
];
|
||||
this.styleCache_[index] = style;
|
||||
}
|
||||
return style;
|
||||
}.bind(this));
|
||||
|
||||
// For performance reasons, don't sort the features before rendering.
|
||||
// The render order is not relevant for a heatmap representation.
|
||||
this.setRenderOrder(null);
|
||||
|
||||
listen(this, RenderEventType.RENDER, this.handleRender_, this);
|
||||
}
|
||||
|
||||
this.setStyle(function(feature, resolution) {
|
||||
const weight = weightFunction(feature);
|
||||
const opacity = weight !== undefined ? clamp(weight, 0, 1) : 1;
|
||||
// cast to 8 bits
|
||||
const index = (255 * opacity) | 0;
|
||||
let style = this.styleCache_[index];
|
||||
if (!style) {
|
||||
style = [
|
||||
new Style({
|
||||
image: new Icon({
|
||||
opacity: opacity,
|
||||
src: this.circleImage_
|
||||
})
|
||||
})
|
||||
];
|
||||
this.styleCache_[index] = style;
|
||||
/**
|
||||
* @return {string} Data URL for a circle.
|
||||
* @private
|
||||
*/
|
||||
createCircle_() {
|
||||
const radius = this.getRadius();
|
||||
const blur = this.getBlur();
|
||||
const halfSize = radius + blur + 1;
|
||||
const size = 2 * halfSize;
|
||||
const context = createCanvasContext2D(size, size);
|
||||
context.shadowOffsetX = context.shadowOffsetY = this.shadow_;
|
||||
context.shadowBlur = blur;
|
||||
context.shadowColor = '#000';
|
||||
context.beginPath();
|
||||
const center = halfSize - this.shadow_;
|
||||
context.arc(center, center, radius, 0, Math.PI * 2, true);
|
||||
context.fill();
|
||||
return context.canvas.toDataURL();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the blur size in pixels.
|
||||
* @return {number} Blur size in pixels.
|
||||
* @api
|
||||
* @observable
|
||||
*/
|
||||
getBlur() {
|
||||
return /** @type {number} */ (this.get(Property.BLUR));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the gradient colors as array of strings.
|
||||
* @return {Array.<string>} Colors.
|
||||
* @api
|
||||
* @observable
|
||||
*/
|
||||
getGradient() {
|
||||
return /** @type {Array.<string>} */ (this.get(Property.GRADIENT));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the size of the radius in pixels.
|
||||
* @return {number} Radius size in pixel.
|
||||
* @api
|
||||
* @observable
|
||||
*/
|
||||
getRadius() {
|
||||
return /** @type {number} */ (this.get(Property.RADIUS));
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
handleGradientChanged_() {
|
||||
this.gradient_ = createGradient(this.getGradient());
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
handleStyleChanged_() {
|
||||
this.circleImage_ = this.createCircle_();
|
||||
this.styleCache_ = new Array(256);
|
||||
this.changed();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {module:ol/render/Event} event Post compose event
|
||||
* @private
|
||||
*/
|
||||
handleRender_(event) {
|
||||
const context = event.context;
|
||||
const canvas = context.canvas;
|
||||
const image = context.getImageData(0, 0, canvas.width, canvas.height);
|
||||
const view8 = image.data;
|
||||
for (let i = 0, ii = view8.length; i < ii; i += 4) {
|
||||
const alpha = view8[i + 3] * 4;
|
||||
if (alpha) {
|
||||
view8[i] = this.gradient_[alpha];
|
||||
view8[i + 1] = this.gradient_[alpha + 1];
|
||||
view8[i + 2] = this.gradient_[alpha + 2];
|
||||
}
|
||||
}
|
||||
return style;
|
||||
}.bind(this));
|
||||
context.putImageData(image, 0, 0);
|
||||
}
|
||||
|
||||
// For performance reasons, don't sort the features before rendering.
|
||||
// The render order is not relevant for a heatmap representation.
|
||||
this.setRenderOrder(null);
|
||||
/**
|
||||
* Set the blur size in pixels.
|
||||
* @param {number} blur Blur size in pixels.
|
||||
* @api
|
||||
* @observable
|
||||
*/
|
||||
setBlur(blur) {
|
||||
this.set(Property.BLUR, blur);
|
||||
}
|
||||
|
||||
listen(this, RenderEventType.RENDER, this.handleRender_, this);
|
||||
};
|
||||
/**
|
||||
* Set the gradient colors as array of strings.
|
||||
* @param {Array.<string>} colors Gradient.
|
||||
* @api
|
||||
* @observable
|
||||
*/
|
||||
setGradient(colors) {
|
||||
this.set(Property.GRADIENT, colors);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the size of the radius in pixels.
|
||||
* @param {number} radius Radius size in pixel.
|
||||
* @api
|
||||
* @observable
|
||||
*/
|
||||
setRadius(radius) {
|
||||
this.set(Property.RADIUS, radius);
|
||||
}
|
||||
}
|
||||
|
||||
inherits(Heatmap, VectorLayer);
|
||||
|
||||
@@ -191,129 +309,4 @@ const createGradient = function(colors) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {string} Data URL for a circle.
|
||||
* @private
|
||||
*/
|
||||
Heatmap.prototype.createCircle_ = function() {
|
||||
const radius = this.getRadius();
|
||||
const blur = this.getBlur();
|
||||
const halfSize = radius + blur + 1;
|
||||
const size = 2 * halfSize;
|
||||
const context = createCanvasContext2D(size, size);
|
||||
context.shadowOffsetX = context.shadowOffsetY = this.shadow_;
|
||||
context.shadowBlur = blur;
|
||||
context.shadowColor = '#000';
|
||||
context.beginPath();
|
||||
const center = halfSize - this.shadow_;
|
||||
context.arc(center, center, radius, 0, Math.PI * 2, true);
|
||||
context.fill();
|
||||
return context.canvas.toDataURL();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the blur size in pixels.
|
||||
* @return {number} Blur size in pixels.
|
||||
* @api
|
||||
* @observable
|
||||
*/
|
||||
Heatmap.prototype.getBlur = function() {
|
||||
return /** @type {number} */ (this.get(Property.BLUR));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the gradient colors as array of strings.
|
||||
* @return {Array.<string>} Colors.
|
||||
* @api
|
||||
* @observable
|
||||
*/
|
||||
Heatmap.prototype.getGradient = function() {
|
||||
return /** @type {Array.<string>} */ (this.get(Property.GRADIENT));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the size of the radius in pixels.
|
||||
* @return {number} Radius size in pixel.
|
||||
* @api
|
||||
* @observable
|
||||
*/
|
||||
Heatmap.prototype.getRadius = function() {
|
||||
return /** @type {number} */ (this.get(Property.RADIUS));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
Heatmap.prototype.handleGradientChanged_ = function() {
|
||||
this.gradient_ = createGradient(this.getGradient());
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
Heatmap.prototype.handleStyleChanged_ = function() {
|
||||
this.circleImage_ = this.createCircle_();
|
||||
this.styleCache_ = new Array(256);
|
||||
this.changed();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {module:ol/render/Event} event Post compose event
|
||||
* @private
|
||||
*/
|
||||
Heatmap.prototype.handleRender_ = function(event) {
|
||||
const context = event.context;
|
||||
const canvas = context.canvas;
|
||||
const image = context.getImageData(0, 0, canvas.width, canvas.height);
|
||||
const view8 = image.data;
|
||||
for (let i = 0, ii = view8.length; i < ii; i += 4) {
|
||||
const alpha = view8[i + 3] * 4;
|
||||
if (alpha) {
|
||||
view8[i] = this.gradient_[alpha];
|
||||
view8[i + 1] = this.gradient_[alpha + 1];
|
||||
view8[i + 2] = this.gradient_[alpha + 2];
|
||||
}
|
||||
}
|
||||
context.putImageData(image, 0, 0);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the blur size in pixels.
|
||||
* @param {number} blur Blur size in pixels.
|
||||
* @api
|
||||
* @observable
|
||||
*/
|
||||
Heatmap.prototype.setBlur = function(blur) {
|
||||
this.set(Property.BLUR, blur);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the gradient colors as array of strings.
|
||||
* @param {Array.<string>} colors Gradient.
|
||||
* @api
|
||||
* @observable
|
||||
*/
|
||||
Heatmap.prototype.setGradient = function(colors) {
|
||||
this.set(Property.GRADIENT, colors);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the size of the radius in pixels.
|
||||
* @param {number} radius Radius size in pixel.
|
||||
* @api
|
||||
* @observable
|
||||
*/
|
||||
Heatmap.prototype.setRadius = function(radius) {
|
||||
this.set(Property.RADIUS, radius);
|
||||
};
|
||||
|
||||
export default Heatmap;
|
||||
|
||||
+138
-142
@@ -66,42 +66,153 @@ import SourceState from '../source/State.js';
|
||||
* @param {module:ol/layer/Layer~Options} options Layer options.
|
||||
* @api
|
||||
*/
|
||||
const Layer = function(options) {
|
||||
class Layer {
|
||||
constructor(options) {
|
||||
|
||||
const baseOptions = assign({}, options);
|
||||
delete baseOptions.source;
|
||||
const baseOptions = assign({}, options);
|
||||
delete baseOptions.source;
|
||||
|
||||
BaseLayer.call(this, /** @type {module:ol/layer/Base~Options} */ (baseOptions));
|
||||
BaseLayer.call(this, /** @type {module:ol/layer/Base~Options} */ (baseOptions));
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {?module:ol/events~EventsKey}
|
||||
*/
|
||||
this.mapPrecomposeKey_ = null;
|
||||
/**
|
||||
* @private
|
||||
* @type {?module:ol/events~EventsKey}
|
||||
*/
|
||||
this.mapPrecomposeKey_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {?module:ol/events~EventsKey}
|
||||
*/
|
||||
this.mapRenderKey_ = null;
|
||||
/**
|
||||
* @private
|
||||
* @type {?module:ol/events~EventsKey}
|
||||
*/
|
||||
this.mapRenderKey_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {?module:ol/events~EventsKey}
|
||||
*/
|
||||
this.sourceChangeKey_ = null;
|
||||
/**
|
||||
* @private
|
||||
* @type {?module:ol/events~EventsKey}
|
||||
*/
|
||||
this.sourceChangeKey_ = null;
|
||||
|
||||
if (options.map) {
|
||||
this.setMap(options.map);
|
||||
if (options.map) {
|
||||
this.setMap(options.map);
|
||||
}
|
||||
|
||||
listen(this,
|
||||
getChangeEventType(LayerProperty.SOURCE),
|
||||
this.handleSourcePropertyChange_, this);
|
||||
|
||||
const source = options.source ? options.source : null;
|
||||
this.setSource(source);
|
||||
}
|
||||
|
||||
listen(this,
|
||||
getChangeEventType(LayerProperty.SOURCE),
|
||||
this.handleSourcePropertyChange_, this);
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
getLayersArray(opt_array) {
|
||||
const array = opt_array ? opt_array : [];
|
||||
array.push(this);
|
||||
return array;
|
||||
}
|
||||
|
||||
const source = options.source ? options.source : null;
|
||||
this.setSource(source);
|
||||
};
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
getLayerStatesArray(opt_states) {
|
||||
const states = opt_states ? opt_states : [];
|
||||
states.push(this.getLayerState());
|
||||
return states;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the layer source.
|
||||
* @return {module:ol/source/Source} The layer source (or `null` if not yet set).
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
getSource() {
|
||||
const source = this.get(LayerProperty.SOURCE);
|
||||
return (
|
||||
/** @type {module:ol/source/Source} */ (source) || null
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
getSourceState() {
|
||||
const source = this.getSource();
|
||||
return !source ? SourceState.UNDEFINED : source.getState();
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
handleSourceChange_() {
|
||||
this.changed();
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
handleSourcePropertyChange_() {
|
||||
if (this.sourceChangeKey_) {
|
||||
unlistenByKey(this.sourceChangeKey_);
|
||||
this.sourceChangeKey_ = null;
|
||||
}
|
||||
const source = this.getSource();
|
||||
if (source) {
|
||||
this.sourceChangeKey_ = listen(source,
|
||||
EventType.CHANGE, this.handleSourceChange_, this);
|
||||
}
|
||||
this.changed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the layer to be rendered on top of other layers on a map. The map will
|
||||
* not manage this layer in its layers collection, and the callback in
|
||||
* {@link module:ol/Map#forEachLayerAtPixel} will receive `null` as layer. This
|
||||
* is useful for temporary layers. To remove an unmanaged layer from the map,
|
||||
* use `#setMap(null)`.
|
||||
*
|
||||
* To add the layer to a map and have it managed by the map, use
|
||||
* {@link module:ol/Map#addLayer} instead.
|
||||
* @param {module:ol/PluggableMap} map Map.
|
||||
* @api
|
||||
*/
|
||||
setMap(map) {
|
||||
if (this.mapPrecomposeKey_) {
|
||||
unlistenByKey(this.mapPrecomposeKey_);
|
||||
this.mapPrecomposeKey_ = null;
|
||||
}
|
||||
if (!map) {
|
||||
this.changed();
|
||||
}
|
||||
if (this.mapRenderKey_) {
|
||||
unlistenByKey(this.mapRenderKey_);
|
||||
this.mapRenderKey_ = null;
|
||||
}
|
||||
if (map) {
|
||||
this.mapPrecomposeKey_ = listen(map, RenderEventType.PRECOMPOSE, function(evt) {
|
||||
const layerState = this.getLayerState();
|
||||
layerState.managed = false;
|
||||
layerState.zIndex = Infinity;
|
||||
evt.frameState.layerStatesArray.push(layerState);
|
||||
evt.frameState.layerStates[getUid(this)] = layerState;
|
||||
}, this);
|
||||
this.mapRenderKey_ = listen(this, EventType.CHANGE, map.render, map);
|
||||
this.changed();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the layer source.
|
||||
* @param {module:ol/source/Source} source The layer source.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
setSource(source) {
|
||||
this.set(LayerProperty.SOURCE, source);
|
||||
}
|
||||
}
|
||||
|
||||
inherits(Layer, BaseLayer);
|
||||
|
||||
@@ -120,119 +231,4 @@ export function visibleAtResolution(layerState, resolution) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
Layer.prototype.getLayersArray = function(opt_array) {
|
||||
const array = opt_array ? opt_array : [];
|
||||
array.push(this);
|
||||
return array;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
Layer.prototype.getLayerStatesArray = function(opt_states) {
|
||||
const states = opt_states ? opt_states : [];
|
||||
states.push(this.getLayerState());
|
||||
return states;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the layer source.
|
||||
* @return {module:ol/source/Source} The layer source (or `null` if not yet set).
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
Layer.prototype.getSource = function() {
|
||||
const source = this.get(LayerProperty.SOURCE);
|
||||
return (
|
||||
/** @type {module:ol/source/Source} */ (source) || null
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
Layer.prototype.getSourceState = function() {
|
||||
const source = this.getSource();
|
||||
return !source ? SourceState.UNDEFINED : source.getState();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
Layer.prototype.handleSourceChange_ = function() {
|
||||
this.changed();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
Layer.prototype.handleSourcePropertyChange_ = function() {
|
||||
if (this.sourceChangeKey_) {
|
||||
unlistenByKey(this.sourceChangeKey_);
|
||||
this.sourceChangeKey_ = null;
|
||||
}
|
||||
const source = this.getSource();
|
||||
if (source) {
|
||||
this.sourceChangeKey_ = listen(source,
|
||||
EventType.CHANGE, this.handleSourceChange_, this);
|
||||
}
|
||||
this.changed();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Sets the layer to be rendered on top of other layers on a map. The map will
|
||||
* not manage this layer in its layers collection, and the callback in
|
||||
* {@link module:ol/Map#forEachLayerAtPixel} will receive `null` as layer. This
|
||||
* is useful for temporary layers. To remove an unmanaged layer from the map,
|
||||
* use `#setMap(null)`.
|
||||
*
|
||||
* To add the layer to a map and have it managed by the map, use
|
||||
* {@link module:ol/Map#addLayer} instead.
|
||||
* @param {module:ol/PluggableMap} map Map.
|
||||
* @api
|
||||
*/
|
||||
Layer.prototype.setMap = function(map) {
|
||||
if (this.mapPrecomposeKey_) {
|
||||
unlistenByKey(this.mapPrecomposeKey_);
|
||||
this.mapPrecomposeKey_ = null;
|
||||
}
|
||||
if (!map) {
|
||||
this.changed();
|
||||
}
|
||||
if (this.mapRenderKey_) {
|
||||
unlistenByKey(this.mapRenderKey_);
|
||||
this.mapRenderKey_ = null;
|
||||
}
|
||||
if (map) {
|
||||
this.mapPrecomposeKey_ = listen(map, RenderEventType.PRECOMPOSE, function(evt) {
|
||||
const layerState = this.getLayerState();
|
||||
layerState.managed = false;
|
||||
layerState.zIndex = Infinity;
|
||||
evt.frameState.layerStatesArray.push(layerState);
|
||||
evt.frameState.layerStates[getUid(this)] = layerState;
|
||||
}, this);
|
||||
this.mapRenderKey_ = listen(this, EventType.CHANGE, map.render, map);
|
||||
this.changed();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the layer source.
|
||||
* @param {module:ol/source/Source} source The layer source.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
Layer.prototype.setSource = function(source) {
|
||||
this.set(LayerProperty.SOURCE, source);
|
||||
};
|
||||
export default Layer;
|
||||
|
||||
+58
-58
@@ -45,42 +45,73 @@ import {assign} from '../obj.js';
|
||||
* @param {module:ol/layer/Tile~Options=} opt_options Tile layer options.
|
||||
* @api
|
||||
*/
|
||||
const TileLayer = function(opt_options) {
|
||||
const options = opt_options ? opt_options : {};
|
||||
class TileLayer {
|
||||
constructor(opt_options) {
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
const baseOptions = assign({}, options);
|
||||
const baseOptions = assign({}, options);
|
||||
|
||||
delete baseOptions.preload;
|
||||
delete baseOptions.useInterimTilesOnError;
|
||||
Layer.call(this, /** @type {module:ol/layer/Layer~Options} */ (baseOptions));
|
||||
delete baseOptions.preload;
|
||||
delete baseOptions.useInterimTilesOnError;
|
||||
Layer.call(this, /** @type {module:ol/layer/Layer~Options} */ (baseOptions));
|
||||
|
||||
this.setPreload(options.preload !== undefined ? options.preload : 0);
|
||||
this.setUseInterimTilesOnError(options.useInterimTilesOnError !== undefined ?
|
||||
options.useInterimTilesOnError : true);
|
||||
this.setPreload(options.preload !== undefined ? options.preload : 0);
|
||||
this.setUseInterimTilesOnError(options.useInterimTilesOnError !== undefined ?
|
||||
options.useInterimTilesOnError : true);
|
||||
|
||||
/**
|
||||
* The layer type.
|
||||
* @protected
|
||||
* @type {module:ol/LayerType}
|
||||
*/
|
||||
this.type = LayerType.TILE;
|
||||
/**
|
||||
* The layer type.
|
||||
* @protected
|
||||
* @type {module:ol/LayerType}
|
||||
*/
|
||||
this.type = LayerType.TILE;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the level as number to which we will preload tiles up to.
|
||||
* @return {number} The level to preload tiles up to.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
getPreload() {
|
||||
return /** @type {number} */ (this.get(TileProperty.PRELOAD));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the level as number to which we will preload tiles up to.
|
||||
* @param {number} preload The level to preload tiles up to.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
setPreload(preload) {
|
||||
this.set(TileProperty.PRELOAD, preload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether we use interim tiles on error.
|
||||
* @return {boolean} Use interim tiles on error.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
getUseInterimTilesOnError() {
|
||||
return /** @type {boolean} */ (this.get(TileProperty.USE_INTERIM_TILES_ON_ERROR));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether we use interim tiles on error.
|
||||
* @param {boolean} useInterimTilesOnError Use interim tiles on error.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
setUseInterimTilesOnError(useInterimTilesOnError) {
|
||||
this.set(TileProperty.USE_INTERIM_TILES_ON_ERROR, useInterimTilesOnError);
|
||||
}
|
||||
}
|
||||
|
||||
inherits(TileLayer, Layer);
|
||||
|
||||
|
||||
/**
|
||||
* Return the level as number to which we will preload tiles up to.
|
||||
* @return {number} The level to preload tiles up to.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
TileLayer.prototype.getPreload = function() {
|
||||
return /** @type {number} */ (this.get(TileProperty.PRELOAD));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the associated {@link module:ol/source/Tile tilesource} of the layer.
|
||||
* @function
|
||||
@@ -90,35 +121,4 @@ TileLayer.prototype.getPreload = function() {
|
||||
TileLayer.prototype.getSource;
|
||||
|
||||
|
||||
/**
|
||||
* Set the level as number to which we will preload tiles up to.
|
||||
* @param {number} preload The level to preload tiles up to.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
TileLayer.prototype.setPreload = function(preload) {
|
||||
this.set(TileProperty.PRELOAD, preload);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Whether we use interim tiles on error.
|
||||
* @return {boolean} Use interim tiles on error.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
TileLayer.prototype.getUseInterimTilesOnError = function() {
|
||||
return /** @type {boolean} */ (this.get(TileProperty.USE_INTERIM_TILES_ON_ERROR));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set whether we use interim tiles on error.
|
||||
* @param {boolean} useInterimTilesOnError Use interim tiles on error.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
TileLayer.prototype.setUseInterimTilesOnError = function(useInterimTilesOnError) {
|
||||
this.set(TileProperty.USE_INTERIM_TILES_ON_ERROR, useInterimTilesOnError);
|
||||
};
|
||||
export default TileLayer;
|
||||
|
||||
+159
-168
@@ -91,114 +91,181 @@ const Property = {
|
||||
* @param {module:ol/layer/Vector~Options=} opt_options Options.
|
||||
* @api
|
||||
*/
|
||||
const VectorLayer = function(opt_options) {
|
||||
const options = opt_options ?
|
||||
opt_options : /** @type {module:ol/layer/Vector~Options} */ ({});
|
||||
class VectorLayer {
|
||||
constructor(opt_options) {
|
||||
const options = opt_options ?
|
||||
opt_options : /** @type {module:ol/layer/Vector~Options} */ ({});
|
||||
|
||||
const baseOptions = assign({}, options);
|
||||
const baseOptions = assign({}, options);
|
||||
|
||||
delete baseOptions.style;
|
||||
delete baseOptions.renderBuffer;
|
||||
delete baseOptions.updateWhileAnimating;
|
||||
delete baseOptions.updateWhileInteracting;
|
||||
Layer.call(this, /** @type {module:ol/layer/Layer~Options} */ (baseOptions));
|
||||
delete baseOptions.style;
|
||||
delete baseOptions.renderBuffer;
|
||||
delete baseOptions.updateWhileAnimating;
|
||||
delete baseOptions.updateWhileInteracting;
|
||||
Layer.call(this, /** @type {module:ol/layer/Layer~Options} */ (baseOptions));
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.declutter_ = options.declutter !== undefined ? options.declutter : false;
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.declutter_ = options.declutter !== undefined ? options.declutter : false;
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
* @private
|
||||
*/
|
||||
this.renderBuffer_ = options.renderBuffer !== undefined ?
|
||||
options.renderBuffer : 100;
|
||||
/**
|
||||
* @type {number}
|
||||
* @private
|
||||
*/
|
||||
this.renderBuffer_ = options.renderBuffer !== undefined ?
|
||||
options.renderBuffer : 100;
|
||||
|
||||
/**
|
||||
* User provided style.
|
||||
* @type {module:ol/style/Style|Array.<module:ol/style/Style>|module:ol/style/Style~StyleFunction}
|
||||
* @private
|
||||
*/
|
||||
this.style_ = null;
|
||||
/**
|
||||
* User provided style.
|
||||
* @type {module:ol/style/Style|Array.<module:ol/style/Style>|module:ol/style/Style~StyleFunction}
|
||||
* @private
|
||||
*/
|
||||
this.style_ = null;
|
||||
|
||||
/**
|
||||
* Style function for use within the library.
|
||||
* @type {module:ol/style/Style~StyleFunction|undefined}
|
||||
* @private
|
||||
*/
|
||||
this.styleFunction_ = undefined;
|
||||
/**
|
||||
* Style function for use within the library.
|
||||
* @type {module:ol/style/Style~StyleFunction|undefined}
|
||||
* @private
|
||||
*/
|
||||
this.styleFunction_ = undefined;
|
||||
|
||||
this.setStyle(options.style);
|
||||
this.setStyle(options.style);
|
||||
|
||||
/**
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
this.updateWhileAnimating_ = options.updateWhileAnimating !== undefined ?
|
||||
options.updateWhileAnimating : false;
|
||||
/**
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
this.updateWhileAnimating_ = options.updateWhileAnimating !== undefined ?
|
||||
options.updateWhileAnimating : false;
|
||||
|
||||
/**
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
this.updateWhileInteracting_ = options.updateWhileInteracting !== undefined ?
|
||||
options.updateWhileInteracting : false;
|
||||
/**
|
||||
* @type {boolean}
|
||||
* @private
|
||||
*/
|
||||
this.updateWhileInteracting_ = options.updateWhileInteracting !== undefined ?
|
||||
options.updateWhileInteracting : false;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/layer/VectorTileRenderType|string}
|
||||
*/
|
||||
this.renderMode_ = options.renderMode || VectorRenderType.VECTOR;
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/layer/VectorTileRenderType|string}
|
||||
*/
|
||||
this.renderMode_ = options.renderMode || VectorRenderType.VECTOR;
|
||||
|
||||
/**
|
||||
* The layer type.
|
||||
* @protected
|
||||
* @type {module:ol/LayerType}
|
||||
*/
|
||||
this.type = LayerType.VECTOR;
|
||||
/**
|
||||
* The layer type.
|
||||
* @protected
|
||||
* @type {module:ol/LayerType}
|
||||
*/
|
||||
this.type = LayerType.VECTOR;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {boolean} Declutter.
|
||||
*/
|
||||
getDeclutter() {
|
||||
return this.declutter_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {boolean} declutter Declutter.
|
||||
*/
|
||||
setDeclutter(declutter) {
|
||||
this.declutter_ = declutter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {number|undefined} Render buffer.
|
||||
*/
|
||||
getRenderBuffer() {
|
||||
return this.renderBuffer_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {function(module:ol/Feature, module:ol/Feature): number|null|undefined} Render
|
||||
* order.
|
||||
*/
|
||||
getRenderOrder() {
|
||||
return (
|
||||
/** @type {module:ol/render~OrderFunction|null|undefined} */ (this.get(Property.RENDER_ORDER))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the style for features. This returns whatever was passed to the `style`
|
||||
* option at construction or to the `setStyle` method.
|
||||
* @return {module:ol/style/Style|Array.<module:ol/style/Style>|module:ol/style/Style~StyleFunction}
|
||||
* Layer style.
|
||||
* @api
|
||||
*/
|
||||
getStyle() {
|
||||
return this.style_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the style function.
|
||||
* @return {module:ol/style/Style~StyleFunction|undefined} Layer style function.
|
||||
* @api
|
||||
*/
|
||||
getStyleFunction() {
|
||||
return this.styleFunction_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {boolean} Whether the rendered layer should be updated while
|
||||
* animating.
|
||||
*/
|
||||
getUpdateWhileAnimating() {
|
||||
return this.updateWhileAnimating_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {boolean} Whether the rendered layer should be updated while
|
||||
* interacting.
|
||||
*/
|
||||
getUpdateWhileInteracting() {
|
||||
return this.updateWhileInteracting_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {module:ol/render~OrderFunction|null|undefined} renderOrder
|
||||
* Render order.
|
||||
*/
|
||||
setRenderOrder(renderOrder) {
|
||||
this.set(Property.RENDER_ORDER, renderOrder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the style for features. This can be a single style object, an array
|
||||
* of styles, or a function that takes a feature and resolution and returns
|
||||
* an array of styles. If it is `undefined` the default style is used. If
|
||||
* it is `null` the layer has no style (a `null` style), so only features
|
||||
* that have their own styles will be rendered in the layer. See
|
||||
* {@link module:ol/style} for information on the default style.
|
||||
* @param {module:ol/style/Style|Array.<module:ol/style/Style>|module:ol/style/Style~StyleFunction|null|undefined}
|
||||
* style Layer style.
|
||||
* @api
|
||||
*/
|
||||
setStyle(style) {
|
||||
this.style_ = style !== undefined ? style : createDefaultStyle;
|
||||
this.styleFunction_ = style === null ?
|
||||
undefined : toStyleFunction(this.style_);
|
||||
this.changed();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {module:ol/layer/VectorRenderType|string} The render mode.
|
||||
*/
|
||||
getRenderMode() {
|
||||
return this.renderMode_;
|
||||
}
|
||||
}
|
||||
|
||||
inherits(VectorLayer, Layer);
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Declutter.
|
||||
*/
|
||||
VectorLayer.prototype.getDeclutter = function() {
|
||||
return this.declutter_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {boolean} declutter Declutter.
|
||||
*/
|
||||
VectorLayer.prototype.setDeclutter = function(declutter) {
|
||||
this.declutter_ = declutter;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {number|undefined} Render buffer.
|
||||
*/
|
||||
VectorLayer.prototype.getRenderBuffer = function() {
|
||||
return this.renderBuffer_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {function(module:ol/Feature, module:ol/Feature): number|null|undefined} Render
|
||||
* order.
|
||||
*/
|
||||
VectorLayer.prototype.getRenderOrder = function() {
|
||||
return (
|
||||
/** @type {module:ol/render~OrderFunction|null|undefined} */ (this.get(Property.RENDER_ORDER))
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the associated {@link module:ol/source/Vector vectorsource} of the layer.
|
||||
* @function
|
||||
@@ -208,80 +275,4 @@ VectorLayer.prototype.getRenderOrder = function() {
|
||||
VectorLayer.prototype.getSource;
|
||||
|
||||
|
||||
/**
|
||||
* Get the style for features. This returns whatever was passed to the `style`
|
||||
* option at construction or to the `setStyle` method.
|
||||
* @return {module:ol/style/Style|Array.<module:ol/style/Style>|module:ol/style/Style~StyleFunction}
|
||||
* Layer style.
|
||||
* @api
|
||||
*/
|
||||
VectorLayer.prototype.getStyle = function() {
|
||||
return this.style_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the style function.
|
||||
* @return {module:ol/style/Style~StyleFunction|undefined} Layer style function.
|
||||
* @api
|
||||
*/
|
||||
VectorLayer.prototype.getStyleFunction = function() {
|
||||
return this.styleFunction_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Whether the rendered layer should be updated while
|
||||
* animating.
|
||||
*/
|
||||
VectorLayer.prototype.getUpdateWhileAnimating = function() {
|
||||
return this.updateWhileAnimating_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Whether the rendered layer should be updated while
|
||||
* interacting.
|
||||
*/
|
||||
VectorLayer.prototype.getUpdateWhileInteracting = function() {
|
||||
return this.updateWhileInteracting_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {module:ol/render~OrderFunction|null|undefined} renderOrder
|
||||
* Render order.
|
||||
*/
|
||||
VectorLayer.prototype.setRenderOrder = function(renderOrder) {
|
||||
this.set(Property.RENDER_ORDER, renderOrder);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the style for features. This can be a single style object, an array
|
||||
* of styles, or a function that takes a feature and resolution and returns
|
||||
* an array of styles. If it is `undefined` the default style is used. If
|
||||
* it is `null` the layer has no style (a `null` style), so only features
|
||||
* that have their own styles will be rendered in the layer. See
|
||||
* {@link module:ol/style} for information on the default style.
|
||||
* @param {module:ol/style/Style|Array.<module:ol/style/Style>|module:ol/style/Style~StyleFunction|null|undefined}
|
||||
* style Layer style.
|
||||
* @api
|
||||
*/
|
||||
VectorLayer.prototype.setStyle = function(style) {
|
||||
this.style_ = style !== undefined ? style : createDefaultStyle;
|
||||
this.styleFunction_ = style === null ?
|
||||
undefined : toStyleFunction(this.style_);
|
||||
this.changed();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {module:ol/layer/VectorRenderType|string} The render mode.
|
||||
*/
|
||||
VectorLayer.prototype.getRenderMode = function() {
|
||||
return this.renderMode_;
|
||||
};
|
||||
|
||||
|
||||
export default VectorLayer;
|
||||
|
||||
+68
-70
@@ -99,86 +99,84 @@ export const RenderType = {
|
||||
* @param {module:ol/layer/VectorTile~Options=} opt_options Options.
|
||||
* @api
|
||||
*/
|
||||
const VectorTileLayer = function(opt_options) {
|
||||
const options = opt_options ? opt_options : {};
|
||||
class VectorTileLayer {
|
||||
constructor(opt_options) {
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
let renderMode = options.renderMode || VectorTileRenderType.HYBRID;
|
||||
assert(renderMode == undefined ||
|
||||
renderMode == VectorTileRenderType.IMAGE ||
|
||||
renderMode == VectorTileRenderType.HYBRID ||
|
||||
renderMode == VectorTileRenderType.VECTOR,
|
||||
28); // `renderMode` must be `'image'`, `'hybrid'` or `'vector'`
|
||||
if (options.declutter && renderMode == VectorTileRenderType.IMAGE) {
|
||||
renderMode = VectorTileRenderType.HYBRID;
|
||||
}
|
||||
options.renderMode = renderMode;
|
||||
let renderMode = options.renderMode || VectorTileRenderType.HYBRID;
|
||||
assert(renderMode == undefined ||
|
||||
renderMode == VectorTileRenderType.IMAGE ||
|
||||
renderMode == VectorTileRenderType.HYBRID ||
|
||||
renderMode == VectorTileRenderType.VECTOR,
|
||||
28); // `renderMode` must be `'image'`, `'hybrid'` or `'vector'`
|
||||
if (options.declutter && renderMode == VectorTileRenderType.IMAGE) {
|
||||
renderMode = VectorTileRenderType.HYBRID;
|
||||
}
|
||||
options.renderMode = renderMode;
|
||||
|
||||
const baseOptions = assign({}, options);
|
||||
const baseOptions = assign({}, options);
|
||||
|
||||
delete baseOptions.preload;
|
||||
delete baseOptions.useInterimTilesOnError;
|
||||
VectorLayer.call(this, /** @type {module:ol/layer/Vector~Options} */ (baseOptions));
|
||||
delete baseOptions.preload;
|
||||
delete baseOptions.useInterimTilesOnError;
|
||||
VectorLayer.call(this, /** @type {module:ol/layer/Vector~Options} */ (baseOptions));
|
||||
|
||||
this.setPreload(options.preload ? options.preload : 0);
|
||||
this.setUseInterimTilesOnError(options.useInterimTilesOnError !== undefined ?
|
||||
options.useInterimTilesOnError : true);
|
||||
this.setPreload(options.preload ? options.preload : 0);
|
||||
this.setUseInterimTilesOnError(options.useInterimTilesOnError !== undefined ?
|
||||
options.useInterimTilesOnError : true);
|
||||
|
||||
/**
|
||||
* The layer type.
|
||||
* @protected
|
||||
* @type {module:ol/LayerType}
|
||||
*/
|
||||
this.type = LayerType.VECTOR_TILE;
|
||||
/**
|
||||
* The layer type.
|
||||
* @protected
|
||||
* @type {module:ol/LayerType}
|
||||
*/
|
||||
this.type = LayerType.VECTOR_TILE;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the level as number to which we will preload tiles up to.
|
||||
* @return {number} The level to preload tiles up to.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
getPreload() {
|
||||
return /** @type {number} */ (this.get(TileProperty.PRELOAD));
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether we use interim tiles on error.
|
||||
* @return {boolean} Use interim tiles on error.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
getUseInterimTilesOnError() {
|
||||
return /** @type {boolean} */ (this.get(TileProperty.USE_INTERIM_TILES_ON_ERROR));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the level as number to which we will preload tiles up to.
|
||||
* @param {number} preload The level to preload tiles up to.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
setPreload(preload) {
|
||||
this.set(TileProperty.PRELOAD, preload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether we use interim tiles on error.
|
||||
* @param {boolean} useInterimTilesOnError Use interim tiles on error.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
setUseInterimTilesOnError(useInterimTilesOnError) {
|
||||
this.set(TileProperty.USE_INTERIM_TILES_ON_ERROR, useInterimTilesOnError);
|
||||
}
|
||||
}
|
||||
|
||||
inherits(VectorTileLayer, VectorLayer);
|
||||
|
||||
|
||||
/**
|
||||
* Return the level as number to which we will preload tiles up to.
|
||||
* @return {number} The level to preload tiles up to.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
VectorTileLayer.prototype.getPreload = function() {
|
||||
return /** @type {number} */ (this.get(TileProperty.PRELOAD));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Whether we use interim tiles on error.
|
||||
* @return {boolean} Use interim tiles on error.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
VectorTileLayer.prototype.getUseInterimTilesOnError = function() {
|
||||
return /** @type {boolean} */ (this.get(TileProperty.USE_INTERIM_TILES_ON_ERROR));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the level as number to which we will preload tiles up to.
|
||||
* @param {number} preload The level to preload tiles up to.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
VectorTileLayer.prototype.setPreload = function(preload) {
|
||||
this.set(TileProperty.PRELOAD, preload);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set whether we use interim tiles on error.
|
||||
* @param {boolean} useInterimTilesOnError Use interim tiles on error.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
VectorTileLayer.prototype.setUseInterimTilesOnError = function(useInterimTilesOnError) {
|
||||
this.set(TileProperty.USE_INTERIM_TILES_ON_ERROR, useInterimTilesOnError);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Return the associated {@link module:ol/source/VectorTile vectortilesource} of the layer.
|
||||
* @function
|
||||
|
||||
Reference in New Issue
Block a user