Skip to content

Commit

Permalink
Set custom overviewmap view in componentDidMount
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed Apr 22, 2024
1 parent 652b98b commit d9a841e
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions plugins/map/OverviewSupport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d9a841e

Please sign in to comment.