Explicit map renderer construction
This commit is contained in:
@@ -7,14 +7,13 @@ import PluginType from './PluginType.js';
|
||||
import {defaults as defaultControls} from './control.js';
|
||||
import {defaults as defaultInteractions} from './interaction.js';
|
||||
import {assign} from './obj.js';
|
||||
import {register, registerMultiple} from './plugins.js';
|
||||
import {registerMultiple} from './plugins.js';
|
||||
import CanvasImageLayerRenderer from './renderer/canvas/ImageLayer.js';
|
||||
import CanvasMapRenderer from './renderer/canvas/Map.js';
|
||||
import CanvasTileLayerRenderer from './renderer/canvas/TileLayer.js';
|
||||
import CanvasVectorLayerRenderer from './renderer/canvas/VectorLayer.js';
|
||||
import CanvasVectorTileLayerRenderer from './renderer/canvas/VectorTileLayer.js';
|
||||
|
||||
register(PluginType.MAP_RENDERER, CanvasMapRenderer);
|
||||
registerMultiple(PluginType.LAYER_RENDERER, [
|
||||
CanvasImageLayerRenderer,
|
||||
CanvasTileLayerRenderer,
|
||||
@@ -90,4 +89,8 @@ const Map = function(options) {
|
||||
|
||||
inherits(Map, PluggableMap);
|
||||
|
||||
Map.prototype.createRenderer = function() {
|
||||
return new CanvasMapRenderer(this);
|
||||
};
|
||||
|
||||
export default Map;
|
||||
|
||||
@@ -24,8 +24,6 @@ import {createEmpty, clone, createOrUpdateEmpty, equals, getForViewAndSize, isEm
|
||||
import {TRUE} from './functions.js';
|
||||
import {DEVICE_PIXEL_RATIO, TOUCH} from './has.js';
|
||||
import LayerGroup from './layer/Group.js';
|
||||
import {getMapRendererPlugins} from './plugins.js';
|
||||
import RendererType from './renderer/Type.js';
|
||||
import {hasArea} from './size.js';
|
||||
import {DROP} from './structs/PriorityQueue.js';
|
||||
import {create as createTransform, apply as applyTransform} from './transform.js';
|
||||
@@ -80,7 +78,6 @@ import {create as createTransform, apply as applyTransform} from './transform.js
|
||||
* @property {module:ol/Collection~Collection.<module:ol/interaction/Interaction~Interaction>} [interactions]
|
||||
* @property {Element|Document} keyboardEventTarget
|
||||
* @property {module:ol/Collection~Collection.<module:ol/Overlay~Overlay>} overlays
|
||||
* @property {module:ol/plugins~MapRendererPlugin} mapRendererPlugin
|
||||
* @property {Object.<string, *>} values
|
||||
*/
|
||||
|
||||
@@ -123,12 +120,6 @@ import {create as createTransform, apply as applyTransform} from './transform.js
|
||||
* Increasing this value can make it easier to click on the map.
|
||||
* @property {module:ol/Collection~Collection.<module:ol/Overlay~Overlay>|Array.<module:ol/Overlay~Overlay>} [overlays]
|
||||
* Overlays initially added to the map. By default, no overlays are added.
|
||||
* @property {module:ol/renderer/Type|Array.<module:ol/renderer/Type>} [renderer]
|
||||
* Renderer. By default, Canvas and WebGL renderers are tested for support in
|
||||
* that order, and the first supported used. Specify a
|
||||
* {@link module:ol/renderer/Type} here to use a specific renderer. Note that
|
||||
* the Canvas renderer fully supports vector data, but WebGL can only render
|
||||
* Point geometries reliably.
|
||||
* @property {Element|string} [target] The container for the map, either the
|
||||
* element itself or the `id` of the element. If not specified at construction
|
||||
* time, {@link module:ol/Map~Map#setTarget} must be called for the map to be
|
||||
@@ -348,7 +339,7 @@ const PluggableMap = function(options) {
|
||||
* @type {module:ol/renderer/Map~Map}
|
||||
* @private
|
||||
*/
|
||||
this.renderer_ = optionsInternal.mapRendererPlugin['create'](this.viewport_, this);
|
||||
this.renderer_ = this.createRenderer(this.viewport_, this);
|
||||
|
||||
/**
|
||||
* @type {function(Event)|undefined}
|
||||
@@ -475,6 +466,11 @@ const PluggableMap = function(options) {
|
||||
inherits(PluggableMap, BaseObject);
|
||||
|
||||
|
||||
PluggableMap.prototype.createRenderer = function() {
|
||||
throw new Error('Use a map type that has a createRenderer method');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Add the given control to the map.
|
||||
* @param {module:ol/control/Control~Control} control Control.
|
||||
@@ -1400,16 +1396,6 @@ PluggableMap.prototype.unskipFeature = function(feature) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @type {Array.<module:ol/renderer/Type>}
|
||||
* @const
|
||||
*/
|
||||
const DEFAULT_RENDERER_TYPES = [
|
||||
RendererType.CANVAS,
|
||||
RendererType.WEBGL
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @param {MapOptions} options Map options.
|
||||
* @return {module:ol/PluggableMap~MapOptionsInternal} Internal map options.
|
||||
@@ -1440,47 +1426,6 @@ function createOptionsInternal(options) {
|
||||
values[MapProperty.VIEW] = options.view !== undefined ?
|
||||
options.view : new View();
|
||||
|
||||
/**
|
||||
* @type {Array.<module:ol/renderer/Type>}
|
||||
*/
|
||||
let rendererTypes;
|
||||
|
||||
if (options.renderer !== undefined) {
|
||||
if (Array.isArray(options.renderer)) {
|
||||
rendererTypes = options.renderer;
|
||||
} else if (typeof options.renderer === 'string') {
|
||||
rendererTypes = [options.renderer];
|
||||
} else {
|
||||
assert(false, 46); // Incorrect format for `renderer` option
|
||||
}
|
||||
if (rendererTypes.indexOf(/** @type {module:ol/renderer/Type} */ ('dom')) >= 0) {
|
||||
rendererTypes = rendererTypes.concat(DEFAULT_RENDERER_TYPES);
|
||||
}
|
||||
} else {
|
||||
rendererTypes = DEFAULT_RENDERER_TYPES;
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {module:ol/plugins~MapRendererPlugin}
|
||||
*/
|
||||
let mapRendererPlugin;
|
||||
|
||||
const mapRendererPlugins = getMapRendererPlugins();
|
||||
outer: for (let i = 0, ii = rendererTypes.length; i < ii; ++i) {
|
||||
const rendererType = rendererTypes[i];
|
||||
for (let j = 0, jj = mapRendererPlugins.length; j < jj; ++j) {
|
||||
const candidate = mapRendererPlugins[j];
|
||||
if (candidate['handles'](rendererType)) {
|
||||
mapRendererPlugin = candidate;
|
||||
break outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!mapRendererPlugin) {
|
||||
throw new Error('Unable to create a map renderer for types: ' + rendererTypes.join(', '));
|
||||
}
|
||||
|
||||
let controls;
|
||||
if (options.controls !== undefined) {
|
||||
if (Array.isArray(options.controls)) {
|
||||
@@ -1521,7 +1466,6 @@ function createOptionsInternal(options) {
|
||||
interactions: interactions,
|
||||
keyboardEventTarget: keyboardEventTarget,
|
||||
overlays: overlays,
|
||||
mapRendererPlugin: mapRendererPlugin,
|
||||
values: values
|
||||
};
|
||||
|
||||
|
||||
@@ -3,11 +3,9 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* A plugin type used when registering a plugin. The supported plugin types are
|
||||
* 'MAP_RENDERER', and 'LAYER_RENDERER'.
|
||||
* A plugin type used when registering a plugin.
|
||||
* @enum {string}
|
||||
*/
|
||||
export default {
|
||||
MAP_RENDERER: 'MAP_RENDERER',
|
||||
LAYER_RENDERER: 'LAYER_RENDERER'
|
||||
};
|
||||
|
||||
@@ -7,15 +7,13 @@ import PluginType from './PluginType.js';
|
||||
import {defaults as defaultControls} from './control.js';
|
||||
import {defaults as defaultInteractions} from './interaction.js';
|
||||
import {assign} from './obj.js';
|
||||
import {register, registerMultiple} from './plugins.js';
|
||||
import {registerMultiple} from './plugins.js';
|
||||
import WebGLImageLayerRenderer from './renderer/webgl/ImageLayer.js';
|
||||
import WebGLMapRenderer from './renderer/webgl/Map.js';
|
||||
import WebGLTileLayerRenderer from './renderer/webgl/TileLayer.js';
|
||||
import WebGLVectorLayerRenderer from './renderer/webgl/VectorLayer.js';
|
||||
|
||||
|
||||
// TODO: move these to new ol-webgl package
|
||||
register(PluginType.MAP_RENDERER, WebGLMapRenderer);
|
||||
registerMultiple(PluginType.LAYER_RENDERER, [
|
||||
WebGLImageLayerRenderer,
|
||||
WebGLTileLayerRenderer,
|
||||
@@ -79,7 +77,6 @@ registerMultiple(PluginType.LAYER_RENDERER, [
|
||||
*/
|
||||
const WebGLMap = function(options) {
|
||||
options = assign({}, options);
|
||||
delete options.renderer;
|
||||
if (!options.controls) {
|
||||
options.controls = defaultControls();
|
||||
}
|
||||
@@ -92,4 +89,9 @@ const WebGLMap = function(options) {
|
||||
|
||||
inherits(WebGLMap, PluggableMap);
|
||||
|
||||
|
||||
WebGLMap.prototype.createRenderer = function() {
|
||||
return new WebGLMapRenderer(this);
|
||||
};
|
||||
|
||||
export default WebGLMap;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
import {inherits} from '../index.js';
|
||||
import Collection from '../Collection.js';
|
||||
import PluggableMap from '../PluggableMap.js';
|
||||
import Map from '../Map.js';
|
||||
import MapEventType from '../MapEventType.js';
|
||||
import MapProperty from '../MapProperty.js';
|
||||
import {getChangeEventType} from '../Object.js';
|
||||
@@ -136,10 +136,10 @@ const OverviewMap = function(opt_options) {
|
||||
this.ovmapDiv_.className = 'ol-overviewmap-map';
|
||||
|
||||
/**
|
||||
* @type {module:ol/PluggableMap~PluggableMap}
|
||||
* @type {module:ol/Map~Map}
|
||||
* @private
|
||||
*/
|
||||
this.ovmap_ = new PluggableMap({
|
||||
this.ovmap_ = new Map({
|
||||
controls: new Collection(),
|
||||
interactions: new Collection(),
|
||||
view: options.view
|
||||
|
||||
@@ -22,23 +22,6 @@ import PluginType from './PluginType.js';
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* The registry of map renderer plugins.
|
||||
* @type {Array<module:ol/plugins~MapRendererPlugin>}
|
||||
* @private
|
||||
*/
|
||||
const mapRendererPlugins = [];
|
||||
|
||||
|
||||
/**
|
||||
* Get all registered map renderer plugins.
|
||||
* @return {Array<module:ol/plugins~MapRendererPlugin>} The registered map renderer plugins.
|
||||
*/
|
||||
export function getMapRendererPlugins() {
|
||||
return mapRendererPlugins;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The registry of layer renderer plugins.
|
||||
* @type {Array<olx.LayerRendererPlugin>}
|
||||
@@ -64,11 +47,6 @@ export function getLayerRendererPlugins() {
|
||||
export function register(type, plugin) {
|
||||
let plugins;
|
||||
switch (type) {
|
||||
case PluginType.MAP_RENDERER: {
|
||||
plugins = mapRendererPlugins;
|
||||
plugins.push(/** @type {module:ol/plugins~MapRendererPlugin} */ (plugin));
|
||||
break;
|
||||
}
|
||||
case PluginType.LAYER_RENDERER: {
|
||||
plugins = layerRendererPlugins;
|
||||
plugins.push(/** @type {olx.LayerRendererPlugin} */ (plugin));
|
||||
|
||||
@@ -16,12 +16,10 @@ import {compose as composeTransform, invert as invertTransform, setFromArray as
|
||||
* @constructor
|
||||
* @abstract
|
||||
* @extends {module:ol/Disposable~Disposable}
|
||||
* @param {Element} container Container.
|
||||
* @param {module:ol/PluggableMap~PluggableMap} map Map.
|
||||
* @struct
|
||||
*/
|
||||
const MapRenderer = function(container, map) {
|
||||
|
||||
const MapRenderer = function(map) {
|
||||
Disposable.call(this);
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
/**
|
||||
* @module ol/renderer/canvas/Map
|
||||
*/
|
||||
// FIXME offset panning
|
||||
|
||||
import {create as createTransform, apply as applyTransform, compose as composeTransform} from '../../transform.js';
|
||||
import {inherits} from '../../index.js';
|
||||
import {stableSort} from '../../array.js';
|
||||
@@ -20,13 +18,13 @@ import SourceState from '../../source/State.js';
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.renderer.Map}
|
||||
* @param {Element} container Container.
|
||||
* @param {module:ol/PluggableMap~PluggableMap} map Map.
|
||||
* @api
|
||||
*/
|
||||
const CanvasMapRenderer = function(container, map) {
|
||||
const CanvasMapRenderer = function(map) {
|
||||
MapRenderer.call(this, map);
|
||||
|
||||
MapRenderer.call(this, container, map);
|
||||
const container = map.getViewport();
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -63,27 +61,6 @@ const CanvasMapRenderer = function(container, map) {
|
||||
inherits(CanvasMapRenderer, MapRenderer);
|
||||
|
||||
|
||||
/**
|
||||
* Determine if this renderer handles the provided layer.
|
||||
* @param {ol.renderer.Type} type The renderer type.
|
||||
* @return {boolean} The renderer can render the layer.
|
||||
*/
|
||||
CanvasMapRenderer['handles'] = function(type) {
|
||||
return type === RendererType.CANVAS;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create the map renderer.
|
||||
* @param {Element} container Container.
|
||||
* @param {module:ol/PluggableMap~PluggableMap} map Map.
|
||||
* @return {ol.renderer.canvas.Map} The map renderer.
|
||||
*/
|
||||
CanvasMapRenderer['create'] = function(container, map) {
|
||||
return new CanvasMapRenderer(container, map);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.render.EventType} type Event type.
|
||||
* @param {module:ol/PluggableMap~FrameState} frameState Frame state.
|
||||
|
||||
@@ -7,7 +7,6 @@ import {stableSort} from '../../array.js';
|
||||
import {CLASS_UNSELECTABLE} from '../../css.js';
|
||||
import {createCanvasContext2D} from '../../dom.js';
|
||||
import {listen} from '../../events.js';
|
||||
import {WEBGL} from '../../has.js';
|
||||
import {visibleAtResolution} from '../../layer/Layer.js';
|
||||
import RenderEvent from '../../render/Event.js';
|
||||
import RenderEventType from '../../render/EventType.js';
|
||||
@@ -43,12 +42,13 @@ const WEBGL_TEXTURE_CACHE_HIGH_WATER_MARK = 1024;
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.renderer.Map}
|
||||
* @param {Element} container Container.
|
||||
* @param {module:ol/PluggableMap~PluggableMap} map Map.
|
||||
* @api
|
||||
*/
|
||||
const WebGLMapRenderer = function(container, map) {
|
||||
MapRenderer.call(this, container, map);
|
||||
const WebGLMapRenderer = function(map) {
|
||||
MapRenderer.call(this, map);
|
||||
|
||||
const container = map.getViewport();
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -182,28 +182,7 @@ inherits(WebGLMapRenderer, MapRenderer);
|
||||
|
||||
|
||||
/**
|
||||
* Determine if this renderer handles the provided layer.
|
||||
* @param {ol.renderer.Type} type The renderer type.
|
||||
* @return {boolean} The renderer can render the layer.
|
||||
*/
|
||||
WebGLMapRenderer['handles'] = function(type) {
|
||||
return WEBGL && type === RendererType.WEBGL;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create the map renderer.
|
||||
* @param {Element} container Container.
|
||||
* @param {module:ol/PluggableMap~PluggableMap} map Map.
|
||||
* @return {ol.renderer.webgl.Map} The map renderer.
|
||||
*/
|
||||
WebGLMapRenderer['create'] = function(container, map) {
|
||||
return new WebGLMapRenderer(container, map);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {module:ol/Tile~Tile} tile Tile.
|
||||
* @param {ol.Tile} tile Tile.
|
||||
* @param {module:ol/size~Size} tileSize Tile size.
|
||||
* @param {number} tileGutter Tile gutter.
|
||||
* @param {number} magFilter Mag filter.
|
||||
@@ -612,4 +591,5 @@ WebGLMapRenderer.prototype.forEachLayerAtPixel = function(pixel, frameState, cal
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
export default WebGLMapRenderer;
|
||||
|
||||
@@ -19,7 +19,7 @@ describe('ol.renderer.canvas.Map', function() {
|
||||
const map = new Map({
|
||||
target: document.createElement('div')
|
||||
});
|
||||
const renderer = new CanvasMapRenderer(map.viewport_, map);
|
||||
const renderer = new CanvasMapRenderer(map);
|
||||
expect(renderer).to.be.a(CanvasMapRenderer);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user