diff --git a/src/pages/Arrow.tsx b/src/pages/Arrow.tsx index a377723..7b02766 100644 --- a/src/pages/Arrow.tsx +++ b/src/pages/Arrow.tsx @@ -1,11 +1,13 @@ import L from "leaflet"; -import { createSignal, For, onMount } from "solid-js"; +import { createEffect, createSignal, onMount } from "solid-js"; let map: L.Map | null = null; export function Arrow() { const container =
; - const [points, setPoints] = createSignal>([]); + const [first_point, set_first_point] = createSignal(null); + const [second_point, set_second_point] = createSignal(null); + const [points, setPoints] = createSignal>([]); onMount(() => { map = L.map(container as HTMLElement) @@ -19,19 +21,44 @@ export function Arrow() { // Set up click logic map.addEventListener("click", (ev) => { - const p1 = ev.latlng; - const p2 = new L.LatLng( - p1.lat + 0.005, - p1.lng, - ); + const point = ev.latlng; - const [c1, c2, c3] = compute_triangle_points(p1, p2); + if (first_point() === null) { + // Set first point + set_first_point(point); + return; + } + if (second_point() === null) { + set_second_point(point); - // Draw the arrow. TODO: direction - L.polygon([c1, c2, c3], { color: "red" }).addTo(map!); + // Compute the triangle + const p1 = first_point()!; + + const [c1, c2, c3] = compute_triangle_points(p1, point); + + // Draw the arrow. TODO: direction + L.polygon([c1, c2, c3], { color: "red" }).addTo(map!); + + // Reset + set_first_point(null); + set_second_point(null); + } }); }); + let current_polyline: L.Polyline | null = null; + createEffect(() => { + const dots = points().map(([lat, lng]) => ({ lat, lng })); + if (dots.length === 0) { + current_polyline?.removeFrom(map!); + current_polyline = null; + } + + current_polyline = L.polyline(dots, { color: "red" }); + current_polyline.addTo(map!); + }); + + return (
@@ -41,30 +68,41 @@ export function Arrow() {

- Haz click en cualquier parte del mapa para crear una flecha. + Ingresá una ruta. +
+ Haz click en un punto de la ruta (punto inicial) +
+ Haz click en otro punto de la ruta (punto final) +
+ Un triangulo se creará en el medio, apuntdando hacia + el punto final

- Puntos: + Ruta:
-
- - {(p) =>

{p.lat},{p.lng}

} -
+