diff --git a/web/src/App.tsx b/web/src/App.tsx index 8d202fd..9e06b58 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -17,7 +17,7 @@ const App: Component = () => { ["latvia", () => ], ["database", () => ], ]; - const [getPageTitle, setPageTitle] = createSignal("cities"); + const [getPageTitle, setPageTitle] = createSignal("station"); const getPageContent = () => { const page = pages.find(p => p[0] === getPageTitle()); diff --git a/web/src/assets/map_1000x570.webp b/web/src/assets/map_1000x570.webp new file mode 100644 index 0000000..18a4195 Binary files /dev/null and b/web/src/assets/map_1000x570.webp differ diff --git a/web/src/cities/Cities.tsx b/web/src/cities/Cities.tsx index cb78ccd..b0adda3 100644 --- a/web/src/cities/Cities.tsx +++ b/web/src/cities/Cities.tsx @@ -2,11 +2,12 @@ import moment from "moment"; import { createSignal } from "solid-js"; import { QueryResult } from "./result/QueryResult"; -import { SelectCity } from "./SelectCity"; +import { SelectCity } from "../components/SelectCity"; +import { SelectTimeRange } from "../components/SelectTimeRange"; + import { SelectField } from "./SelectField"; import { SelectGranularity } from "./SelectGranularity"; import { SelectKey } from "./SelectKey"; -import { SelectTimeRange } from "../components/SelectTimeRange"; const nowRounded = new Date(new Date().setMinutes(30)); const dayAgo = moment(nowRounded).subtract(1, "days").subtract(30, "minutes").toDate(); @@ -21,7 +22,6 @@ export function Cities() { return (
-

Cities

diff --git a/web/src/cities/SelectCity.tsx b/web/src/components/SelectCity.tsx similarity index 100% rename from web/src/cities/SelectCity.tsx rename to web/src/components/SelectCity.tsx diff --git a/web/src/country/Country.tsx b/web/src/country/Country.tsx index 4bc30de..7867a01 100644 --- a/web/src/country/Country.tsx +++ b/web/src/country/Country.tsx @@ -16,7 +16,6 @@ export function Country() { return (
-

Latvia

-

Database

diff --git a/web/src/station/Station.tsx b/web/src/station/Station.tsx index 81111bf..d24b207 100644 --- a/web/src/station/Station.tsx +++ b/web/src/station/Station.tsx @@ -1,15 +1,51 @@ -import { Component } from "solid-js"; +import { Component, createEffect, createSignal, onMount } from "solid-js"; + +import mapUrl from "../assets/map_1000x570.webp"; + +import "../css/station.css" +import { cityCoords } from "./cityCoords"; +import { SelectCity } from "../components/SelectCity"; + +export const Station: Component<{}> = () => { + const [getCanvas, setCanvas] = createSignal(); + const [getImg, setImg] = createSignal(new Image()); + const [getShowCities, setShowCities] = createSignal(false); + const [getCities, setCities] = createSignal>(new Set(["Rīga", "Rēzekne", "Liepāja"])); + + let ctx: CanvasRenderingContext2D | undefined; + + onMount(() => { + ctx = getCanvas()!.getContext("2d")!; + + const img = new Image(); + img.onload = () => setImg(img); + img.src = mapUrl; + }); + + createEffect(() => { + if (!ctx || !getImg()) return; + drawOnMap( + ctx!, + [getImg()], + getCities(), + ); + }); -export const Station: Component<{}> = (props) => { return ( -
-

Station

+
- 1st -
-
- 2nd + +
+ +
+
3rd @@ -17,4 +53,25 @@ export const Station: Component<{}> = (props) => {
); +} + +function drawOnMap( + ctx: CanvasRenderingContext2D, + imgArr: [HTMLImageElement], + cities: Set, +): void { + console.log("Draw cities"); + ctx.drawImage(imgArr[0], 0, 0); + ctx.fillStyle = "red"; + ctx.font = "18px serif"; + cities.forEach(city => { + const coord = cityCoords[city]; + if (!coord) return; + + ctx.beginPath(); + ctx.arc(coord.x, coord.y, 6, 0, 2 * Math.PI); + const cityTextSize = ctx.measureText(city); + ctx.fillText(city, coord.x - cityTextSize.width/2, coord.y - 6); + ctx.fill(); + }); } \ No newline at end of file diff --git a/web/src/station/cityCoords.ts b/web/src/station/cityCoords.ts new file mode 100644 index 0000000..80a15e6 --- /dev/null +++ b/web/src/station/cityCoords.ts @@ -0,0 +1,35 @@ +export const cityCoords: {[key: string]: { x: number, y: number}} = { + "Ainaži": { x: 467, y: 77 }, + "Alūksne": { x: 812, y: 145 }, + "Bauska": { x: 470, y: 405 }, + "Dagda": { x: 902, y: 450 }, + "Daugavgrīva": { x: 435, y: 250 }, + "Daugavpils": { x: 780, y: 508 }, + "Dobele": { x: 340, y: 365 }, + "Gulbene": { x: 770, y: 215 }, + "Jelgava": { x: 410, y: 350 }, + "Kalnciems": { x: 390, y: 310 }, + "Kolka": { x: 250, y: 87 }, + "Kuldīga": { x: 180, y: 277 }, + "Lielpēči": { x: 530, y: 310 }, + "Liepāja": { x: 55, y: 375 }, + "Madona": { x: 720, y: 280 }, + "Mērsrags": { x: 320, y: 185 }, + "Pāvilosta": { x: 80, y: 295 }, + "Piedruja": { x: 895, y: 520 }, + "Priekuļi": { x: 590, y: 195 }, + "Rēzekne": { x: 870, y: 350 }, + "Rīga": { x: 455, y: 275 }, + "Rucava": { x: 75, y: 470 }, + "Rūjiena": { x: 590, y: 60 }, + "Saldus": { x: 240, y: 350 }, + "Sigulda": { x: 540, y: 230 }, + "Sīļi": { x: 720, y: 410 }, + "Skrīveri": { x: 580, y: 340 }, + "Skulte": { x: 485, y: 195 }, + "Stende": { x: 250, y: 235 }, + "Ventspils": { x: 123, y: 175 }, + "Vičaki": { x: 155, y: 142}, + "Zīlāni": { x: 690, y: 370 }, + "Zosēni": { x: 650, y: 250 }, +}; \ No newline at end of file