Layer / accepts a custom render function
This commit is contained in:
@@ -10,6 +10,10 @@ 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';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {function(import("../PluggableMap.js").FrameState):HTMLElement} RenderFunction
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} Options
|
* @typedef {Object} Options
|
||||||
@@ -29,6 +33,8 @@ import SourceState from '../source/State.js';
|
|||||||
* the source can be set by calling {@link module:ol/layer/Layer#setSource layer.setSource(source)} after
|
* the source can be set by calling {@link module:ol/layer/Layer#setSource layer.setSource(source)} after
|
||||||
* construction.
|
* construction.
|
||||||
* @property {import("../PluggableMap.js").default} [map] Map.
|
* @property {import("../PluggableMap.js").default} [map] Map.
|
||||||
|
* @property {RenderFunction} [render] Render function. Takes the frame state as input and is expected to return an
|
||||||
|
* HTML element. Will overwrite the default rendering for the layer.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -100,6 +106,11 @@ class Layer extends BaseLayer {
|
|||||||
*/
|
*/
|
||||||
this.renderer_ = null;
|
this.renderer_ = null;
|
||||||
|
|
||||||
|
// Overwrite default render method with a custom one
|
||||||
|
if (options.render) {
|
||||||
|
this.render = options.render;
|
||||||
|
}
|
||||||
|
|
||||||
if (options.map) {
|
if (options.map) {
|
||||||
this.setMap(options.map);
|
this.setMap(options.map);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,6 +94,16 @@ describe('ol.layer.Layer', function() {
|
|||||||
layer.dispose();
|
layer.dispose();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('accepts a custom render function', function() {
|
||||||
|
let called = false;
|
||||||
|
const layer = new Layer({
|
||||||
|
render: function() {
|
||||||
|
called = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
layer.render();
|
||||||
|
expect(called).to.eql(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('visibleAtResolution', function() {
|
describe('visibleAtResolution', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user