-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@dpc-sdp/ripple-ui-maps): ♻️ use custom map controls
- Loading branch information
1 parent
425340e
commit 150e9ac
Showing
10 changed files
with
188 additions
and
44 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
1 change: 1 addition & 0 deletions
1
packages/ripple-ui-core/src/components/icon/custom/Icon-map-zoom-out.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions
4
packages/ripple-ui-core/src/components/icon/custom/icon-enlarge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
packages/ripple-ui-core/src/components/icon/custom/icon-home.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
packages/ripple-ui-core/src/components/icon/custom/icon-map-zoom-in.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
12 changes: 0 additions & 12 deletions
12
packages/ripple-ui-maps/src/composables/useMapControlLabel.ts
This file was deleted.
Oops, something went wrong.
135 changes: 135 additions & 0 deletions
135
packages/ripple-ui-maps/src/composables/useMapControls.ts
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,135 @@ | ||
import { easeOut } from 'ol/easing' | ||
import { centerMap } from './../components/map/utils.ts' | ||
import { ref } from 'vue' | ||
export default (mapRef, center, initialZoom) => { | ||
const isFullScreenRef = ref(false) | ||
|
||
/** | ||
* @param {number} delta Zoom delta. | ||
* @private | ||
*/ | ||
function zoomByDelta(delta, duration = 250) { | ||
const view = mapRef.value.map.getView() | ||
if (!view) { | ||
// the map does not have a view, so we can't act | ||
// upon it | ||
return | ||
} | ||
const currentZoom = view.getZoom() | ||
if (currentZoom !== undefined) { | ||
const newZoom = view.getConstrainedZoom(currentZoom + delta) | ||
if (duration > 0) { | ||
if (view.getAnimating()) { | ||
view.cancelAnimations() | ||
} | ||
view.animate({ | ||
zoom: newZoom, | ||
duration: duration, | ||
easing: easeOut | ||
}) | ||
} else { | ||
view.setZoom(newZoom) | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @param {Document} doc The root document to check. | ||
* @return {boolean} Fullscreen is supported by the current platform. | ||
*/ | ||
function isFullScreenSupported(doc) { | ||
const body = doc.body | ||
return !!( | ||
body['webkitRequestFullscreen'] || | ||
(body.requestFullscreen && doc.fullscreenEnabled) | ||
) | ||
} | ||
|
||
/** | ||
* @param {Document} doc The root document to check. | ||
* @return {boolean} Element is currently in fullscreen. | ||
*/ | ||
function isFullScreen(doc) { | ||
return !!(doc['webkitIsFullScreen'] || doc.fullscreenElement) | ||
} | ||
|
||
/** | ||
* Request to fullscreen an element. | ||
* @param {HTMLElement} element Element to request fullscreen | ||
*/ | ||
function requestFullScreen(element) { | ||
if (element.requestFullscreen) { | ||
element.requestFullscreen() | ||
} else if (element['webkitRequestFullscreen']) { | ||
element['webkitRequestFullscreen']() | ||
} | ||
} | ||
|
||
/** | ||
* Request to fullscreen an element with keyboard input. | ||
* @param {HTMLElement} element Element to request fullscreen | ||
*/ | ||
function requestFullScreenWithKeys(element) { | ||
if (element['webkitRequestFullscreen']) { | ||
element['webkitRequestFullscreen']() | ||
} else { | ||
requestFullScreen(element) | ||
} | ||
} | ||
|
||
/** | ||
* Exit fullscreen. | ||
* @param {Document} doc The document to exit fullscren from | ||
*/ | ||
function exitFullScreen(doc) { | ||
if (doc.exitFullscreen) { | ||
doc.exitFullscreen() | ||
} else if (doc['webkitExitFullscreen']) { | ||
doc['webkitExitFullscreen']() | ||
} | ||
} | ||
|
||
function handleFullScreen(withKeys = false) { | ||
const map = mapRef.value.map | ||
if (!map) { | ||
return | ||
} | ||
const doc = map.getOwnerDocument() | ||
if (!isFullScreenSupported(doc)) { | ||
return | ||
} | ||
if (isFullScreen(doc)) { | ||
exitFullScreen(doc) | ||
isFullScreenRef.value = false | ||
} else { | ||
const element = map.getTargetElement() | ||
if (withKeys) { | ||
requestFullScreenWithKeys(element) | ||
} else { | ||
requestFullScreen(element) | ||
} | ||
isFullScreenRef.value = true | ||
} | ||
} | ||
|
||
function onHomeClick() { | ||
centerMap(mapRef.value.map, center.value, { y: 0, x: 0 }, initialZoom) | ||
} | ||
function onZoomInClick() { | ||
zoomByDelta(1) | ||
} | ||
function onZoomOutClick() { | ||
zoomByDelta(-1) | ||
} | ||
function onFullScreenClick() { | ||
handleFullScreen() | ||
} | ||
|
||
return { | ||
onHomeClick, | ||
onZoomInClick, | ||
onZoomOutClick, | ||
onFullScreenClick, | ||
isFullScreenRef | ||
} | ||
} |