Add optional arrows

master
Araozu 2024-09-05 20:17:58 -05:00
parent bac8157aec
commit 5d5d13f0b7
7 changed files with 30 additions and 10 deletions

View File

@ -4,7 +4,7 @@
"description": "", "description": "",
"scripts": { "scripts": {
"start": "vite", "start": "vite",
"dev": "vite", "dev": "vite --host",
"build": "vite build", "build": "vite build",
"serve": "vite preview" "serve": "vite preview"
}, },

File diff suppressed because one or more lines are too long

View File

@ -24,5 +24,6 @@ export interface Route {
name: string name: string
/** `[lat,lng]`, stored as arrays to save space in JSON */ /** `[lat,lng]`, stored as arrays to save space in JSON */
points: Array<[number, number]> points: Array<[number, number]>
arrows?: Array<[L.LatLng, L.LatLng, L.LatLng, L.LatLng]>
} }

View File

@ -8,6 +8,7 @@ export function Arrow() {
const [first_point, set_first_point] = createSignal<L.LatLng | null>(null); const [first_point, set_first_point] = createSignal<L.LatLng | null>(null);
const [second_point, set_second_point] = createSignal<L.LatLng | null>(null); const [second_point, set_second_point] = createSignal<L.LatLng | null>(null);
const [points, setPoints] = createSignal<Array<[number, number]>>([]); const [points, setPoints] = createSignal<Array<[number, number]>>([]);
let arrows: Array<[L.LatLng, L.LatLng, L.LatLng, L.LatLng]> = [];
onMount(() => { onMount(() => {
map = L.map(container as HTMLElement) map = L.map(container as HTMLElement)
@ -34,10 +35,11 @@ export function Arrow() {
// Compute the triangle // Compute the triangle
const p1 = first_point()!; const p1 = first_point()!;
const [c1, c2, c3, c4] = compute_triangle_points(p1, point); const points = compute_triangle_points(p1, point);
// Draw the arrow. // Draw the arrow.
L.polygon([c1, c2, c3, c4], { color: "red" }).addTo(map!); L.polygon(points, { color: "red" }).addTo(map!);
arrows.push(points);
// Reset // Reset
set_first_point(null); set_first_point(null);
@ -95,6 +97,15 @@ export function Arrow() {
Punto 2: {second_point()?.lat ?? "<vacio>"}, {second_point()?.lng ?? "<vacio>"} Punto 2: {second_point()?.lat ?? "<vacio>"}, {second_point()?.lng ?? "<vacio>"}
</div> </div>
<button class="bg-c-primary text-white py-2 px-4 rounded mr-2"
onClick={() => {
navigator.clipboard.writeText(JSON.stringify(arrows))
.then(() => alert("copiado"))
.catch(() => alert("error copiando"));
}}
>
Copiar flechas
</button>
<button class="bg-c-primary text-white py-2 px-4 rounded mr-2" <button class="bg-c-primary text-white py-2 px-4 rounded mr-2"
onClick={() => { onClick={() => {
const confirmation = confirm("¿Estas seguro? Se perderán todos los puntos"); const confirmation = confirm("¿Estas seguro? Se perderán todos los puntos");
@ -102,6 +113,7 @@ export function Arrow() {
setPoints([]); setPoints([]);
set_first_point(null); set_first_point(null);
set_second_point(null); set_second_point(null);
arrows = [];
} }
}} }}
> >
@ -146,9 +158,7 @@ function compute_triangle_points(start: L.LatLng, end: L.LatLng): [L.LatLng, L.L
// Compute the angle of the rect // Compute the angle of the rect
// what do you call the "pendiente" of a rect? // what do you call the "pendiente" of a rect?
const pendiente = (y2 - y1) / (x2 - x1); const pendiente = (y2 - y1) / (x2 - x1);
console.log("pendiente:", pendiente);
const angle = Math.atan(pendiente); const angle = Math.atan(pendiente);
console.log("angle: ", angle * (180 / Math.PI));
// Vector pointing upwards // Vector pointing upwards
const [vx, vy] = [delta, 0]; const [vx, vy] = [delta, 0];

View File

@ -66,7 +66,7 @@ export function Editor() {
}; };
return ( return (
<div class="grid grid-cols-[30rem_auto]"> <div class="grid grid-cols-[20rem_auto]">
<div> <div>
<h1 class="text-c-primary text-center font-bold text-2xl py-4">AQP combi</h1> <h1 class="text-c-primary text-center font-bold text-2xl py-4">AQP combi</h1>
<h2 class="bg-c-primary text-white py-2 px-2 font-bold text-lg"> <h2 class="bg-c-primary text-white py-2 px-2 font-bold text-lg">

View File

@ -1,5 +1,5 @@
import { Map, map, polyline, tileLayer } from "leaflet"; import { Map, map, polyline, tileLayer } from "leaflet";
import { createEffect, createResource, For, onMount, Suspense } from "solid-js"; import { createEffect, createResource, createSignal, For, onMount, Suspense } from "solid-js";
import { Line, RouteWrapper, Route, LineWrapper, PointsWrapper } from "../types"; import { Line, RouteWrapper, Route, LineWrapper, PointsWrapper } from "../types";
import { LineSegmentsIcon } from "../icons/LineSegmentsIcon"; import { LineSegmentsIcon } from "../icons/LineSegmentsIcon";
@ -85,6 +85,7 @@ function LineEl(props: { line: Line }) {
} }
function RouteEl(props: { route: Route, parent_id: number, color: string }) { function RouteEl(props: { route: Route, parent_id: number, color: string }) {
const [draw, setDraw] = createSignal(false);
const [points] = createResource<PointsWrapper>(async() => { const [points] = createResource<PointsWrapper>(async() => {
const res = await fetch(`/data/cuenca_${props.parent_id}_ruta_${props.route.id_ruta}_ida.json`); const res = await fetch(`/data/cuenca_${props.parent_id}_ruta_${props.route.id_ruta}_ida.json`);
if (!res.ok) throw new Error("Error fetching data"); if (!res.ok) throw new Error("Error fetching data");
@ -97,7 +98,7 @@ function RouteEl(props: { route: Route, parent_id: number, color: string }) {
}); });
createEffect(() => { createEffect(() => {
if (points.state === "ready") { if (points.state === "ready" && draw()) {
// Render the dots into the map // Render the dots into the map
const coords = points()!.data[0]!.ruta_json; const coords = points()!.data[0]!.ruta_json;
@ -107,7 +108,7 @@ function RouteEl(props: { route: Route, parent_id: number, color: string }) {
}); });
createEffect(() => { createEffect(() => {
if (return_points.state === "ready") { if (return_points.state === "ready" && draw()) {
// Render the dots into the map // Render the dots into the map
const coords = return_points()!.data[0]!.ruta_json; const coords = return_points()!.data[0]!.ruta_json;
@ -117,7 +118,7 @@ function RouteEl(props: { route: Route, parent_id: number, color: string }) {
}); });
return ( return (
<div class="pl-10"> <div class="pl-10" onClick={() => setDraw(true)}>
Ruta {props.route.cod_ruta} Ruta {props.route.cod_ruta}
</div> </div>
); );

View File

@ -172,6 +172,9 @@ function re_render_polylines() {
if (active_count > 0) { if (active_count > 0) {
route_polilyne.setStyle({opacity: LINE_OPACITY}); route_polilyne.setStyle({opacity: LINE_OPACITY});
render_count += 1; render_count += 1;
// if the route has arrows and is manually toggled,
// render the arrows
} else { } else {
route_polilyne.setStyle({opacity: 0}); route_polilyne.setStyle({opacity: 0});
} }