Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions public/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
--menu-radius: 3px;
--menu-padding: 4px 12px;
--header-height: 54px;
/* media query changes this value dynamically so that JavaScript can read it */
--current-breakpoint: desktop;
}

body {
Expand Down Expand Up @@ -175,6 +177,11 @@ a {
}

@media (max-width: 768px) {
:root {
/* media query changes this value dynamically so that JavaScript can read it */
--current-breakpoint: mobile;
}

.hamburger-menu {
display: block;
font-size: 1.5rem;
Expand Down Expand Up @@ -243,8 +250,8 @@ a {
}
}

/*
* Basemap Switcher
/*
* Basemap Switcher
*/

.basemap-switcher-container {
Expand Down
7 changes: 6 additions & 1 deletion public/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import "./lib/external/maplibre/maplibre-gl-geocoder/maplibre-gl-geocoder.js";

import { BasemapSwitcher } from "./lib/internal/BasemapSwitcher.js";
import {
isMobile,
setGlobePermalinkUpdate,
setupLinkUpdate,
} from "./lib/internal/mapUtils.js";
Expand Down Expand Up @@ -83,7 +84,11 @@ const setupMap = () => {
map.addLayer({ id, source: id, type: "raster" });
});

map.addControl(createSearchControl(maplibregl));
const searchControl = createSearchControl({
mapInstance: maplibregl,
collapsed: isMobile(),
});
map.addControl(searchControl);

map.addControl(new maplibregl.NavigationControl({ showCompass: false }));

Expand Down
22 changes: 21 additions & 1 deletion public/lib/internal/mapUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,24 @@ const setGlobePermalinkUpdate = (mapLibreMap) => {
});
};

export { setupLinkUpdate, setGlobePermalinkUpdate };
/**
* Checks if the website is currently on mobile or desktop mode.
*
* Determines the state by reading a CSS variable that is dynamically set by
* the CSS media query.
*/
const isMobile = () => {
const breakPointValue = getComputedStyle(document.documentElement)
.getPropertyValue("--current-breakpoint")
.trim();

if (!["desktop", "mobile"].includes(breakPointValue)) {
throw new Error(
"Could not determine if website is in mobile or desktop mode.",
);
}

return breakPointValue === "mobile";
};

export { setupLinkUpdate, setGlobePermalinkUpdate, isMobile };
5 changes: 3 additions & 2 deletions public/lib/internal/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ const reverseGeocode = (config) => {
return fetch(url).then(processPhotonResponse);
};

export function createSearchControl(mapInstance) {
export function createSearchControl(config) {
const { mapInstance, collapsed } = config;
const geocoderApi = {
forwardGeocode: forwardGeocode,
reverseGeocode: reverseGeocode,
Expand All @@ -132,7 +133,7 @@ export function createSearchControl(mapInstance) {
maplibregl: mapInstance,
limit: countDisplayedResults,
language: defaultLanguage,
collapsed: true,
collapsed: collapsed,

// needed for autocomplete
showResultsWhileTyping: true,
Expand Down
Loading