Use same city coords for station and city view

This commit is contained in:
Guntis Smaukstelis
2024-01-22 23:54:33 +02:00
parent 80a192a401
commit 68decb613c
4 changed files with 18 additions and 42 deletions
+17 -6
View File
@@ -1,12 +1,12 @@
import { Component, createEffect, createSignal, onMount } from "solid-js";
import { ResultKeyVal } from "../../consts";
import { cityCoords } from "./cityCoords";
import { drawRotatedImage, getAngleFromString } from "./windAngles";
import { WindInputs, WindSignals } from "./WindInputs";
import mapUrl from "../../assets/map_1920x1080.webp";
import arrowUrl from "../../assets/arrow.webp";
import { cityCoords } from "../../components/cityCoords";
export const MapView: Component<{ data: () => ResultKeyVal[] }> = ({ data }) => {
const [getCanvas, setCanvas] = createSignal<HTMLCanvasElement>();
@@ -78,7 +78,10 @@ function drawOnMap(
coords: [string, {x: number, y: number }, number][],
windData: [string, string, string, boolean],
): void {
const size = 80;
const boxSize = 80;
const offsetX = 90;
const offsetY = 120;
const scale = 1.35;
const [windDirection, windSpeed, windGusts, roundValues] = windData;
const [bgImg, arrowImg] = imgArr;
@@ -89,7 +92,13 @@ function drawOnMap(
// city boxes
ctx.fillStyle = "#FFFFFF";
coords.forEach(([, {x, y}, value]) => {
ctx.rect(x, y, size, size);
const localX = offsetX + x * scale;
const localY = offsetY + y * scale;
ctx.beginPath();
ctx.fillStyle = "#FFFFFF";
ctx.rect(localX-boxSize/2, localY-boxSize/2, boxSize, boxSize);
ctx.fill();
});
ctx.fill();
@@ -97,12 +106,14 @@ function drawOnMap(
ctx.font = "bold 30px Rubik";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#000000";
coords.forEach(([, {x, y}, value]) => {
ctx.rect(x, y, size, size);
const localX = offsetX + x * scale;
const localY = offsetY + y * scale;
ctx.fillStyle = "#000000";
const numericValue = roundValues ? Math.round(value) : value;
const stringValue = numericValue.toString().replace(".", ",");
ctx.fillText(stringValue, x + size/2, y + size/2);
ctx.fillText(stringValue, localX, localY);
});
// wind values
-35
View File
@@ -1,35 +0,0 @@
export const cityCoords = {
"Ainaži": { x: 685, y: 146 },
"Alūksne": { x: 1176, y: 294 },
"Bauska": { x: 721, y: 608 },
"Dagda": { x: 1280, y: 680 },
"Daugavgrīva": { x: 640, y: 410 },
"Daugavpils": { x: 1140, y: 739 },
"Dobele": { x: 550, y: 580 },
"Gulbene": { x: 1100, y: 370 },
"Jelgava": { x: 620, y: 570 },
"Kalnciems": { x: 600, y: 500 },
"Kolka": { x: 380, y: 200 },
"Kuldīga": { x: 300, y: 470 },
"Lielpēči": { x: 780, y: 490 },
"Liepāja": { x: 124, y: 638 },
"Madona": { x: 1004, y: 432 },
"Mērsrags": { x: 480, y: 300 },
"Pāvilosta": { x: 160, y: 450 },
"Piedruja": { x: 1290, y: 770 },
"Priekuļi": { x: 900, y: 320 },
"Rēzekne": { x: 1229, y: 544 },
"Rīga": { x: 689, y: 430 },
"Rucava": { x: 140, y: 710 },
"Rūjiena": { x: 870, y: 140 },
"Saldus": { x: 383, y: 561 },
"Sigulda": { x: 810, y: 380 },
"Sīļi": { x: 1050, y: 640 },
"Skrīveri": { x: 880, y: 530 },
"Skulte": { x: 710, y: 320 },
"Stende": { x: 402, y: 400 },
"Ventspils": { x: 210, y: 329 },
"Vičaki": { x: 270, y: 260},
"Zīlāni": { x: 983, y: 581 },
"Zosēni": { x: 970, y: 370 },
};
+1 -1
View File
@@ -1,11 +1,11 @@
import { Accessor, Component, Setter, createEffect, createResource, createSignal, onMount } from "solid-js";
import { coordToCity } from "./coordToCity";
import { cityCoords } from "./cityCoords";
import mapUrl from "../assets/map_1000x570.webp";
import moment from "moment";
import { FETCH_DELAY_MS, apiHost, cityList } from "../consts";
import { LoadingSpinner } from "../components/LoadingSpinner";
import { cityCoords } from "../components/cityCoords";
export const MapResult: Component<{
setCity: Setter<string | undefined>,