Merge pull request #10572 from ahocevar/assert-no-duplicate-layers
Assert each layer is only added to the map once
This commit is contained in:
@@ -245,3 +245,7 @@ Layer opacity must be a number.
|
|||||||
|
|
||||||
`forEachFeatureAtCoordinate` cannot be used on a WebGL layer if the hit detection logic has not been enabled.
|
`forEachFeatureAtCoordinate` cannot be used on a WebGL layer if the hit detection logic has not been enabled.
|
||||||
This is done by providing adequate shaders using the `hitVertexShader` and `hitFragmentShader` properties of `WebGLPointsLayerRenderer`.
|
This is done by providing adequate shaders using the `hitVertexShader` and `hitFragmentShader` properties of `WebGLPointsLayerRenderer`.
|
||||||
|
|
||||||
|
### 67
|
||||||
|
|
||||||
|
A layer can only be added to the map once. Use either `layer.setMap()` or `map.addLayer()`, not both.
|
||||||
@@ -9,6 +9,7 @@ import LayerProperty from './Property.js';
|
|||||||
import {assign} from '../obj.js';
|
import {assign} from '../obj.js';
|
||||||
import RenderEventType from '../render/EventType.js';
|
import RenderEventType from '../render/EventType.js';
|
||||||
import SourceState from '../source/State.js';
|
import SourceState from '../source/State.js';
|
||||||
|
import {assert} from '../asserts.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {function(import("../PluggableMap.js").FrameState):HTMLElement} RenderFunction
|
* @typedef {function(import("../PluggableMap.js").FrameState):HTMLElement} RenderFunction
|
||||||
@@ -243,7 +244,13 @@ 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);
|
||||||
renderEvent.frameState.layerStatesArray.push(this.getLayerState(false));
|
const layerStatesArray = renderEvent.frameState.layerStatesArray;
|
||||||
|
const layerState = this.getLayerState(false);
|
||||||
|
// A layer can only be added to the map once. Use either `layer.setMap()` or `map.addLayer()`, not both.
|
||||||
|
assert(!layerStatesArray.some(function(arrayLayerState) {
|
||||||
|
return arrayLayerState.layer === layerState.layer;
|
||||||
|
}), 67);
|
||||||
|
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();
|
||||||
|
|||||||
@@ -631,8 +631,7 @@ describe('ol.layer.Layer', function() {
|
|||||||
map: map
|
map: map
|
||||||
});
|
});
|
||||||
frameState = {
|
frameState = {
|
||||||
layerStatesArray: [],
|
layerStatesArray: []
|
||||||
layerStates: {}
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -651,6 +650,7 @@ describe('ol.layer.Layer', function() {
|
|||||||
layer.setZIndex(index);
|
layer.setZIndex(index);
|
||||||
map.dispatchEvent(new RenderEvent('precompose', null, frameState, null));
|
map.dispatchEvent(new RenderEvent('precompose', null, frameState, null));
|
||||||
const layerState = frameState.layerStatesArray[0];
|
const layerState = frameState.layerStatesArray[0];
|
||||||
|
frameState.layerStatesArray.length = 0;
|
||||||
expect(layerState.zIndex).to.be(index);
|
expect(layerState.zIndex).to.be(index);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user