-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix] Fixed issue when mapstate latitude or langitude are out of boun…
…ds (#2882) - fixed issue when mapstate latitude or langitude are out of bounds Signed-off-by: Ihor Dykhta <dikhta.igor@gmail.com>
- Loading branch information
1 parent
92c9e6a
commit 603fde8
Showing
7 changed files
with
247 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
// SPDX-License-Identifier: MIT | ||
// Copyright contributors to the kepler.gl project | ||
|
||
import WebMercatorViewport from 'viewport-mercator-project'; | ||
|
||
import {TRANSITION_DURATION} from '@kepler.gl/constants'; | ||
import { | ||
getMapLayersFromSplitMaps, | ||
onViewPortChange, | ||
getViewportFromMapState | ||
} from '@kepler.gl/utils'; | ||
|
||
export const INITIAL_MAP_STATE = { | ||
pitch: 0, | ||
bearing: 0, | ||
latitude: 40, | ||
longitude: -100, | ||
zoom: 9, | ||
dragRotate: false, | ||
width: 800, | ||
height: 800, | ||
minZoom: undefined, | ||
maxZoom: undefined, | ||
maxBounds: undefined, | ||
isSplit: false, | ||
isViewportSynced: true, | ||
isZoomLocked: false, | ||
splitMapViewports: [] | ||
}; | ||
|
||
describe('mapUtils', () => { | ||
describe('onViewPortChange', () => { | ||
let mockOnUpdateMap; | ||
let mockOnViewStateChange; | ||
|
||
beforeEach(() => { | ||
mockOnUpdateMap = jest.fn(); | ||
mockOnViewStateChange = jest.fn(); | ||
}); | ||
|
||
test('should use restViewState when width and height are 0', () => { | ||
const viewState = {...INITIAL_MAP_STATE, width: 0, height: 0}; | ||
onViewPortChange(viewState, mockOnUpdateMap, mockOnViewStateChange); | ||
|
||
/* eslint-disable no-unused-vars */ | ||
const {width, height, ...restViewState} = INITIAL_MAP_STATE; | ||
expect(mockOnUpdateMap).toHaveBeenCalledWith({...restViewState, transitionDuration: 0}, 0); | ||
}); | ||
|
||
test('should use viewState when width and height are greater than 0', () => { | ||
const viewState = INITIAL_MAP_STATE; | ||
onViewPortChange(viewState, mockOnUpdateMap, mockOnViewStateChange); | ||
|
||
expect(mockOnUpdateMap).toHaveBeenCalledWith({...viewState, transitionDuration: 0}, 0); | ||
}); | ||
|
||
test('should set transitionDuration based on primary flag', () => { | ||
const viewState = INITIAL_MAP_STATE; | ||
onViewPortChange(viewState, mockOnUpdateMap, mockOnViewStateChange, true); | ||
expect(mockOnUpdateMap).toHaveBeenCalledWith( | ||
{...viewState, transitionDuration: TRANSITION_DURATION}, | ||
0 | ||
); | ||
|
||
onViewPortChange(viewState, mockOnUpdateMap, mockOnViewStateChange, false); | ||
expect(mockOnUpdateMap).toHaveBeenCalledWith({...viewState, transitionDuration: 0}, 0); | ||
}); | ||
|
||
test('should call onViewStateChange if it is a function', () => { | ||
const viewState = {width: 100, height: 100}; | ||
onViewPortChange(viewState, mockOnUpdateMap, mockOnViewStateChange); | ||
expect(mockOnViewStateChange).toHaveBeenCalledWith({...viewState, transitionDuration: 0}); | ||
}); | ||
|
||
test('should call onUpdateMap with correct arguments', () => { | ||
const viewState = {width: 100, height: 100}; | ||
const mapIndex = 1; | ||
onViewPortChange(viewState, mockOnUpdateMap, mockOnViewStateChange, false, mapIndex); | ||
expect(mockOnUpdateMap).toHaveBeenCalledWith({...viewState, transitionDuration: 0}, mapIndex); | ||
}); | ||
}); | ||
describe('getMapLayersFromSplitMaps', () => { | ||
test('returns layers for valid index', () => { | ||
const splitMaps = [{layers: ['Layer1', 'Layer2']}, {layers: ['Layer3', 'Layer4']}]; | ||
const mapIndex = 1; | ||
|
||
expect(getMapLayersFromSplitMaps(splitMaps, mapIndex)).toEqual(['Layer3', 'Layer4']); | ||
}); | ||
|
||
test('returns undefined for invalid index', () => { | ||
const splitMaps = [{layers: ['Layer1', 'Layer2']}]; | ||
const mapIndex = 2; | ||
|
||
expect(getMapLayersFromSplitMaps(splitMaps, mapIndex)).toBeUndefined(); | ||
}); | ||
|
||
test('returns undefined for empty splitMaps array', () => { | ||
expect(getMapLayersFromSplitMaps([], 0)).toBeUndefined(); | ||
}); | ||
|
||
test('returns undefined if layers property does not exist', () => { | ||
const splitMaps = [{}, {layers: ['Layer3', 'Layer4']}]; | ||
const mapIndex = 0; | ||
|
||
expect(getMapLayersFromSplitMaps(splitMaps, mapIndex)).toBeUndefined(); | ||
}); | ||
}); | ||
|
||
describe('getViewportFromMapState', () => { | ||
test('returns WebMercatorViewport when globe property is undefined', () => { | ||
const mapState = {}; | ||
const result = getViewportFromMapState(mapState); | ||
|
||
expect(result).toBeInstanceOf(WebMercatorViewport); | ||
}); | ||
|
||
test('should not throw an exception if latitude is -90', () => { | ||
const mapState = { | ||
...INITIAL_MAP_STATE, | ||
latitude: -90 | ||
}; | ||
expect(() => getViewportFromMapState(mapState)).not.toThrow(); | ||
}); | ||
|
||
test('should not throw an exception if latitude is 90', () => { | ||
const mapState = { | ||
...INITIAL_MAP_STATE, | ||
latitude: 90 | ||
}; | ||
expect(() => getViewportFromMapState(mapState)).not.toThrow(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters