Skip to content

Commit

Permalink
Merge pull request #1164 from dpc-sdp/feature/map-design-change
Browse files Browse the repository at this point in the history
[R20-1805] Changed the design of the 'infobox' popup on small screens
  • Loading branch information
dylankelly authored May 21, 2024
2 parents a26b5e5 + e3a2893 commit 550c099
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/ripple-ui-maps/src/components/map/RplMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ const selectedPinStyle = (feature, style) => {
})
ic.load()
style.setImage(ic)
return style
}
const { isFullscreen } = useFullscreen()
Expand Down
60 changes: 52 additions & 8 deletions packages/ripple-ui-maps/src/components/map/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,48 @@ export const zoomToClusterExtent = (
})
}

/**
* Find the distance we need to move from the center of the map to account for the
* dead space taken up by the sidepanel/sidebars/popups etc. The purpose of this function
* is to calculate the offset needed to center the map on a specific point, inside the
* available space on the map.
*
* Note that in OpenLayers, the x-axis is positive to the right and the y-axis is positive
* downwards.
*/
const getCenterPointDelta = (
mapWidth: number,
mapHeight: number,
_deadSpace?: MapDeadSpace
): [number, number] => {
const defaultDeadSpace = {
top: 0,
bottom: 0,
left: 0,
right: 0
}

const deadSpace = {
...defaultDeadSpace,
...(_deadSpace || {})
}

const mapCenterX = mapWidth / 2
const mapCenterY = mapHeight / 2

const availableWidth = mapWidth - deadSpace.left - deadSpace.right
const availableHeight = mapHeight - deadSpace.top - deadSpace.bottom

const newCenterX = deadSpace.left + availableWidth / 2
const newCenterY = deadSpace.top + availableHeight / 2

// Get the difference between the current center and the new center
const deltaX = mapCenterX - newCenterX
const deltaY = newCenterY - mapCenterY

return [deltaX, deltaY]
}

export const centerMap = (
map,
position = [0, 0],
Expand All @@ -97,16 +139,18 @@ export const centerMap = (
// Figure out offset based on the amount of space taken up by the sidepanel/sidebar
const mapSize = map.getSize()
const mapWidth = mapSize ? mapSize[0] : 0
const leftDeadSpace = deadSpace?.left || 0
const remaingingSpaceStart = mapWidth / 2 - leftDeadSpace
const remaingingSpaceWidth = mapWidth - leftDeadSpace
const xOffset = leftDeadSpace
? remaingingSpaceStart - remaingingSpaceWidth / 2
: 0
const mapHeight = mapSize ? mapSize[0] : 0

const yOffset = popupType === 'popover' ? -100 : 0
const delta = getCenterPointDelta(mapWidth, mapHeight, deadSpace)

const offset = { x: xOffset, y: yOffset }
// If the popup is a popover, we need to adjust the y-axis to account for the
// desired design of the popover.
const yCorrection = popupType === 'popover' ? -100 : 0

const offset = {
x: delta[0],
y: delta[1] + yCorrection
}

const view = map.getView()
const resolution = view.getResolution()
Expand Down
11 changes: 8 additions & 3 deletions packages/ripple-ui-maps/src/components/popup/RplMapPopUp.css
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,22 @@
}

.rpl-map-popup--sidebar {
--local-infobox-mobile-blank-space: 106px;

z-index: var(--rpl-layer-1);
margin-left: var(--rpl-sp-2);
margin-top: var(--rpl-sp-2);
height: calc(var(--local-map-height) - var(--rpl-sp-2) * 2);
margin-top: var(--local-infobox-mobile-blank-space);
height: calc(
var(--local-map-height) - var(--local-infobox-mobile-blank-space) -
var(--rpl-sp-2)
);
width: 100%;
max-width: calc(100% - var(--rpl-sp-2) * 2);

.rpl-map-pop-up-scroll-container {
max-height: calc(
var(--local-map-height) - var(--local-popup-header-height) -
var(--rpl-sp-2) * 2
var(--local-infobox-mobile-blank-space) - var(--rpl-sp-2) * 2
);
}

Expand Down
12 changes: 12 additions & 0 deletions packages/ripple-ui-maps/src/composables/useMapDeadSpace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ export default (hasSidepanel, popupType, popup) => {

const deadSpace = computed(() => {
if (isMobile.value) {
// On mobile the infobox has a special design that shows a little bit of the map above it.
if (hasInfoboxPopup.value && !hasSidepanel) {
const mobileInfoboxHeight = 350

return {
left: 0,
right: 0,
bottom: mobileInfoboxHeight,
top: 0
}
}

return {
left: 0,
right: 0,
Expand Down

0 comments on commit 550c099

Please sign in to comment.