Get default projection for overview map from main map.

Changes OverviewMap such that it will use whatever projection the
hosting map is using unless a view was specified explicitly.

Fixes #2998 #5188 #10670
This commit is contained in:
Augustus Kling
2020-02-18 00:43:52 +01:00
parent 3a92a8091a
commit da7f51c085
2 changed files with 54 additions and 6 deletions
+36 -3
View File
@@ -55,8 +55,8 @@ describe('ol.control.OverviewMap', function() {
rotateWithView: true
});
map.addControl(control);
const ovView = control.ovmap_.getView();
expect(ovView.getRotation()).to.be(0);
const ovInitialView = control.ovmap_.getView();
expect(ovInitialView.getRotation()).to.be(0);
const view = new View({
center: [0, 0],
@@ -64,6 +64,7 @@ describe('ol.control.OverviewMap', function() {
rotation: Math.PI / 2
});
map.setView(view);
const ovView = control.ovmap_.getView();
expect(ovView.getRotation()).to.be(Math.PI / 2);
view.setRotation(Math.PI / 4);
@@ -74,7 +75,6 @@ describe('ol.control.OverviewMap', function() {
const control = new OverviewMap({
rotateWithView: true
});
const ovView = control.ovmap_.getView();
const view = new View({
center: [0, 0],
@@ -83,6 +83,7 @@ describe('ol.control.OverviewMap', function() {
});
map.setView(view);
map.addControl(control);
const ovView = control.ovmap_.getView();
view.setRotation(Math.PI / 8);
expect(ovView.getRotation()).to.be(Math.PI / 8);
@@ -93,6 +94,38 @@ describe('ol.control.OverviewMap', function() {
expect(ovView.getRotation()).to.be(Math.PI / 8);
});
it('reflects projection change of main map', function() {
const control = new OverviewMap({
rotateWithView: true
});
map.addControl(control);
expect(control.ovmap_.getView().getProjection().getCode()).to.be('EPSG:3857');
map.setView(new View({
projection: 'EPSG:4326'
}));
expect(control.ovmap_.getView().getProjection().getCode()).to.be('EPSG:4326');
});
it('retains explicitly set view', function() {
const overviewMapView = new View();
const control = new OverviewMap({
rotateWithView: true,
view: overviewMapView
});
map.addControl(control);
expect(control.ovmap_.getView()).to.be(overviewMapView);
expect(control.ovmap_.getView().getProjection().getCode()).to.be('EPSG:3857');
map.setView(new View({
projection: 'EPSG:4326'
}));
expect(control.ovmap_.getView()).to.be(overviewMapView);
expect(control.ovmap_.getView().getProjection().getCode()).to.be('EPSG:3857');
});
it('set target to null', function() {
const control = new OverviewMap();