-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## JIRA Ticket [BSS-289](https://jira.csiro.au/browse/BSS-289) ## Description Added button to map component to move the map back to the initial location. ## Proposed Changes - Created centre icon HTML element - Created centre control button HTML element - Added centre control to map component - Added styling for map centre button in global App.css file ## How to Test 1. Activate "Campus Survey Demo" if it is not already activated 2. Open the survey "Campus Survey Demo" 3. Click the "+ Survey Area" button to add a new survey area 4. Click the "DRAW BOUNDING BOX AROUND SURVEY AREA" 5. Move the map 6. Test the centre button on the bottom left of the map screen ## Additional Information HTML elements were used instead of React components as these are what OpenLayers expects for map components. See [OpenLayers v10.0.0 API - Class: Control](https://openlayers.org/en/latest/apidoc/module-ol_control_Control-Control.html) ## Checklist - [x] I have confirmed all commits have been signed. - [x] I have added JSDoc style comments to any new functions or classes. - [x] Relevant documentation such as READMEs, guides, and class comments are updated.
- Loading branch information
Showing
6 changed files
with
104 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import {Control} from 'ol/control'; | ||
import {Coordinate} from 'ol/coordinate'; | ||
import {View} from 'ol'; | ||
import {CreateDomIcon} from './dom-icon'; | ||
import src from '../../../target.svg'; | ||
|
||
/** | ||
* Creates a custom control button that centers the map view to a specified coordinate. | ||
* | ||
* @param {View} view - The map view instance to be controlled. | ||
* @param {Coordinate} center - The coordinate to which the map view should be centered. | ||
* @returns {Control} - The custom control instance. | ||
*/ | ||
export const createCenterControl = ( | ||
view: View, | ||
center: Coordinate | ||
): Control => { | ||
const button = document.createElement('button'); | ||
button.className = 'ol-center-button'; | ||
|
||
button.appendChild( | ||
CreateDomIcon({ | ||
src, | ||
width: 24, | ||
height: 24, | ||
alt: 'Center map', | ||
}) | ||
); | ||
|
||
const handleClick = () => { | ||
view.setCenter(center); | ||
}; | ||
|
||
button.addEventListener('click', handleClick); | ||
|
||
const element = document.createElement('div'); | ||
element.className = 'ol-center-box'; | ||
element.appendChild(button); | ||
|
||
return new Control({ | ||
element: element, | ||
}); | ||
}; |
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,32 @@ | ||
interface CenterControlIconProps { | ||
src: string; | ||
width: number; | ||
height: number; | ||
alt: string; | ||
} | ||
|
||
/** | ||
* Creates a DOM image element with the specified properties. | ||
* | ||
* @param {CenterControlIconProps} props - The properties for the image element. | ||
* @param {string} props.src - The source URL of the image. | ||
* @param {number} props.width - The width of the image in pixels. | ||
* @param {number} props.height - The height of the image in pixels. | ||
* @param {string} props.alt - The alternative text for the image. | ||
* @returns {HTMLImageElement} - The created image element. | ||
*/ | ||
export const CreateDomIcon = ({ | ||
src, | ||
width, | ||
height, | ||
alt, | ||
}: CenterControlIconProps) => { | ||
const img = document.createElement('img'); | ||
|
||
img.width = width; | ||
img.height = height; | ||
img.src = src; | ||
img.alt = alt; | ||
|
||
return img; | ||
}; |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.