mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
Normalize longitudes of bounds so it falls within the acceptable [-180,180] range (#18674)
This commit is contained in:
parent
e1a2fcbd96
commit
bf71836c51
3 changed files with 53 additions and 49 deletions
|
@ -23,7 +23,7 @@ export function CoordinateMapsVisualizationProvider(Notifier, Private) {
|
|||
|
||||
await super._makeKibanaMap();
|
||||
|
||||
this.vis.sessionState.mapBounds = this._kibanaMap.getUntrimmedBounds();
|
||||
this.vis.sessionState.mapBounds = this._kibanaMap.getBounds();
|
||||
|
||||
let previousPrecision = this._kibanaMap.getGeohashPrecision();
|
||||
let precisionChange = false;
|
||||
|
|
|
@ -73,7 +73,7 @@ describe('kibana_map tests', function () {
|
|||
});
|
||||
|
||||
|
||||
describe('getUntrimmedBounds', function () {
|
||||
describe('getBounds', function () {
|
||||
|
||||
afterEach(function () {
|
||||
kibanaMap.destroy();
|
||||
|
@ -92,7 +92,7 @@ describe('kibana_map tests', function () {
|
|||
});
|
||||
|
||||
it('should get untrimmed map bounds', function () {
|
||||
const bounds = kibanaMap.getUntrimmedBounds();
|
||||
const bounds = kibanaMap.getBounds();
|
||||
expect(bounds.bottom_right.lon.toFixed(2)).to.equal('281.25');
|
||||
expect(bounds.top_left.lon.toFixed(2)).to.equal('-281.25');
|
||||
});
|
||||
|
@ -112,7 +112,7 @@ describe('kibana_map tests', function () {
|
|||
});
|
||||
|
||||
it('should calculate map dimensions based on enforcement of single pixel min-width CSS-rule', function () {
|
||||
const bounds = kibanaMap.getUntrimmedBounds();
|
||||
const bounds = kibanaMap.getBounds();
|
||||
expect(bounds).to.have.property('bottom_right');
|
||||
expect(round(bounds.bottom_right.lon, 2)).to.equal(0.27);
|
||||
expect(round(bounds.bottom_right.lat, 2)).to.equal(0);
|
||||
|
@ -142,7 +142,7 @@ describe('kibana_map tests', function () {
|
|||
});
|
||||
|
||||
it('should calculate map dimensions based on enforcement of single pixel min-width CSS-rule', function () {
|
||||
const bounds = kibanaMap.getUntrimmedBounds();
|
||||
const bounds = kibanaMap.getBounds();
|
||||
expect(bounds).to.have.property('bottom_right');
|
||||
expect(Math.round(bounds.bottom_right.lon)).to.equal(0);
|
||||
expect(bounds.bottom_right.lat.toFixed(2)).to.equal('-0.18');
|
||||
|
@ -151,9 +151,49 @@ describe('kibana_map tests', function () {
|
|||
expect(bounds.top_left.lat.toFixed(2)).to.equal('0.18');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('wrapping', function () {
|
||||
beforeEach(async function () {
|
||||
setupDOM('1600px', '1024px');
|
||||
kibanaMap = new KibanaMap(domNode, {
|
||||
minZoom: 1,
|
||||
maxZoom: 10,
|
||||
center: [0, -800], //swing the map over two earth-rotations west
|
||||
zoom: 2
|
||||
});
|
||||
});
|
||||
|
||||
it('coordinates should be corrected to center the -180,180 range', function () {
|
||||
const bounds = kibanaMap.getBounds();
|
||||
expect(bounds.bottom_right.lon.toFixed(2)).to.equal('201.09');
|
||||
expect(bounds.top_left.lon.toFixed(2)).to.equal('-361.41');
|
||||
});
|
||||
});
|
||||
|
||||
describe('wrapping - zoomed in', function () {
|
||||
beforeEach(async function () {
|
||||
setupDOM('1600px', '1024px');
|
||||
kibanaMap = new KibanaMap(domNode, {
|
||||
minZoom: 1,
|
||||
maxZoom: 10,
|
||||
center: [0, -800], //swing the map over two earth-rotations west
|
||||
zoom: 8
|
||||
});
|
||||
});
|
||||
|
||||
it('coordinates should be corrected to fall within the -180,180 range', function () {
|
||||
const bounds = kibanaMap.getBounds();
|
||||
expect(bounds.bottom_right.lon.toFixed(2)).to.equal('-75.61');
|
||||
expect(bounds.top_left.lon.toFixed(2)).to.equal('-84.40');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
describe('KibanaMap - attributions', function () {
|
||||
|
||||
beforeEach(async function () {
|
||||
|
|
|
@ -353,48 +353,11 @@ export class KibanaMap extends EventEmitter {
|
|||
return _.min([distanceX, distanceY]);
|
||||
}
|
||||
|
||||
getBounds() {
|
||||
|
||||
const bounds = this._leafletMap.getBounds();
|
||||
if (!bounds) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const southEast = bounds.getSouthEast();
|
||||
const northWest = bounds.getNorthWest();
|
||||
let southEastLng = southEast.lng;
|
||||
if (southEastLng > 180) {
|
||||
southEastLng -= 360;
|
||||
}
|
||||
let northWestLng = northWest.lng;
|
||||
if (northWestLng < -180) {
|
||||
northWestLng += 360;
|
||||
}
|
||||
|
||||
const southEastLat = southEast.lat;
|
||||
const northWestLat = northWest.lat;
|
||||
|
||||
//Bounds cannot be created unless they form a box with larger than 0 dimensions
|
||||
//Invalid areas are rejected by ES.
|
||||
if (southEastLat === northWestLat || southEastLng === northWestLng) {
|
||||
return;
|
||||
}
|
||||
|
||||
return {
|
||||
bottom_right: {
|
||||
lat: southEastLat,
|
||||
lon: southEastLng
|
||||
},
|
||||
top_left: {
|
||||
lat: northWestLat,
|
||||
lon: northWestLng
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
_getLeafletBounds(resizeOnFail) {
|
||||
|
||||
const bounds = this._leafletMap.getBounds();
|
||||
const boundsRaw = this._leafletMap.getBounds();
|
||||
const bounds = this._leafletMap.wrapLatLngBounds(boundsRaw);
|
||||
|
||||
if (!bounds) {
|
||||
return null;
|
||||
}
|
||||
|
@ -416,7 +379,8 @@ export class KibanaMap extends EventEmitter {
|
|||
}
|
||||
}
|
||||
|
||||
getUntrimmedBounds() {
|
||||
getBounds() {
|
||||
|
||||
const bounds = this._getLeafletBounds(true);
|
||||
if (!bounds) {
|
||||
return null;
|
||||
|
@ -664,14 +628,14 @@ export class KibanaMap extends EventEmitter {
|
|||
if (!centerFromUIState || centerFromMap.lon !== centerFromUIState[1] || centerFromMap.lat !== centerFromUIState[0]) {
|
||||
visualization.uiStateVal('mapCenter', [centerFromMap.lat, centerFromMap.lon]);
|
||||
}
|
||||
visualization.sessionState.mapBounds = this.getUntrimmedBounds();
|
||||
visualization.sessionState.mapBounds = this.getBounds();
|
||||
}
|
||||
|
||||
this._leafletMap.on('resize', () => {
|
||||
visualization.sessionState.mapBounds = this.getUntrimmedBounds();
|
||||
visualization.sessionState.mapBounds = this.getBounds();
|
||||
});
|
||||
this._leafletMap.on('load', () => {
|
||||
visualization.sessionState.mapBounds = this.getUntrimmedBounds();
|
||||
visualization.sessionState.mapBounds = this.getBounds();
|
||||
});
|
||||
this.on('dragend', persistMapStateInUiState);
|
||||
this.on('zoomend', persistMapStateInUiState);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue