Merge pull request #8515 from ahocevar/getoverlay
More convenient select and sketch layer management
This commit is contained in:
@@ -441,6 +441,15 @@ class Draw extends PointerInteraction {
|
||||
this.updateState_();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the overlay layer that this interaction renders sketch features to.
|
||||
* @return {module:ol/layer/Vector} Overlay layer.
|
||||
* @api
|
||||
*/
|
||||
getOverlay() {
|
||||
return this.overlay_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle move events.
|
||||
* @param {module:ol/MapBrowserEvent} event A move event.
|
||||
|
||||
@@ -422,6 +422,15 @@ class Modify extends PointerInteraction {
|
||||
super.setMap(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the overlay layer that this interaction renders sketch features to.
|
||||
* @return {module:ol/layer/Vector} Overlay layer.
|
||||
* @api
|
||||
*/
|
||||
getOverlay() {
|
||||
return this.overlay_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {module:ol/source/Vector~VectorSourceEvent} event Event.
|
||||
* @private
|
||||
|
||||
@@ -255,11 +255,13 @@ class Select extends Interaction {
|
||||
*/
|
||||
this.featureLayerAssociation_ = {};
|
||||
|
||||
const features = this.featureOverlay_.getSource().getFeaturesCollection();
|
||||
listen(features, CollectionEventType.ADD,
|
||||
this.addFeature_, this);
|
||||
listen(features, CollectionEventType.REMOVE,
|
||||
this.removeFeature_, this);
|
||||
if (this.featureOverlay_) {
|
||||
const features = this.featureOverlay_.getSource().getFeaturesCollection();
|
||||
listen(features, CollectionEventType.ADD,
|
||||
this.addFeature_, this);
|
||||
listen(features, CollectionEventType.REMOVE,
|
||||
this.removeFeature_, this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -307,6 +309,15 @@ class Select extends Interaction {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the overlay layer that this interaction renders selected features to.
|
||||
* @return {module:ol/layer/Vector} Overlay layer.
|
||||
* @api
|
||||
*/
|
||||
getOverlay() {
|
||||
return this.featureOverlay_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hit-detection tolerance. Pixels inside the radius around the given position
|
||||
* will be checked for features. This only works for the canvas renderer and
|
||||
|
||||
@@ -13,8 +13,10 @@ import {assign} from '../obj.js';
|
||||
* @property {boolean} [visible=true] Visibility.
|
||||
* @property {module:ol/extent~Extent} [extent] The bounding extent for layer rendering. The layer will not be
|
||||
* rendered outside of this extent.
|
||||
* @property {number} [zIndex=0] The z-index for layer rendering. At rendering time, the layers
|
||||
* will be ordered, first by Z-index and then by position.
|
||||
* @property {number} [zIndex] The z-index for layer rendering. At rendering time, the layers
|
||||
* will be ordered, first by Z-index and then by position. When `undefined`, a `zIndex` of 0 is assumed
|
||||
* for layers that are added to the map's `layers` collection, or `Infinity` when the layer's `setMap()`
|
||||
* method was used.
|
||||
* @property {number} [minResolution] The minimum resolution (inclusive) at which this layer will be
|
||||
* visible.
|
||||
* @property {number} [maxResolution] The maximum resolution (exclusive) below which this layer will
|
||||
@@ -48,8 +50,7 @@ class BaseLayer extends BaseObject {
|
||||
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.Z_INDEX] = options.zIndex;
|
||||
properties[LayerProperty.MAX_RESOLUTION] =
|
||||
options.maxResolution !== undefined ? options.maxResolution : Infinity;
|
||||
properties[LayerProperty.MIN_RESOLUTION] =
|
||||
@@ -91,7 +92,7 @@ class BaseLayer extends BaseObject {
|
||||
this.state_.sourceState = this.getSourceState();
|
||||
this.state_.visible = this.getVisible();
|
||||
this.state_.extent = this.getExtent();
|
||||
this.state_.zIndex = this.getZIndex();
|
||||
this.state_.zIndex = this.getZIndex() || 0;
|
||||
this.state_.maxResolution = this.getMaxResolution();
|
||||
this.state_.minResolution = Math.max(this.getMinResolution(), 0);
|
||||
|
||||
|
||||
@@ -191,7 +191,9 @@ class Layer extends BaseLayer {
|
||||
this.mapPrecomposeKey_ = listen(map, RenderEventType.PRECOMPOSE, function(evt) {
|
||||
const layerState = this.getLayerState();
|
||||
layerState.managed = false;
|
||||
layerState.zIndex = Infinity;
|
||||
if (this.getZIndex() === undefined) {
|
||||
layerState.zIndex = Infinity;
|
||||
}
|
||||
evt.frameState.layerStatesArray.push(layerState);
|
||||
evt.frameState.layerStates[getUid(this)] = layerState;
|
||||
}, this);
|
||||
|
||||
@@ -1060,6 +1060,13 @@ describe('ol.interaction.Draw', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getOverlay', function() {
|
||||
it('returns the feature overlay layer', function() {
|
||||
const draw = new Draw({});
|
||||
expect (draw.getOverlay()).to.eql(draw.overlay_);
|
||||
});
|
||||
});
|
||||
|
||||
describe('createRegularPolygon', function() {
|
||||
it('creates a regular polygon in Circle mode', function() {
|
||||
const draw = new Draw({
|
||||
|
||||
@@ -712,4 +712,13 @@ describe('ol.interaction.Modify', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getOverlay', function() {
|
||||
it('returns the feature overlay layer', function() {
|
||||
const modify = new Modify({
|
||||
features: new Collection()
|
||||
});
|
||||
expect (modify.getOverlay()).to.eql(modify.overlay_);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -442,4 +442,11 @@ describe('ol.interaction.Select', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getOverlay', function() {
|
||||
it('returns the feature overlay layer', function() {
|
||||
const select = new Select();
|
||||
expect (select.getOverlay()).to.eql(select.featureOverlay_);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -434,6 +434,41 @@ describe('ol.layer.Layer', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('zIndex for unmanaged layers', function() {
|
||||
|
||||
let frameState, layer;
|
||||
|
||||
beforeEach(function() {
|
||||
layer = new Layer({
|
||||
map: map
|
||||
});
|
||||
frameState = {
|
||||
layerStatesArray: [],
|
||||
layerStates: {}
|
||||
};
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
layer.setMap(null);
|
||||
});
|
||||
|
||||
it('has Infinity as zIndex when not configured otherwise', function() {
|
||||
map.dispatchEvent(new RenderEvent('precompose', null,
|
||||
frameState, null, null));
|
||||
const layerState = frameState.layerStatesArray[0];
|
||||
expect(layerState.zIndex).to.be(Infinity);
|
||||
});
|
||||
|
||||
it('respects the configured zIndex', function() {
|
||||
layer.setZIndex(42);
|
||||
map.dispatchEvent(new RenderEvent('precompose', null,
|
||||
frameState, null, null));
|
||||
const layerState = frameState.layerStatesArray[0];
|
||||
expect(layerState.zIndex).to.be(42);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user