From 593632daeae4b834fbeac7d76e8564ac6ca09205 Mon Sep 17 00:00:00 2001 From: Olivier Guyot Date: Wed, 14 Nov 2018 19:34:53 +0100 Subject: [PATCH] Fix the OverviewMap control & example Layers must now always be specified for the control. Base example was amended to reflect that. The breaking change was added in the update notes. --- changelog/upgrade-notes.md | 2 ++ examples/overviewmap.html | 3 ++- examples/overviewmap.js | 13 +++++++++++-- src/ol/control/OverviewMap.js | 10 ++-------- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/changelog/upgrade-notes.md b/changelog/upgrade-notes.md index c9d9ab0710..7b2c9f8dfb 100644 --- a/changelog/upgrade-notes.md +++ b/changelog/upgrade-notes.md @@ -2,6 +2,8 @@ ### Next version +Breaking change: The `OverviewMap` control now cannot be instantiated without a list of layers. + ### v5.3.0 #### The `getUid` function returns string diff --git a/examples/overviewmap.html b/examples/overviewmap.html index e499fde4ed..fbb5a0ee7d 100644 --- a/examples/overviewmap.html +++ b/examples/overviewmap.html @@ -3,7 +3,8 @@ layout: example.html title: Overview Map Control shortdesc: Example of OverviewMap control. docs: > - This example demonstrates the use of the OverviewMap control. + This example demonstrates the use of the OverviewMap control. Both the main map and the overview map are configured with layers using the same source. + Please note that explicitly configuring layers for the overview map is mandatory. tags: "overview, overviewmap" ---
diff --git a/examples/overviewmap.js b/examples/overviewmap.js index 5aad00acaf..a740254a40 100644 --- a/examples/overviewmap.js +++ b/examples/overviewmap.js @@ -4,13 +4,22 @@ import {defaults as defaultControls, OverviewMap} from '../src/ol/control.js'; import TileLayer from '../src/ol/layer/Tile.js'; import OSM from '../src/ol/source/OSM.js'; +const source = new OSM(); +const overviewMapControl = new OverviewMap({ + layers: [ + new TileLayer({ + source: source + }) + ] +}); + const map = new Map({ controls: defaultControls().extend([ - new OverviewMap() + overviewMapControl ]), layers: [ new TileLayer({ - source: new OSM() + source: source }) ], target: 'map', diff --git a/src/ol/control/OverviewMap.js b/src/ol/control/OverviewMap.js index 25e8bdd434..6c3afc1d39 100644 --- a/src/ol/control/OverviewMap.js +++ b/src/ol/control/OverviewMap.js @@ -44,9 +44,8 @@ const MIN_RATIO = 0.1; * @property {boolean} [collapsible=true] Whether the control can be collapsed or not. * @property {string|HTMLElement} [label='ยป'] Text label to use for the collapsed * overviewmap button. Instead of text, also an element (e.g. a `span` element) can be used. - * @property {Array|import("../Collection.js").default} [layers] - * Layers for the overview map. If not set, then all main map layers are used - * instead. + * @property {Array|import("../Collection.js").default} layers + * Layers for the overview map (mandatory). * @property {function(import("../MapEvent.js").default)} [render] Function called when the control * should be re-rendered. This is called in a `requestAnimationFrame` callback. * @property {HTMLElement|string} [target] Specify a target if you want the control @@ -251,11 +250,6 @@ class OverviewMap extends Control { map, ObjectEventType.PROPERTYCHANGE, this.handleMapPropertyChange_, this)); - // TODO: to really support map switching, this would need to be reworked - if (this.ovmap_.getLayers().getLength() === 0) { - this.ovmap_.setLayerGroup(map.getLayerGroup()); - } - const view = map.getView(); if (view) { this.bindView_(view);