Merge pull request #8515 from ahocevar/getoverlay

More convenient select and sketch layer management
This commit is contained in:
Andreas Hocevar
2018-08-15 13:21:48 +02:00
committed by GitHub
9 changed files with 101 additions and 11 deletions
+9
View File
@@ -441,6 +441,15 @@ class Draw extends PointerInteraction {
this.updateState_(); 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. * Handle move events.
* @param {module:ol/MapBrowserEvent} event A move event. * @param {module:ol/MapBrowserEvent} event A move event.
+9
View File
@@ -422,6 +422,15 @@ class Modify extends PointerInteraction {
super.setMap(map); 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. * @param {module:ol/source/Vector~VectorSourceEvent} event Event.
* @private * @private
+16 -5
View File
@@ -255,11 +255,13 @@ class Select extends Interaction {
*/ */
this.featureLayerAssociation_ = {}; this.featureLayerAssociation_ = {};
const features = this.featureOverlay_.getSource().getFeaturesCollection(); if (this.featureOverlay_) {
listen(features, CollectionEventType.ADD, const features = this.featureOverlay_.getSource().getFeaturesCollection();
this.addFeature_, this); listen(features, CollectionEventType.ADD,
listen(features, CollectionEventType.REMOVE, this.addFeature_, this);
this.removeFeature_, 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 * Hit-detection tolerance. Pixels inside the radius around the given position
* will be checked for features. This only works for the canvas renderer and * will be checked for features. This only works for the canvas renderer and
+6 -5
View File
@@ -13,8 +13,10 @@ import {assign} from '../obj.js';
* @property {boolean} [visible=true] Visibility. * @property {boolean} [visible=true] Visibility.
* @property {module:ol/extent~Extent} [extent] The bounding extent for layer rendering. The layer will not be * @property {module:ol/extent~Extent} [extent] The bounding extent for layer rendering. The layer will not be
* rendered outside of this extent. * rendered outside of this extent.
* @property {number} [zIndex=0] The z-index for layer rendering. At rendering time, the layers * @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. * 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 * @property {number} [minResolution] The minimum resolution (inclusive) at which this layer will be
* visible. * visible.
* @property {number} [maxResolution] The maximum resolution (exclusive) below which this layer will * @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; options.opacity !== undefined ? options.opacity : 1;
properties[LayerProperty.VISIBLE] = properties[LayerProperty.VISIBLE] =
options.visible !== undefined ? options.visible : true; options.visible !== undefined ? options.visible : true;
properties[LayerProperty.Z_INDEX] = properties[LayerProperty.Z_INDEX] = options.zIndex;
options.zIndex !== undefined ? options.zIndex : 0;
properties[LayerProperty.MAX_RESOLUTION] = properties[LayerProperty.MAX_RESOLUTION] =
options.maxResolution !== undefined ? options.maxResolution : Infinity; options.maxResolution !== undefined ? options.maxResolution : Infinity;
properties[LayerProperty.MIN_RESOLUTION] = properties[LayerProperty.MIN_RESOLUTION] =
@@ -91,7 +92,7 @@ class BaseLayer extends BaseObject {
this.state_.sourceState = this.getSourceState(); this.state_.sourceState = this.getSourceState();
this.state_.visible = this.getVisible(); this.state_.visible = this.getVisible();
this.state_.extent = this.getExtent(); this.state_.extent = this.getExtent();
this.state_.zIndex = this.getZIndex(); this.state_.zIndex = this.getZIndex() || 0;
this.state_.maxResolution = this.getMaxResolution(); this.state_.maxResolution = this.getMaxResolution();
this.state_.minResolution = Math.max(this.getMinResolution(), 0); this.state_.minResolution = Math.max(this.getMinResolution(), 0);
+3 -1
View File
@@ -191,7 +191,9 @@ class Layer extends BaseLayer {
this.mapPrecomposeKey_ = listen(map, RenderEventType.PRECOMPOSE, function(evt) { this.mapPrecomposeKey_ = listen(map, RenderEventType.PRECOMPOSE, function(evt) {
const layerState = this.getLayerState(); const layerState = this.getLayerState();
layerState.managed = false; layerState.managed = false;
layerState.zIndex = Infinity; if (this.getZIndex() === undefined) {
layerState.zIndex = Infinity;
}
evt.frameState.layerStatesArray.push(layerState); evt.frameState.layerStatesArray.push(layerState);
evt.frameState.layerStates[getUid(this)] = layerState; evt.frameState.layerStates[getUid(this)] = layerState;
}, this); }, this);
+7
View File
@@ -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() { describe('createRegularPolygon', function() {
it('creates a regular polygon in Circle mode', function() { it('creates a regular polygon in Circle mode', function() {
const draw = new Draw({ const draw = new Draw({
+9
View File
@@ -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_);
});
});
}); });
+7
View File
@@ -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_);
});
});
}); });
+35
View File
@@ -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);
});
});
}); });
}); });