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

Create GPS URL query #152

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
30 changes: 30 additions & 0 deletions components/map-url-params.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { useRouter } from "next/router";
import { useState } from "react";
import { useMap, useMapEvent } from "react-leaflet";

export default function MapURLParams() {
// const route = useRouter();
// // console.log(route);

// const [location, setLocation] = useState(() => {
// const { lng, lat, zoom } = route.query;
// return { lng: lng, lat: lat, zoom: zoom };
// });
// // zoomend
// const map = useMapEvent("dragend zoomend", (e) => {
// const z = e.target.getZoom();
// const c = e.target.getCenter();
// console.log("onMoveEnd", z, c);
// setLocation({
// lng: c.lng,
// lat: c.lat,
// zoom: z,
// });
// route.push(`?lat=${c.lat}&lng=${c.lng}&zoom=${z}`, undefined, {
// shallow: true,
// });
// map.setView([c.lat, c.lng], z);
// });

return null;
}
2 changes: 2 additions & 0 deletions components/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "leaflet/dist/leaflet.css";
import SracLocation from "../components/map-srac-location";
import MapToilets from "../components/map-toilets";
import MapPicker from "./map-picker";
import MapURLParams from "./map-url-params";

export default function Map() {
return (
Expand All @@ -21,6 +22,7 @@ export default function Map() {
<SracLocation />
<MapToilets />
<MapPicker />
<MapURLParams />
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/L.Control.Locate.min.css"
Expand Down
6 changes: 6 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function parseParamsFloat(input) {
return parseFloat(input);
}
export function parseParamsInt(input) {
return parseInt(input);
}