forked from geosolutions-it/geonode-mapstore-client
-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e5984a
commit 75f40e5
Showing
9 changed files
with
111 additions
and
83 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
48 changes: 48 additions & 0 deletions
48
geonode_mapstore_client/client/js/components/ZoomTo/ZoomTo.jsx
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,48 @@ | ||
/* | ||
* Copyright 2022, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import { useRef, useEffect } from 'react'; | ||
import { reprojectBbox } from '@mapstore/framework/utils/CoordinatesUtils'; | ||
|
||
const ZoomTo = ({ | ||
map, | ||
extent | ||
}) => { | ||
const once = useRef(); | ||
useEffect(() => { | ||
if (map && extent && !once.current) { | ||
const [ | ||
aMinx, aMiny, aMaxx, aMaxy, | ||
bMinx, bMiny, bMaxx, bMaxy | ||
] = extent.split(','); | ||
const projection = map.getView().getProjection().getCode(); | ||
let bounds; | ||
const aBounds = reprojectBbox([aMinx, aMiny, aMaxx, aMaxy], 'EPSG:4326', projection); | ||
if (bMinx !== undefined && bMiny !== undefined && bMaxx !== undefined && bMaxy !== undefined) { | ||
const bBounds = reprojectBbox([bMinx, bMiny, bMaxx, bMaxy], 'EPSG:4326', projection); | ||
// if there is the second bbox we should shift the minimum x value to correctly center the view | ||
// the x of the [A] bounds needs to be shifted by the width of the [B] bounds | ||
const minx = aBounds[0] - (bBounds[2] - bBounds[0]); | ||
bounds = [minx, aBounds[1], aBounds[2], aBounds[3]]; | ||
} else { | ||
bounds = aBounds; | ||
} | ||
map.getView().fit(bounds, { | ||
size: map.getSize(), | ||
duration: 300, | ||
nearest: true | ||
}); | ||
// ensure to avoid other fit action by setting once to true | ||
once.current = true; | ||
} | ||
}, [extent]); | ||
|
||
return null; | ||
}; | ||
|
||
export default ZoomTo; |
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,3 @@ | ||
import ZoomTo from "./ZoomTo"; | ||
|
||
export default ZoomTo; |
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