Break the circular dependency by extending a pluggable map
This commit is contained in:
@@ -2,7 +2,7 @@ import Map from '../src/ol/Map.js';
|
|||||||
import View from '../src/ol/View.js';
|
import View from '../src/ol/View.js';
|
||||||
import TileLayer from '../src/ol/layer/Tile.js';
|
import TileLayer from '../src/ol/layer/Tile.js';
|
||||||
import OSM from '../src/ol/source/OSM.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';
|
import ZoomSlider from '../src/ol/control/ZoomSlider';
|
||||||
|
|
||||||
const view = new View({
|
const view = new View({
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
* @module ol/Map
|
* @module ol/Map
|
||||||
*/
|
*/
|
||||||
import PluggableMap from './PluggableMap.js';
|
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 {defaults as defaultInteractions} from './interaction.js';
|
||||||
import {assign} from './obj.js';
|
import {assign} from './obj.js';
|
||||||
import CompositeMapRenderer from './renderer/Composite.js';
|
import CompositeMapRenderer from './renderer/Composite.js';
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
/**
|
/**
|
||||||
* @module ol/control
|
* @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 Attribution} from './control/Attribution.js';
|
||||||
export {default as Control} from './control/Control.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 Zoom} from './control/Zoom.js';
|
||||||
export {default as ZoomSlider} from './control/ZoomSlider.js';
|
export {default as ZoomSlider} from './control/ZoomSlider.js';
|
||||||
export {default as ZoomToExtent} from './control/ZoomToExtent.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<import("./control/Control.js").default>}
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
/**
|
/**
|
||||||
* @module ol/control/OverviewMap
|
* @module ol/control/OverviewMap
|
||||||
*/
|
*/
|
||||||
import Collection from '../Collection.js';
|
import PluggableMap from '../PluggableMap.js';
|
||||||
import Map from '../Map.js';
|
import CompositeMapRenderer from '../renderer/Composite.js';
|
||||||
import MapEventType from '../MapEventType.js';
|
import MapEventType from '../MapEventType.js';
|
||||||
import MapProperty from '../MapProperty.js';
|
import MapProperty from '../MapProperty.js';
|
||||||
import {getChangeEventType} from '../Object.js';
|
import {getChangeEventType} from '../Object.js';
|
||||||
@@ -35,6 +35,13 @@ const MAX_RATIO = 0.75;
|
|||||||
const MIN_RATIO = 0.1;
|
const MIN_RATIO = 0.1;
|
||||||
|
|
||||||
|
|
||||||
|
class ControlledMap extends PluggableMap {
|
||||||
|
createRenderer() {
|
||||||
|
return new CompositeMapRenderer(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} Options
|
* @typedef {Object} Options
|
||||||
* @property {string} [className='ol-overviewmap'] CSS class name.
|
* @property {string} [className='ol-overviewmap'] CSS class name.
|
||||||
@@ -143,12 +150,10 @@ class OverviewMap extends Control {
|
|||||||
this.ovmapDiv_.className = 'ol-overviewmap-map';
|
this.ovmapDiv_.className = 'ol-overviewmap-map';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {import("../Map.js").default}
|
* @type {ControlledMap}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.ovmap_ = new Map({
|
this.ovmap_ = new ControlledMap({
|
||||||
controls: new Collection(),
|
|
||||||
interactions: new Collection(),
|
|
||||||
view: options.view
|
view: options.view
|
||||||
});
|
});
|
||||||
const ovmap = this.ovmap_;
|
const ovmap = this.ovmap_;
|
||||||
|
|||||||
@@ -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<import("./Control.js").default>}
|
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user