Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(map): Add cycling raster layer from CyclOSM and a visibility toggle #949

Merged
merged 5 commits into from
Aug 30, 2024
Merged
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
37 changes: 34 additions & 3 deletions frontend/components/media/MediaMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import MapLibreGlDirections, {
layersFactory,
} from "@maplibre/maplibre-gl-directions";
import maplibregl from "maplibre-gl";
import maplibregl, { Map } from "maplibre-gl";
import "maplibre-gl/dist/maplibre-gl.css";

const props = defineProps<{
Expand Down Expand Up @@ -126,6 +126,14 @@ const mapProfile = (profile: string) => {

let selectedRoute = mapProfile(routeProfileOptions.FOOT);

const toggleLayerHandler = (map: Map) => {
if (currentProfile === walkingRouteProfileControl) {
map.setLayoutProperty("cycle-layer", "visibility", "visible");
} else {
map.setLayoutProperty("cycle-layer", "visibility", "none");
}
};

const routeProfileHandler = () => {
if (currentProfile === walkingRouteProfileControl) {
currentProfile = bikeRouteProfileControl;
Expand Down Expand Up @@ -167,7 +175,18 @@ onMounted(() => {
tiles: ["https://tile.openstreetmap.org/{z}/{x}/{y}.png"],
tileSize: 256,
attribution:
'<a href="https://www.openstreetmap.org/about" target="_blank">Data &copy; OpenStreetMap contributors</a>',
'<a href="https://www.openstreetmap.org/copyright" target="_blank">&copy; OpenStreetMap contributors</a>',
},
"cycle-raster-tiles": {
type: "raster",
tiles: [
"https://a.tile-cyclosm.openstreetmap.fr/cyclosm-lite/{z}/{x}/{y}.png",
"https://b.tile-cyclosm.openstreetmap.fr/cyclosm-lite/{z}/{x}/{y}.png",
"https://c.tile-cyclosm.openstreetmap.fr/cyclosm-lite/{z}/{x}/{y}.png",
Comment on lines +183 to +185
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding thoughts here..

It could potentially be good if we're able to load the tile source URLs from env vars - instead of configuring these hard-coded. Same as with https://tile.openstreetmap.org for the default layer source URL and the geocoding API URL https://nominatim.openstreetmap.org.

To note - as they are, the latter two are probably easy to do as we can simply replace them with an env var each. What about multiple-subdomain URLs though as in here for CyclOSM? We might have to configure a way to be able to add more or less env vars if the number of subdomains change.

Or - we decide to not concern ourselves too much given that the mentioned services are likely to be and continue fairly stable in the near future? 🤔🤷

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya I'd say for now let's not concern ourselves too much with this, @wkyoshida :) We can revisit it later when we have a bit more capacity 😊

],
tileSize: 256,
attribution:
'<a href="https://www.cyclosm.org" target="_blank">CyclOSM</a> tiles hosted by <a href="https://openstreetmap.fr" target="_blank">OpenStreetMap France</a>',
},
},
layers: [
Expand All @@ -180,12 +199,22 @@ onMounted(() => {
},
},
{
id: "simple-tiles",
id: "default-layer",
type: "raster",
source: "raster-tiles",
minzoom: 0,
maxzoom: 24,
},
{
id: "cycle-layer",
type: "raster",
source: "cycle-raster-tiles",
minzoom: 0,
maxzoom: 20,
layout: {
visibility: "none",
},
},
],
},
center: [parseFloat(location["lon"]), parseFloat(location["lat"])],
Expand Down Expand Up @@ -304,6 +333,8 @@ onMounted(() => {
div.innerHTML = currentProfile;

const updateSelectedProfile = () => {
toggleLayerHandler(map);

directions.destroy();
div.innerHTML = routeProfileHandler();

Expand Down
Loading