Merge pull request #9961 from KlausBenndorf/remove-select-interaction
SelectInteraction removal
This commit is contained in:
@@ -47,7 +47,6 @@ import {create as createTransform, apply as applyTransform} from './transform.js
|
||||
* @property {import("./transform.js").Transform} pixelToCoordinateTransform
|
||||
* @property {Array<PostRenderFunction>} postRenderFunctions
|
||||
* @property {import("./size.js").Size} size
|
||||
* @property {!Object<string, boolean>} skippedFeatureUids
|
||||
* @property {TileQueue} tileQueue
|
||||
* @property {!Object<string, Object<string, boolean>>} usedTiles
|
||||
* @property {Array<number>} viewHints
|
||||
@@ -366,13 +365,6 @@ class PluggableMap extends BaseObject {
|
||||
this.getTilePriority.bind(this),
|
||||
this.handleTileChange_.bind(this));
|
||||
|
||||
/**
|
||||
* Uids of features to skip at rendering time.
|
||||
* @type {Object<string, boolean>}
|
||||
* @private
|
||||
*/
|
||||
this.skippedFeatureUids_ = {};
|
||||
|
||||
this.addEventListener(getChangeEventType(MapProperty.LAYERGROUP), this.handleLayerGroupChanged_);
|
||||
this.addEventListener(getChangeEventType(MapProperty.VIEW), this.handleViewChanged_);
|
||||
this.addEventListener(getChangeEventType(MapProperty.SIZE), this.handleSizeChanged_);
|
||||
@@ -1241,7 +1233,6 @@ class PluggableMap extends BaseObject {
|
||||
pixelToCoordinateTransform: this.pixelToCoordinateTransform_,
|
||||
postRenderFunctions: [],
|
||||
size: size,
|
||||
skippedFeatureUids: this.skippedFeatureUids_,
|
||||
tileQueue: this.tileQueue_,
|
||||
time: time,
|
||||
usedTiles: {},
|
||||
@@ -1329,14 +1320,6 @@ class PluggableMap extends BaseObject {
|
||||
this.set(MapProperty.VIEW, view);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("./Feature.js").default} feature Feature.
|
||||
*/
|
||||
skipFeature(feature) {
|
||||
this.skippedFeatureUids_[getUid(feature)] = true;
|
||||
this.render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Force a recalculation of the map viewport size. This should be called when
|
||||
* third-party code changes the size of the map viewport.
|
||||
@@ -1363,14 +1346,6 @@ class PluggableMap extends BaseObject {
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("./Feature.js").default} feature Feature.
|
||||
*/
|
||||
unskipFeature(feature) {
|
||||
delete this.skippedFeatureUids_[getUid(feature)];
|
||||
this.render();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ export {default as MouseWheelZoom} from './interaction/MouseWheelZoom.js';
|
||||
export {default as PinchRotate} from './interaction/PinchRotate.js';
|
||||
export {default as PinchZoom} from './interaction/PinchZoom.js';
|
||||
export {default as Pointer} from './interaction/Pointer.js';
|
||||
export {default as Select} from './interaction/Select.js';
|
||||
export {default as Snap} from './interaction/Snap.js';
|
||||
export {default as Translate} from './interaction/Translate.js';
|
||||
|
||||
|
||||
@@ -1,483 +0,0 @@
|
||||
/**
|
||||
* @module ol/interaction/Select
|
||||
*/
|
||||
import {getUid} from '../util.js';
|
||||
import CollectionEventType from '../CollectionEventType.js';
|
||||
import {extend, includes} from '../array.js';
|
||||
import Event from '../events/Event.js';
|
||||
import {singleClick, never, shiftKeyOnly, pointerMove} from '../events/condition.js';
|
||||
import {TRUE} from '../functions.js';
|
||||
import GeometryType from '../geom/GeometryType.js';
|
||||
import Interaction from './Interaction.js';
|
||||
import VectorLayer from '../layer/Vector.js';
|
||||
import {clear} from '../obj.js';
|
||||
import VectorSource from '../source/Vector.js';
|
||||
import {createEditingStyle} from '../style/Style.js';
|
||||
|
||||
|
||||
/**
|
||||
* @enum {string}
|
||||
*/
|
||||
const SelectEventType = {
|
||||
/**
|
||||
* Triggered when feature(s) has been (de)selected.
|
||||
* @event SelectEvent#select
|
||||
* @api
|
||||
*/
|
||||
SELECT: 'select'
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* A function that takes an {@link module:ol/Feature} or
|
||||
* {@link module:ol/render/Feature} and an
|
||||
* {@link module:ol/layer/Layer} and returns `true` if the feature may be
|
||||
* selected or `false` otherwise.
|
||||
* @typedef {function(import("../Feature.js").FeatureLike, import("../layer/Layer.js").default):boolean} FilterFunction
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {import("../events/condition.js").Condition} [addCondition] A function
|
||||
* that takes an {@link module:ol/MapBrowserEvent~MapBrowserEvent} and returns a
|
||||
* boolean to indicate whether that event should be handled.
|
||||
* By default, this is {@link module:ol/events/condition~never}. Use this if you
|
||||
* want to use different events for add and remove instead of `toggle`.
|
||||
* @property {import("../events/condition.js").Condition} [condition] A function that
|
||||
* takes an {@link module:ol/MapBrowserEvent~MapBrowserEvent} and returns a
|
||||
* boolean to indicate whether that event should be handled. This is the event
|
||||
* for the selected features as a whole. By default, this is
|
||||
* {@link module:ol/events/condition~singleClick}. Clicking on a feature selects that
|
||||
* feature and removes any that were in the selection. Clicking outside any
|
||||
* feature removes all from the selection.
|
||||
* See `toggle`, `add`, `remove` options for adding/removing extra features to/
|
||||
* from the selection.
|
||||
* @property {Array<import("../layer/Layer.js").default>|function(import("../layer/Layer.js").default): boolean} [layers]
|
||||
* A list of layers from which features should be selected. Alternatively, a
|
||||
* filter function can be provided. The function will be called for each layer
|
||||
* in the map and should return `true` for layers that you want to be
|
||||
* selectable. If the option is absent, all visible layers will be considered
|
||||
* selectable.
|
||||
* @property {import("../style/Style.js").StyleLike} [style]
|
||||
* Style for the selected features. By default the default edit style is used
|
||||
* (see {@link module:ol/style}).
|
||||
* @property {import("../events/condition.js").Condition} [removeCondition] A function
|
||||
* that takes an {@link module:ol/MapBrowserEvent~MapBrowserEvent} and returns a
|
||||
* boolean to indicate whether that event should be handled.
|
||||
* By default, this is {@link module:ol/events/condition~never}. Use this if you
|
||||
* want to use different events for add and remove instead of `toggle`.
|
||||
* @property {import("../events/condition.js").Condition} [toggleCondition] A function
|
||||
* that takes an {@link module:ol/MapBrowserEvent~MapBrowserEvent} and returns a
|
||||
* boolean to indicate whether that event should be handled. This is in addition
|
||||
* to the `condition` event. By default,
|
||||
* {@link module:ol/events/condition~shiftKeyOnly}, i.e. pressing `shift` as
|
||||
* well as the `condition` event, adds that feature to the current selection if
|
||||
* it is not currently selected, and removes it if it is. See `add` and `remove`
|
||||
* if you want to use different events instead of a toggle.
|
||||
* @property {boolean} [multi=false] A boolean that determines if the default
|
||||
* behaviour should select only single features or all (overlapping) features at
|
||||
* the clicked map position. The default of `false` means single select.
|
||||
* @property {import("../Collection.js").default<import("../Feature.js").default>} [features]
|
||||
* Collection where the interaction will place selected features. Optional. If
|
||||
* not set the interaction will create a collection. In any case the collection
|
||||
* used by the interaction is returned by
|
||||
* {@link module:ol/interaction/Select~Select#getFeatures}.
|
||||
* @property {FilterFunction} [filter] A function
|
||||
* that takes an {@link module:ol/Feature} and an
|
||||
* {@link module:ol/layer/Layer} and returns `true` if the feature may be
|
||||
* selected or `false` otherwise.
|
||||
* @property {boolean} [wrapX=true] Wrap the world horizontally on the selection
|
||||
* overlay.
|
||||
* @property {number} [hitTolerance=0] Hit-detection tolerance. Pixels inside
|
||||
* the radius around the given position will be checked for features.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Events emitted by {@link module:ol/interaction/Select~Select} instances are instances of
|
||||
* this type.
|
||||
*/
|
||||
class SelectEvent extends Event {
|
||||
/**
|
||||
* @param {SelectEventType} type The event type.
|
||||
* @param {Array<import("../Feature.js").default>} selected Selected features.
|
||||
* @param {Array<import("../Feature.js").default>} deselected Deselected features.
|
||||
* @param {import("../MapBrowserEvent.js").default} mapBrowserEvent Associated
|
||||
* {@link module:ol/MapBrowserEvent}.
|
||||
*/
|
||||
constructor(type, selected, deselected, mapBrowserEvent) {
|
||||
super(type);
|
||||
|
||||
/**
|
||||
* Selected features array.
|
||||
* @type {Array<import("../Feature.js").default>}
|
||||
* @api
|
||||
*/
|
||||
this.selected = selected;
|
||||
|
||||
/**
|
||||
* Deselected features array.
|
||||
* @type {Array<import("../Feature.js").default>}
|
||||
* @api
|
||||
*/
|
||||
this.deselected = deselected;
|
||||
|
||||
/**
|
||||
* Associated {@link module:ol/MapBrowserEvent}.
|
||||
* @type {import("../MapBrowserEvent.js").default}
|
||||
* @api
|
||||
*/
|
||||
this.mapBrowserEvent = mapBrowserEvent;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Interaction for selecting vector features. By default, selected features are
|
||||
* styled differently, so this interaction can be used for visual highlighting,
|
||||
* as well as selecting features for other actions, such as modification or
|
||||
* output. There are three ways of controlling which features are selected:
|
||||
* using the browser event as defined by the `condition` and optionally the
|
||||
* `toggle`, `add`/`remove`, and `multi` options; a `layers` filter; and a
|
||||
* further feature filter using the `filter` option.
|
||||
*
|
||||
* Selected features are added to an internal unmanaged layer.
|
||||
*
|
||||
* @fires SelectEvent
|
||||
* @api
|
||||
*/
|
||||
class Select extends Interaction {
|
||||
/**
|
||||
* @param {Options=} opt_options Options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
|
||||
super({
|
||||
handleEvent: handleEvent
|
||||
});
|
||||
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../events/condition.js").Condition}
|
||||
*/
|
||||
this.condition_ = options.condition ? options.condition : singleClick;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../events/condition.js").Condition}
|
||||
*/
|
||||
this.addCondition_ = options.addCondition ? options.addCondition : never;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../events/condition.js").Condition}
|
||||
*/
|
||||
this.removeCondition_ = options.removeCondition ? options.removeCondition : never;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../events/condition.js").Condition}
|
||||
*/
|
||||
this.toggleCondition_ = options.toggleCondition ? options.toggleCondition : shiftKeyOnly;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.multi_ = options.multi ? options.multi : false;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {FilterFunction}
|
||||
*/
|
||||
this.filter_ = options.filter ? options.filter : TRUE;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.hitTolerance_ = options.hitTolerance ? options.hitTolerance : 0;
|
||||
|
||||
const featureOverlay = new VectorLayer({
|
||||
source: new VectorSource({
|
||||
useSpatialIndex: false,
|
||||
features: options.features,
|
||||
wrapX: options.wrapX
|
||||
}),
|
||||
style: options.style ? options.style :
|
||||
getDefaultStyleFunction(),
|
||||
updateWhileAnimating: true,
|
||||
updateWhileInteracting: true
|
||||
});
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {VectorLayer}
|
||||
*/
|
||||
this.featureOverlay_ = featureOverlay;
|
||||
|
||||
/** @type {function(import("../layer/Layer.js").default): boolean} */
|
||||
let layerFilter;
|
||||
if (options.layers) {
|
||||
if (typeof options.layers === 'function') {
|
||||
layerFilter = options.layers;
|
||||
} else {
|
||||
const layers = options.layers;
|
||||
layerFilter = function(layer) {
|
||||
return includes(layers, layer);
|
||||
};
|
||||
}
|
||||
} else {
|
||||
layerFilter = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {function(import("../layer/Layer.js").default): boolean}
|
||||
*/
|
||||
this.layerFilter_ = layerFilter;
|
||||
|
||||
/**
|
||||
* An association between selected feature (key)
|
||||
* and layer (value)
|
||||
* @private
|
||||
* @type {Object<string, import("../layer/Layer.js").default>}
|
||||
*/
|
||||
this.featureLayerAssociation_ = {};
|
||||
|
||||
const features = this.getFeatures();
|
||||
features.addEventListener(CollectionEventType.ADD, this.addFeature_.bind(this));
|
||||
features.addEventListener(CollectionEventType.REMOVE, this.removeFeature_.bind(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("../Feature.js").FeatureLike} feature Feature.
|
||||
* @param {import("../layer/Layer.js").default} layer Layer.
|
||||
* @private
|
||||
*/
|
||||
addFeatureLayerAssociation_(feature, layer) {
|
||||
this.featureLayerAssociation_[getUid(feature)] = layer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the selected features.
|
||||
* @return {import("../Collection.js").default<import("../Feature.js").default>} Features collection.
|
||||
* @api
|
||||
*/
|
||||
getFeatures() {
|
||||
return this.featureOverlay_.getSource().getFeaturesCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Hit-detection tolerance.
|
||||
* @returns {number} Hit tolerance in pixels.
|
||||
* @api
|
||||
*/
|
||||
getHitTolerance() {
|
||||
return this.hitTolerance_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the associated {@link module:ol/layer/Vector~Vector vectorlayer} of
|
||||
* the (last) selected feature. Note that this will not work with any
|
||||
* programmatic method like pushing features to
|
||||
* {@link module:ol/interaction/Select~Select#getFeatures collection}.
|
||||
* @param {import("../Feature.js").FeatureLike} feature Feature
|
||||
* @return {VectorLayer} Layer.
|
||||
* @api
|
||||
*/
|
||||
getLayer(feature) {
|
||||
return (
|
||||
/** @type {VectorLayer} */ (this.featureLayerAssociation_[getUid(feature)])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the overlay layer that this interaction renders selected features to.
|
||||
* @return {VectorLayer} Overlay layer.
|
||||
* @api
|
||||
*/
|
||||
getOverlay() {
|
||||
return this.featureOverlay_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hit-detection tolerance. Pixels inside the radius around the given position
|
||||
* will be checked for features.
|
||||
* @param {number} hitTolerance Hit tolerance in pixels.
|
||||
* @api
|
||||
*/
|
||||
setHitTolerance(hitTolerance) {
|
||||
this.hitTolerance_ = hitTolerance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the interaction from its current map, if any, and attach it to a new
|
||||
* map, if any. Pass `null` to just remove the interaction from the current map.
|
||||
* @param {import("../PluggableMap.js").default} map Map.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
setMap(map) {
|
||||
const currentMap = this.getMap();
|
||||
const selectedFeatures = this.getFeatures();
|
||||
if (currentMap) {
|
||||
selectedFeatures.forEach(currentMap.unskipFeature.bind(currentMap));
|
||||
}
|
||||
super.setMap(map);
|
||||
this.featureOverlay_.setMap(map);
|
||||
if (map) {
|
||||
selectedFeatures.forEach(map.skipFeature.bind(map));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("../Collection.js").CollectionEvent} evt Event.
|
||||
* @private
|
||||
*/
|
||||
addFeature_(evt) {
|
||||
const map = this.getMap();
|
||||
if (map) {
|
||||
map.skipFeature(/** @type {import("../Feature.js").default} */ (evt.element));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("../Collection.js").CollectionEvent} evt Event.
|
||||
* @private
|
||||
*/
|
||||
removeFeature_(evt) {
|
||||
const map = this.getMap();
|
||||
if (map) {
|
||||
map.unskipFeature(/** @type {import("../Feature.js").default} */ (evt.element));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("../Feature.js").FeatureLike} feature Feature.
|
||||
* @private
|
||||
*/
|
||||
removeFeatureLayerAssociation_(feature) {
|
||||
delete this.featureLayerAssociation_[getUid(feature)];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handles the {@link module:ol/MapBrowserEvent map browser event} and may change the
|
||||
* selected state of features.
|
||||
* @param {import("../MapBrowserEvent.js").default} mapBrowserEvent Map browser event.
|
||||
* @return {boolean} `false` to stop event propagation.
|
||||
* @this {Select}
|
||||
*/
|
||||
function handleEvent(mapBrowserEvent) {
|
||||
if (!this.condition_(mapBrowserEvent)) {
|
||||
return true;
|
||||
}
|
||||
const add = this.addCondition_(mapBrowserEvent);
|
||||
const remove = this.removeCondition_(mapBrowserEvent);
|
||||
const toggle = this.toggleCondition_(mapBrowserEvent);
|
||||
const set = !add && !remove && !toggle;
|
||||
const map = mapBrowserEvent.map;
|
||||
const features = this.getFeatures();
|
||||
const deselected = [];
|
||||
const selected = [];
|
||||
if (set) {
|
||||
// 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.
|
||||
clear(this.featureLayerAssociation_);
|
||||
map.forEachFeatureAtPixel(mapBrowserEvent.pixel,
|
||||
(
|
||||
/**
|
||||
* @param {import("../Feature.js").FeatureLike} feature Feature.
|
||||
* @param {import("../layer/Layer.js").default} layer Layer.
|
||||
* @return {boolean|undefined} Continue to iterate over the features.
|
||||
*/
|
||||
function(feature, layer) {
|
||||
if (this.filter_(feature, layer)) {
|
||||
selected.push(feature);
|
||||
this.addFeatureLayerAssociation_(feature, layer);
|
||||
return !this.multi_;
|
||||
}
|
||||
}).bind(this), {
|
||||
layerFilter: this.layerFilter_,
|
||||
hitTolerance: this.hitTolerance_
|
||||
});
|
||||
for (let i = features.getLength() - 1; i >= 0; --i) {
|
||||
const feature = features.item(i);
|
||||
const index = selected.indexOf(feature);
|
||||
if (index > -1) {
|
||||
// feature is already selected
|
||||
selected.splice(index, 1);
|
||||
} else {
|
||||
features.remove(feature);
|
||||
deselected.push(feature);
|
||||
}
|
||||
}
|
||||
if (selected.length !== 0) {
|
||||
features.extend(selected);
|
||||
}
|
||||
} else {
|
||||
// Modify the currently selected feature(s).
|
||||
map.forEachFeatureAtPixel(mapBrowserEvent.pixel,
|
||||
(
|
||||
/**
|
||||
* @param {import("../Feature.js").FeatureLike} feature Feature.
|
||||
* @param {import("../layer/Layer.js").default} layer Layer.
|
||||
* @return {boolean|undefined} Continue to iterate over the features.
|
||||
*/
|
||||
function(feature, layer) {
|
||||
if (this.filter_(feature, layer)) {
|
||||
if ((add || toggle) && !includes(features.getArray(), feature)) {
|
||||
selected.push(feature);
|
||||
this.addFeatureLayerAssociation_(feature, layer);
|
||||
} else if ((remove || toggle) && includes(features.getArray(), feature)) {
|
||||
deselected.push(feature);
|
||||
this.removeFeatureLayerAssociation_(feature);
|
||||
}
|
||||
return !this.multi_;
|
||||
}
|
||||
}).bind(this), {
|
||||
layerFilter: this.layerFilter_,
|
||||
hitTolerance: this.hitTolerance_
|
||||
});
|
||||
for (let j = deselected.length - 1; j >= 0; --j) {
|
||||
features.remove(deselected[j]);
|
||||
}
|
||||
features.extend(selected);
|
||||
}
|
||||
if (selected.length > 0 || deselected.length > 0) {
|
||||
this.dispatchEvent(
|
||||
new SelectEvent(SelectEventType.SELECT,
|
||||
selected, deselected, mapBrowserEvent));
|
||||
}
|
||||
return pointerMove(mapBrowserEvent);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return {import("../style/Style.js").StyleFunction} Styles.
|
||||
*/
|
||||
function getDefaultStyleFunction() {
|
||||
const styles = createEditingStyle();
|
||||
extend(styles[GeometryType.POLYGON], styles[GeometryType.LINE_STRING]);
|
||||
extend(styles[GeometryType.GEOMETRY_COLLECTION], styles[GeometryType.LINE_STRING]);
|
||||
|
||||
return function(feature, resolution) {
|
||||
if (!feature.getGeometry()) {
|
||||
return null;
|
||||
}
|
||||
return styles[feature.getGeometry().getType()];
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
export default Select;
|
||||
@@ -1,14 +1,12 @@
|
||||
/**
|
||||
* @module ol/render/canvas/Executor
|
||||
*/
|
||||
import {getUid} from '../../util.js';
|
||||
import {equals} from '../../array.js';
|
||||
import {createEmpty, createOrUpdate,
|
||||
createOrUpdateEmpty, extend, intersects} from '../../extent.js';
|
||||
import {lineStringLength} from '../../geom/flat/length.js';
|
||||
import {drawTextOnPath} from '../../geom/flat/textpath.js';
|
||||
import {transform2D} from '../../geom/flat/transform.js';
|
||||
import {isEmpty} from '../../obj.js';
|
||||
import {drawImage, defaultPadding, defaultTextBaseline} from '../canvas.js';
|
||||
import CanvasInstruction from './Instruction.js';
|
||||
import {TEXT_ALIGN} from './TextBuilder.js';
|
||||
@@ -497,8 +495,6 @@ class Executor extends Disposable {
|
||||
* @private
|
||||
* @param {CanvasRenderingContext2D} context Context.
|
||||
* @param {import("../../transform.js").Transform} transform Transform.
|
||||
* @param {Object<string, boolean>} skippedFeaturesHash Ids of features
|
||||
* to skip.
|
||||
* @param {Array<*>} instructions Instructions array.
|
||||
* @param {boolean} snapToPixel Snap point symbols and text to integer pixels.
|
||||
* @param {function(import("../../Feature.js").FeatureLike): T|undefined} featureCallback Feature callback.
|
||||
@@ -510,7 +506,6 @@ class Executor extends Disposable {
|
||||
execute_(
|
||||
context,
|
||||
transform,
|
||||
skippedFeaturesHash,
|
||||
instructions,
|
||||
snapToPixel,
|
||||
featureCallback,
|
||||
@@ -530,7 +525,6 @@ class Executor extends Disposable {
|
||||
transform, this.pixelCoordinates_);
|
||||
transformSetFromArray(this.renderedTransform_, transform);
|
||||
}
|
||||
const skipFeatures = !isEmpty(skippedFeaturesHash);
|
||||
let i = 0; // instruction index
|
||||
const ii = instructions.length; // end of instructions
|
||||
let d = 0; // data index
|
||||
@@ -562,9 +556,7 @@ class Executor extends Disposable {
|
||||
switch (type) {
|
||||
case CanvasInstruction.BEGIN_GEOMETRY:
|
||||
feature = /** @type {import("../../Feature.js").FeatureLike} */ (instruction[1]);
|
||||
if ((skipFeatures && skippedFeaturesHash[getUid(feature)]) || !feature.getGeometry()) {
|
||||
i = /** @type {number} */ (instruction[2]);
|
||||
} else if (opt_hitExtent !== undefined && !intersects(
|
||||
if (opt_hitExtent !== undefined && !intersects(
|
||||
opt_hitExtent, feature.getGeometry().getExtent())) {
|
||||
i = /** @type {number} */ (instruction[2]) + 1;
|
||||
} else {
|
||||
@@ -871,22 +863,17 @@ class Executor extends Disposable {
|
||||
* @param {CanvasRenderingContext2D} context Context.
|
||||
* @param {import("../../transform.js").Transform} transform Transform.
|
||||
* @param {number} viewRotation View rotation.
|
||||
* @param {Object<string, boolean>} skippedFeaturesHash Ids of features
|
||||
* to skip.
|
||||
* @param {boolean} snapToPixel Snap point symbols and text to integer pixels.
|
||||
*/
|
||||
execute(context, transform, viewRotation, skippedFeaturesHash, snapToPixel) {
|
||||
execute(context, transform, viewRotation, snapToPixel) {
|
||||
this.viewRotation_ = viewRotation;
|
||||
this.execute_(context, transform,
|
||||
skippedFeaturesHash, this.instructions, snapToPixel, undefined, undefined);
|
||||
this.execute_(context, transform, this.instructions, snapToPixel, undefined, undefined);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {CanvasRenderingContext2D} context Context.
|
||||
* @param {import("../../transform.js").Transform} transform Transform.
|
||||
* @param {number} viewRotation View rotation.
|
||||
* @param {Object<string, boolean>} skippedFeaturesHash Ids of features
|
||||
* to skip.
|
||||
* @param {function(import("../../Feature.js").FeatureLike): T=} opt_featureCallback
|
||||
* Feature callback.
|
||||
* @param {import("../../extent.js").Extent=} opt_hitExtent Only check features that intersect this
|
||||
@@ -898,12 +885,11 @@ class Executor extends Disposable {
|
||||
context,
|
||||
transform,
|
||||
viewRotation,
|
||||
skippedFeaturesHash,
|
||||
opt_featureCallback,
|
||||
opt_hitExtent
|
||||
) {
|
||||
this.viewRotation_ = viewRotation;
|
||||
return this.execute_(context, transform, skippedFeaturesHash,
|
||||
return this.execute_(context, transform,
|
||||
this.hitDetectionInstructions, true, opt_featureCallback, opt_hitExtent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,7 +167,6 @@ class ExecutorGroup extends Disposable {
|
||||
* @param {number} resolution Resolution.
|
||||
* @param {number} rotation Rotation.
|
||||
* @param {number} hitTolerance Hit tolerance in pixels.
|
||||
* @param {Object<string, boolean>} skippedFeaturesHash Ids of features to skip.
|
||||
* @param {function(import("../../Feature.js").FeatureLike): T} callback Feature callback.
|
||||
* @param {Array<import("../../Feature.js").FeatureLike>} declutteredFeatures Decluttered features.
|
||||
* @return {T|undefined} Callback result.
|
||||
@@ -178,7 +177,6 @@ class ExecutorGroup extends Disposable {
|
||||
resolution,
|
||||
rotation,
|
||||
hitTolerance,
|
||||
skippedFeaturesHash,
|
||||
callback,
|
||||
declutteredFeatures
|
||||
) {
|
||||
@@ -256,8 +254,7 @@ class ExecutorGroup extends Disposable {
|
||||
builderType = ORDER[j];
|
||||
executor = executors[builderType];
|
||||
if (executor !== undefined) {
|
||||
result = executor.executeHitDetection(context, transform, rotation,
|
||||
skippedFeaturesHash, featureCallback, hitExtent);
|
||||
result = executor.executeHitDetection(context, transform, rotation, featureCallback, hitExtent);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
@@ -297,14 +294,12 @@ class ExecutorGroup extends Disposable {
|
||||
* @param {CanvasRenderingContext2D} context Context.
|
||||
* @param {import("../../transform.js").Transform} transform Transform.
|
||||
* @param {number} viewRotation View rotation.
|
||||
* @param {Object<string, boolean>} skippedFeaturesHash Ids of features to skip.
|
||||
* @param {boolean} snapToPixel Snap point symbols and test to integer pixel.
|
||||
* @param {Array<BuilderType>=} opt_builderTypes Ordered replay types to replay.
|
||||
* Default is {@link module:ol/render/replay~ORDER}
|
||||
* @param {Object<string, import("../canvas.js").DeclutterGroup>=} opt_declutterReplays Declutter replays.
|
||||
*/
|
||||
execute(context, transform, viewRotation, skippedFeaturesHash, snapToPixel, opt_builderTypes,
|
||||
opt_declutterReplays) {
|
||||
execute(context, transform, viewRotation, snapToPixel, opt_builderTypes, opt_declutterReplays) {
|
||||
|
||||
/** @type {Array<number>} */
|
||||
const zs = Object.keys(this.executorsByZIndex_).map(Number);
|
||||
@@ -335,7 +330,7 @@ class ExecutorGroup extends Disposable {
|
||||
declutter.push(replay, transform.slice(0));
|
||||
}
|
||||
} else {
|
||||
replay.execute(context, transform, viewRotation, skippedFeaturesHash, snapToPixel);
|
||||
replay.execute(context, transform, viewRotation, snapToPixel);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -436,7 +431,6 @@ export function getCircleArray(radius) {
|
||||
*/
|
||||
export function replayDeclutter(declutterReplays, context, rotation, opacity, snapToPixel, declutterItems) {
|
||||
const zs = Object.keys(declutterReplays).map(Number).sort(numberSafeCompareFunction);
|
||||
const skippedFeatureUids = {};
|
||||
for (let z = 0, zz = zs.length; z < zz; ++z) {
|
||||
const executorData = declutterReplays[zs[z].toString()];
|
||||
let currentExecutor;
|
||||
@@ -450,7 +444,7 @@ export function replayDeclutter(declutterReplays, context, rotation, opacity, sn
|
||||
});
|
||||
}
|
||||
const transform = executorData[i++];
|
||||
executor.execute(context, transform, rotation, skippedFeatureUids, snapToPixel);
|
||||
executor.execute(context, transform, rotation, snapToPixel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @module ol/renderer/Map
|
||||
*/
|
||||
import {abstract, getUid} from '../util.js';
|
||||
import {abstract} from '../util.js';
|
||||
import Disposable from '../Disposable.js';
|
||||
import {getWidth} from '../extent.js';
|
||||
import {TRUE} from '../functions.js';
|
||||
@@ -95,8 +95,8 @@ class MapRenderer extends Disposable {
|
||||
* @return {?} Callback result.
|
||||
*/
|
||||
function forEachFeatureAtCoordinate(managed, feature, layer) {
|
||||
if (!(getUid(feature) in frameState.skippedFeatureUids && !managed)) {
|
||||
return callback.call(thisArg, feature, managed ? layer : null);
|
||||
if (managed) {
|
||||
return callback.call(thisArg, feature, layer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
*/
|
||||
import ImageCanvas from '../../ImageCanvas.js';
|
||||
import ViewHint from '../../ViewHint.js';
|
||||
import {equals} from '../../array.js';
|
||||
import {getHeight, getWidth, isEmpty, scaleFromCenter} from '../../extent.js';
|
||||
import {assign} from '../../obj.js';
|
||||
import CanvasImageLayerRenderer from './ImageLayer.js';
|
||||
@@ -25,11 +24,6 @@ class CanvasVectorImageLayerRenderer extends CanvasImageLayerRenderer {
|
||||
constructor(layer) {
|
||||
super(layer);
|
||||
|
||||
/**
|
||||
* @type {!Array<string>}
|
||||
*/
|
||||
this.skippedFeatures_ = [];
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("./VectorLayer.js").default}
|
||||
@@ -76,7 +70,6 @@ class CanvasVectorImageLayerRenderer extends CanvasImageLayerRenderer {
|
||||
}
|
||||
|
||||
if (!hints[ViewHint.ANIMATING] && !hints[ViewHint.INTERACTING] && !isEmpty(renderedExtent)) {
|
||||
let skippedFeatures = this.skippedFeatures_;
|
||||
vectorRenderer.useContainer(null, null, 1);
|
||||
const context = vectorRenderer.context;
|
||||
const imageFrameState = /** @type {import("../../PluggableMap.js").FrameState} */ (assign({}, frameState, {
|
||||
@@ -89,14 +82,10 @@ class CanvasVectorImageLayerRenderer extends CanvasImageLayerRenderer {
|
||||
rotation: 0
|
||||
}))
|
||||
}));
|
||||
const newSkippedFeatures = Object.keys(imageFrameState.skippedFeatureUids).sort();
|
||||
const image = new ImageCanvas(renderedExtent, viewResolution, pixelRatio, context.canvas, function(callback) {
|
||||
if (vectorRenderer.prepareFrame(imageFrameState) &&
|
||||
(vectorRenderer.replayGroupChanged ||
|
||||
!equals(skippedFeatures, newSkippedFeatures))) {
|
||||
if (vectorRenderer.prepareFrame(imageFrameState) && vectorRenderer.replayGroupChanged) {
|
||||
vectorRenderer.renderFrame(imageFrameState, null);
|
||||
renderDeclutterItems(imageFrameState, null);
|
||||
skippedFeatures = newSkippedFeatures;
|
||||
callback();
|
||||
}
|
||||
});
|
||||
@@ -104,7 +93,6 @@ class CanvasVectorImageLayerRenderer extends CanvasImageLayerRenderer {
|
||||
image.addEventListener(EventType.CHANGE, function() {
|
||||
if (image.getState() === ImageState.LOADED) {
|
||||
this.image_ = image;
|
||||
this.skippedFeatures_ = skippedFeatures;
|
||||
}
|
||||
}.bind(this));
|
||||
image.load();
|
||||
|
||||
@@ -144,9 +144,8 @@ class CanvasVectorLayerRenderer extends CanvasLayerRenderer {
|
||||
const snapToPixel = !(viewHints[ViewHint.ANIMATING] || viewHints[ViewHint.INTERACTING]);
|
||||
|
||||
const transform = this.getRenderTransform(frameState, width, height, 0);
|
||||
const skippedFeatureUids = layerState.managed ? frameState.skippedFeatureUids : {};
|
||||
const declutterReplays = /** @type {import("../../layer/Vector.js").default} */ (this.getLayer()).getDeclutter() ? {} : null;
|
||||
replayGroup.execute(context, transform, rotation, skippedFeatureUids, snapToPixel, undefined, declutterReplays);
|
||||
replayGroup.execute(context, transform, rotation, snapToPixel, undefined, declutterReplays);
|
||||
|
||||
if (vectorSource.getWrapX() && projection.canWrapX() && !containsExtent(projectionExtent, extent)) {
|
||||
let startX = extent[0];
|
||||
@@ -157,7 +156,7 @@ class CanvasVectorLayerRenderer extends CanvasLayerRenderer {
|
||||
--world;
|
||||
offsetX = worldWidth * world;
|
||||
const transform = this.getRenderTransform(frameState, width, height, offsetX);
|
||||
replayGroup.execute(context, transform, rotation, skippedFeatureUids, snapToPixel, undefined, declutterReplays);
|
||||
replayGroup.execute(context, transform, rotation, snapToPixel, undefined, declutterReplays);
|
||||
startX += worldWidth;
|
||||
}
|
||||
world = 0;
|
||||
@@ -166,7 +165,7 @@ class CanvasVectorLayerRenderer extends CanvasLayerRenderer {
|
||||
++world;
|
||||
offsetX = worldWidth * world;
|
||||
const transform = this.getRenderTransform(frameState, width, height, offsetX);
|
||||
replayGroup.execute(context, transform, rotation, skippedFeatureUids, snapToPixel, undefined, declutterReplays);
|
||||
replayGroup.execute(context, transform, rotation, snapToPixel, undefined, declutterReplays);
|
||||
startX -= worldWidth;
|
||||
}
|
||||
}
|
||||
@@ -203,7 +202,7 @@ class CanvasVectorLayerRenderer extends CanvasLayerRenderer {
|
||||
const layer = /** @type {import("../../layer/Vector").default} */ (this.getLayer());
|
||||
/** @type {!Object<string, boolean>} */
|
||||
const features = {};
|
||||
const result = this.replayGroup_.forEachFeatureAtCoordinate(coordinate, resolution, rotation, hitTolerance, {},
|
||||
const result = this.replayGroup_.forEachFeatureAtCoordinate(coordinate, resolution, rotation, hitTolerance,
|
||||
/**
|
||||
* @param {import("../../Feature.js").FeatureLike} feature Feature.
|
||||
* @return {?} Callback result.
|
||||
|
||||
@@ -357,7 +357,7 @@ class CanvasVectorTileLayerRenderer extends CanvasTileLayerRenderer {
|
||||
const executorGroups = tile.executorGroups[getUid(layer)];
|
||||
for (let t = 0, tt = executorGroups.length; t < tt; ++t) {
|
||||
const executorGroup = executorGroups[t];
|
||||
found = found || executorGroup.forEachFeatureAtCoordinate(coordinate, resolution, rotation, hitTolerance, {},
|
||||
found = found || executorGroup.forEachFeatureAtCoordinate(coordinate, resolution, rotation, hitTolerance,
|
||||
/**
|
||||
* @param {import("../../Feature.js").FeatureLike} feature Feature.
|
||||
* @return {?} Callback result.
|
||||
@@ -497,7 +497,7 @@ class CanvasVectorTileLayerRenderer extends CanvasTileLayerRenderer {
|
||||
}
|
||||
}
|
||||
}
|
||||
executorGroup.execute(context, transform, rotation, {}, hifi, replayTypes, declutterReplays);
|
||||
executorGroup.execute(context, transform, rotation, hifi, replayTypes, declutterReplays);
|
||||
if (!declutterReplays && !clipped) {
|
||||
context.restore();
|
||||
clips.push(currentClip);
|
||||
@@ -617,7 +617,7 @@ class CanvasVectorTileLayerRenderer extends CanvasTileLayerRenderer {
|
||||
translateTransform(transform, -tileExtent[0], -tileExtent[3]);
|
||||
for (let i = 0, ii = executorGroups.length; i < ii; ++i) {
|
||||
const executorGroup = executorGroups[i];
|
||||
executorGroup.execute(context, transform, 0, {}, true, IMAGE_REPLAYS[layer.getRenderMode()]);
|
||||
executorGroup.execute(context, transform, 0, true, IMAGE_REPLAYS[layer.getRenderMode()]);
|
||||
}
|
||||
replayState.renderedTileResolution = tile.wantedResolution;
|
||||
}
|
||||
|
||||
@@ -220,7 +220,6 @@ class RasterSource extends ImageSource {
|
||||
pixelToCoordinateTransform: createTransform(),
|
||||
postRenderFunctions: [],
|
||||
size: [0, 0],
|
||||
skippedFeatureUids: {},
|
||||
tileQueue: this.tileQueue_,
|
||||
time: Date.now(),
|
||||
usedTiles: {},
|
||||
|
||||
Reference in New Issue
Block a user