From c860f15f91fcd5d83942c22fe32091204d306273 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Fri, 17 May 2019 12:18:37 -0600 Subject: [PATCH] Break the circular dependency by extending a pluggable map --- examples/extent-constrained.js | 2 +- src/ol/Map.js | 2 +- src/ol/control.js | 61 ++++++++++++++++++++++++++++++- src/ol/control/OverviewMap.js | 17 +++++---- src/ol/control/util.js | 65 ---------------------------------- 5 files changed, 73 insertions(+), 74 deletions(-) delete mode 100644 src/ol/control/util.js diff --git a/examples/extent-constrained.js b/examples/extent-constrained.js index 8fc6e68c77..7e274290bc 100644 --- a/examples/extent-constrained.js +++ b/examples/extent-constrained.js @@ -2,7 +2,7 @@ import Map from '../src/ol/Map.js'; import View from '../src/ol/View.js'; import TileLayer from '../src/ol/layer/Tile.js'; import OSM from '../src/ol/source/OSM.js'; -import {defaults as defaultControls} from '../src/ol/control/util'; +import {defaults as defaultControls} from '../src/ol/control.js'; import ZoomSlider from '../src/ol/control/ZoomSlider'; const view = new View({ diff --git a/src/ol/Map.js b/src/ol/Map.js index bcd9f3a152..794ddcebd3 100644 --- a/src/ol/Map.js +++ b/src/ol/Map.js @@ -2,7 +2,7 @@ * @module ol/Map */ import PluggableMap from './PluggableMap.js'; -import {defaults as defaultControls} from './control/util.js'; +import {defaults as defaultControls} from './control.js'; import {defaults as defaultInteractions} from './interaction.js'; import {assign} from './obj.js'; import CompositeMapRenderer from './renderer/Composite.js'; diff --git a/src/ol/control.js b/src/ol/control.js index 14bb5669a2..7b10be95b8 100644 --- a/src/ol/control.js +++ b/src/ol/control.js @@ -1,6 +1,10 @@ /** * @module ol/control */ +import Collection from './Collection.js'; +import Attribution from './control/Attribution.js'; +import Rotate from './control/Rotate.js'; +import Zoom from './control/Zoom.js'; export {default as Attribution} from './control/Attribution.js'; export {default as Control} from './control/Control.js'; @@ -12,4 +16,59 @@ export {default as ScaleLine} from './control/ScaleLine.js'; export {default as Zoom} from './control/Zoom.js'; export {default as ZoomSlider} from './control/ZoomSlider.js'; export {default as ZoomToExtent} from './control/ZoomToExtent.js'; -export {defaults} from './control/util.js'; + +/** + * @typedef {Object} DefaultsOptions + * @property {boolean} [attribution=true] Include + * {@link module:ol/control/Attribution~Attribution}. + * @property {import("./control/Attribution.js").Options} [attributionOptions] + * Options for {@link module:ol/control/Attribution~Attribution}. + * @property {boolean} [rotate=true] Include + * {@link module:ol/control/Rotate~Rotate}. + * @property {import("./control/Rotate.js").Options} [rotateOptions] Options + * for {@link module:ol/control/Rotate~Rotate}. + * @property {boolean} [zoom] Include {@link module:ol/control/Zoom~Zoom}. + * @property {import("./control/Zoom.js").Options} [zoomOptions] Options for + * {@link module:ol/control/Zoom~Zoom}. + * @api + */ + + +/** + * Set of controls included in maps by default. Unless configured otherwise, + * this returns a collection containing an instance of each of the following + * controls: + * * {@link module:ol/control/Zoom~Zoom} + * * {@link module:ol/control/Rotate~Rotate} + * * {@link module:ol/control/Attribution~Attribution} + * + * @param {DefaultsOptions=} opt_options + * Defaults options. + * @return {Collection} + * Controls. + * @api + */ +export function defaults(opt_options) { + + const options = opt_options ? opt_options : {}; + + const controls = new Collection(); + + const zoomControl = options.zoom !== undefined ? options.zoom : true; + if (zoomControl) { + controls.push(new Zoom(options.zoomOptions)); + } + + const rotateControl = options.rotate !== undefined ? options.rotate : true; + if (rotateControl) { + controls.push(new Rotate(options.rotateOptions)); + } + + const attributionControl = options.attribution !== undefined ? + options.attribution : true; + if (attributionControl) { + controls.push(new Attribution(options.attributionOptions)); + } + + return controls; +} diff --git a/src/ol/control/OverviewMap.js b/src/ol/control/OverviewMap.js index 6c3afc1d39..9d935c0c76 100644 --- a/src/ol/control/OverviewMap.js +++ b/src/ol/control/OverviewMap.js @@ -1,8 +1,8 @@ /** * @module ol/control/OverviewMap */ -import Collection from '../Collection.js'; -import Map from '../Map.js'; +import PluggableMap from '../PluggableMap.js'; +import CompositeMapRenderer from '../renderer/Composite.js'; import MapEventType from '../MapEventType.js'; import MapProperty from '../MapProperty.js'; import {getChangeEventType} from '../Object.js'; @@ -35,6 +35,13 @@ const MAX_RATIO = 0.75; const MIN_RATIO = 0.1; +class ControlledMap extends PluggableMap { + createRenderer() { + return new CompositeMapRenderer(this); + } +} + + /** * @typedef {Object} Options * @property {string} [className='ol-overviewmap'] CSS class name. @@ -143,12 +150,10 @@ class OverviewMap extends Control { this.ovmapDiv_.className = 'ol-overviewmap-map'; /** - * @type {import("../Map.js").default} + * @type {ControlledMap} * @private */ - this.ovmap_ = new Map({ - controls: new Collection(), - interactions: new Collection(), + this.ovmap_ = new ControlledMap({ view: options.view }); const ovmap = this.ovmap_; diff --git a/src/ol/control/util.js b/src/ol/control/util.js deleted file mode 100644 index c8ea795c21..0000000000 --- a/src/ol/control/util.js +++ /dev/null @@ -1,65 +0,0 @@ -/** - * @module ol/control/util - */ -import Collection from '../Collection.js'; -import Attribution from './Attribution.js'; -import Rotate from './Rotate.js'; -import Zoom from './Zoom.js'; - - -/** - * @typedef {Object} DefaultsOptions - * @property {boolean} [attribution=true] Include - * {@link module:ol/control/Attribution~Attribution}. - * @property {import("./Attribution.js").Options} [attributionOptions] - * Options for {@link module:ol/control/Attribution~Attribution}. - * @property {boolean} [rotate=true] Include - * {@link module:ol/control/Rotate~Rotate}. - * @property {import("./Rotate.js").Options} [rotateOptions] Options - * for {@link module:ol/control/Rotate~Rotate}. - * @property {boolean} [zoom] Include {@link module:ol/control/Zoom~Zoom}. - * @property {import("./Zoom.js").Options} [zoomOptions] Options for - * {@link module:ol/control/Zoom~Zoom}. - * @api - */ - - -/** - * Set of controls included in maps by default. Unless configured otherwise, - * this returns a collection containing an instance of each of the following - * controls: - * * {@link module:ol/control/Zoom~Zoom} - * * {@link module:ol/control/Rotate~Rotate} - * * {@link module:ol/control/Attribution~Attribution} - * - * @param {DefaultsOptions=} opt_options - * Defaults options. - * @return {Collection} - * Controls. - * @function module:ol/control.defaults - * @api - */ -export function defaults(opt_options) { - - const options = opt_options ? opt_options : {}; - - const controls = new Collection(); - - const zoomControl = options.zoom !== undefined ? options.zoom : true; - if (zoomControl) { - controls.push(new Zoom(options.zoomOptions)); - } - - const rotateControl = options.rotate !== undefined ? options.rotate : true; - if (rotateControl) { - controls.push(new Rotate(options.rotateOptions)); - } - - const attributionControl = options.attribution !== undefined ? - options.attribution : true; - if (attributionControl) { - controls.push(new Attribution(options.attributionOptions)); - } - - return controls; -}