From d9a841e603406b10f09ff86f175dec0212a94d0c Mon Sep 17 00:00:00 2001 From: Sandro Mani Date: Mon, 22 Apr 2024 15:13:34 +0200 Subject: [PATCH] Set custom overviewmap view in componentDidMount --- plugins/map/OverviewSupport.jsx | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/plugins/map/OverviewSupport.jsx b/plugins/map/OverviewSupport.jsx index ced00fec9..0afc4e7f8 100644 --- a/plugins/map/OverviewSupport.jsx +++ b/plugins/map/OverviewSupport.jsx @@ -48,22 +48,31 @@ class OverviewMap extends React.Component { ...props.options }; delete opt.layer; - const overviewView = new ol.View({ - projection: props.map.getView().getProjection(), - ...(opt.viewOptions || {}) - }); - opt.view = overviewView; delete opt.viewOptions; this.overview = new ol.control.OverviewMap(opt); this.overview.getOverviewMap().set('id', 'overview'); } + componentDidUpdate(prevProps, prevState) { + if (this.props.projection !== prevProps.projection) { + const overviewView = new ol.View({ + projection: this.props.projection, + ...(this.props.options.viewOptions || {}) + }); + this.overview.getOverviewMap().setView(overviewView); + } + } componentDidMount() { this.overviewContainer = document.createElement("div"); this.overviewContainer.id = this.props.map.get('id') + "-overview"; document.getElementById("PluginsContainer").appendChild(this.overviewContainer); this.overview.setTarget(this.props.map.get('id') + "-overview"); this.props.map.addControl(this.overview); + const overviewView = new ol.View({ + projection: this.props.projection, + ...(this.props.options.viewOptions || {}) + }); + this.overview.getOverviewMap().setView(overviewView); } componentWillUnmount = () => { document.getElementById("PluginsContainer").removeChild(this.overviewContainer);