feat(bounds): plugins bounds (MIN-228)
Bounds
Get Bounds
To get bounds of the current active map, plugins can use the getBounds
method defined in window.minerva.map.data
object available globally. It returns object with properties x1, y1, x2, y2
- x1, y1 - top left corner coordinates
- x2, y2 - right bottom corner coordinates
Example of returned object:
{
x1: 12853,
y1: 4201,
x2: 23327,
y2: 9575
}
Example of getBounds method usage:
window.minerva.map.data.getBounds();
Fit bounds
To zoom in the map in a way that rectangle defined by coordinates is visible, plugins can use the fitBounds
method defined in window.minerva.map
object available globally. This method takes one argument: object with properties x1, y1, x2, y2.
- x1, y1 - top left corner coordinates
- x2, y2 - right bottom corner coordinates
Example of fitBounds method usage:
window.minerva.map.fitBounds({
x1: 14057.166666666668,
y1: 6805.337365980873,
x2: 14057.166666666668,
y2: 6805.337365980873,
});
In addition to the bounds functionality for plugins, support for fitBounds
param in window.minerva.map.triggerSearch
has also been added. When param is true
, after searching by coordinates or query, the map is zoomed to the results.
Now everything should work correctly as described in plugins/search.md
In addition, the getOpenMapId
method has been added. After consulting with Piotr, we no longer provide modelId in fitBounds/getBounds
, but the plugin user must be able to check what map is currently open to know which map the coordinates belong to.
getOpenMapId
getOpenMapId
fitBounds and getBounds
fitboundsgetbounds
triggerSearch by query - fitBounds: true
triggerSearch-fitbounds
triggerSearch by query - fitBounds: false
triggersearch_fit_bounds_false_-2
triggerSearch by coordinates - fitBounds: true
triggerSearch_-_fitbounds2
triggerSearch by coordinates - fitBounds: false
triggerSearch_-_fitbounds_false
Closes MIN-228
Merge request reports
Activity
assigned to @mateusz-winiarczyk
14 15 searchQueries: [id.toString()], 15 16 isPerfectMatch: true 16 17 }), 17 ); 18 ) 19 .unwrap().then(() => { 20 if (hasFitBounds) { 21 searchFitBounds(fitBoundsZoom); 22 } 23 }).catch(() => { 24 // TODO to discuss manage state of failure 28 29 getMultiBioEntity({ 29 30 searchQueries: bioEntitiesIds, 30 31 isPerfectMatch: true }, 31 ), 32 ); 32 ) 33 ).unwrap().then(() => { 34 if (hasFitBounds) { 35 searchFitBounds(fitBoundsZoom); 36 } 37 }).catch(() => { 38 // TODO to discuss manage state of failure 42 43 }); 43 44 44 45 setMapInstance(currentMap => currentMap || map); 46 if (!MapManager.mapInstance) { 47 MapManager.setMapInstance(map); 48 } - Comment on lines 45 to +48
RFC: doubling the state
If it possible, there should not be two different sources of truth. It may generate unexpected issues in the future. Even if it's not possible, sync shouldn't be done here.
You can change how MapInstance context works to make sure that MapManager and context have the same source of truth or are in sync
@AdrianOrlow True, the
setMapInstance
andMapManager.setMapInstance
methods should always be updated together. Even because thesetMapInstance
method can be used in the future not only in one place like now, and you can forget to add MapManager.setMapInstance
and it will desync. Good catch, thanks!changed this line in version 2 of the diff
@AdrianOrlow Fixed, could check please if that is what you had in mind?
@mateusz-winiarczyk Now it's ok. Well done:)
23 getStateMock.mockImplementation( 24 () => 25 ({ 26 map: { 27 ...initialMapStateFixture, 28 data: { 29 ...initialMapStateFixture.data, 30 modelId: null, 31 }, 32 }, 33 // eslint-disable-next-line @typescript-eslint/no-explicit-any 34 }) as any, 35 ); 36 37 expect(() => getOpenMapId()).toThrowError( 38 'Unable to retrieve the ID of the active map: the modelId is not a number.', changed this line in version 3 of the diff
added 16 commits
-
e966ba1b...1bfc48af - 14 commits from branch
development
- a8b51b52 - refactor(mapinstance): fix doubling state and mapinstance provider and map manager have sync value
- a306d5c9 - Merge remote-tracking branch 'origin/development' into MIN-228-plugin-bounds
-
e966ba1b...1bfc48af - 14 commits from branch
added 1 commit
- 1e615a3f - refactor(pluginerrors): extract plugin errors to variables and add description in docs
mentioned in commit c8418366