Fix zIndex handling for unmanaged layers
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 101 KiB After Width: | Height: | Size: 101 KiB |
@@ -4,8 +4,10 @@ import {Vector as VectorLayer, Tile as TileLayer} from '../../../src/ol/layer.js
|
|||||||
import {Vector as VectorSource, XYZ} from '../../../src/ol/source.js';
|
import {Vector as VectorSource, XYZ} from '../../../src/ol/source.js';
|
||||||
import GeoJSON from '../../../src/ol/format/GeoJSON.js';
|
import GeoJSON from '../../../src/ol/format/GeoJSON.js';
|
||||||
import {Style, Stroke} from '../../../src/ol/style.js';
|
import {Style, Stroke} from '../../../src/ol/style.js';
|
||||||
|
import Feature from '../../../src/ol/Feature.js';
|
||||||
|
import Point from '../../../src/ol/geom/Point.js';
|
||||||
|
|
||||||
new Map({
|
const map = new Map({
|
||||||
layers: [
|
layers: [
|
||||||
new TileLayer({
|
new TileLayer({
|
||||||
source: new XYZ({
|
source: new XYZ({
|
||||||
@@ -14,6 +16,7 @@ new Map({
|
|||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
new VectorLayer({
|
new VectorLayer({
|
||||||
|
zIndex: 1,
|
||||||
style: new Style({
|
style: new Style({
|
||||||
stroke: new Stroke({
|
stroke: new Stroke({
|
||||||
color: 'rgba(255,255,255,0.5)',
|
color: 'rgba(255,255,255,0.5)',
|
||||||
@@ -33,4 +36,11 @@ new Map({
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const unmanaged = new VectorLayer({
|
||||||
|
source: new VectorSource({
|
||||||
|
features: [new Feature(new Point([0, 0]))]
|
||||||
|
})
|
||||||
|
});
|
||||||
|
unmanaged.setMap(map);
|
||||||
|
|
||||||
render();
|
render();
|
||||||
|
|||||||
@@ -83,19 +83,20 @@ class BaseLayer extends BaseObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param {boolean=} opt_managed Layer is managed.
|
||||||
* @return {import("./Layer.js").State} Layer state.
|
* @return {import("./Layer.js").State} Layer state.
|
||||||
*/
|
*/
|
||||||
getLayerState() {
|
getLayerState(opt_managed) {
|
||||||
/** @type {import("./Layer.js").State} */
|
/** @type {import("./Layer.js").State} */
|
||||||
const state = this.state_ || /** @type {?} */ ({
|
const state = this.state_ || /** @type {?} */ ({
|
||||||
layer: this,
|
layer: this,
|
||||||
managed: true
|
managed: opt_managed === undefined ? true : opt_managed
|
||||||
});
|
});
|
||||||
state.opacity = clamp(Math.round(this.getOpacity() * 100) / 100, 0, 1);
|
state.opacity = clamp(Math.round(this.getOpacity() * 100) / 100, 0, 1);
|
||||||
state.sourceState = this.getSourceState();
|
state.sourceState = this.getSourceState();
|
||||||
state.visible = this.getVisible();
|
state.visible = this.getVisible();
|
||||||
state.extent = this.getExtent();
|
state.extent = this.getExtent();
|
||||||
state.zIndex = this.getZIndex() || 0;
|
state.zIndex = this.getZIndex() || (state.managed === false ? Infinity : 0);
|
||||||
state.maxResolution = this.getMaxResolution();
|
state.maxResolution = this.getMaxResolution();
|
||||||
state.minResolution = Math.max(this.getMinResolution(), 0);
|
state.minResolution = Math.max(this.getMinResolution(), 0);
|
||||||
this.state_ = state;
|
this.state_ = state;
|
||||||
|
|||||||
@@ -212,12 +212,7 @@ class Layer extends BaseLayer {
|
|||||||
if (map) {
|
if (map) {
|
||||||
this.mapPrecomposeKey_ = listen(map, RenderEventType.PRECOMPOSE, function(evt) {
|
this.mapPrecomposeKey_ = listen(map, RenderEventType.PRECOMPOSE, function(evt) {
|
||||||
const renderEvent = /** @type {import("../render/Event.js").default} */ (evt);
|
const renderEvent = /** @type {import("../render/Event.js").default} */ (evt);
|
||||||
const layerState = this.getLayerState();
|
renderEvent.frameState.layerStatesArray.push(this.getLayerState(false));
|
||||||
layerState.managed = false;
|
|
||||||
if (this.getZIndex() === undefined) {
|
|
||||||
layerState.zIndex = Infinity;
|
|
||||||
}
|
|
||||||
renderEvent.frameState.layerStatesArray.push(layerState);
|
|
||||||
}, this);
|
}, this);
|
||||||
this.mapRenderKey_ = listen(this, EventType.CHANGE, map.render, map);
|
this.mapRenderKey_ = listen(this, EventType.CHANGE, map.render, map);
|
||||||
this.changed();
|
this.changed();
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ class CompositeMapRenderer extends MapRenderer {
|
|||||||
if (element) {
|
if (element) {
|
||||||
const zIndex = layerState.zIndex;
|
const zIndex = layerState.zIndex;
|
||||||
if (zIndex !== element.style.zIndex) {
|
if (zIndex !== element.style.zIndex) {
|
||||||
element.style.zIndex = zIndex;
|
element.style.zIndex = zIndex === Infinity ? Number.MAX_SAFE_INTEGER : zIndex;
|
||||||
}
|
}
|
||||||
this.children_.push(element);
|
this.children_.push(element);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user