Add weather icon inputs to cities on map
This commit is contained in:
+16
-10
@@ -6,6 +6,7 @@ import { Cities } from './cities/Cities';
|
|||||||
import { Database } from './database/Database';
|
import { Database } from './database/Database';
|
||||||
import { Station } from './station/Station';
|
import { Station } from './station/Station';
|
||||||
import { apiHost } from './consts';
|
import { apiHost } from './consts';
|
||||||
|
import { WeatherIconStub } from './components/weatherIcons/WeatherIconStub';
|
||||||
|
|
||||||
console.log("env:", import.meta.env.MODE);
|
console.log("env:", import.meta.env.MODE);
|
||||||
console.log("api host:", apiHost);
|
console.log("api host:", apiHost);
|
||||||
@@ -30,16 +31,21 @@ const App: Component = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div class={styles.App}>
|
<div class={styles.App}>
|
||||||
<ul class={styles.menu}>
|
<div class="grid-1-1">
|
||||||
{ pages.map(([pageTitle]) =>
|
<div><WeatherIconStub /></div>
|
||||||
<li
|
<div>
|
||||||
class={getActiveCSS(pageTitle)}
|
<ul class={styles.menu}>
|
||||||
onClick={() => setPageTitle(pageTitle)}
|
{ pages.map(([pageTitle]) =>
|
||||||
>
|
<li
|
||||||
{pageTitle}
|
class={getActiveCSS(pageTitle)}
|
||||||
</li>
|
onClick={() => setPageTitle(pageTitle)}
|
||||||
)}
|
>
|
||||||
</ul>
|
{pageTitle}
|
||||||
|
</li>
|
||||||
|
)}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{ getPageContent() }
|
{ getPageContent() }
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Binary file not shown.
@@ -5,13 +5,17 @@ import { WindInputs, WindSignals } from "./WindInputs";
|
|||||||
|
|
||||||
import arrowUrl from "../../assets/arrow.webp";
|
import arrowUrl from "../../assets/arrow.webp";
|
||||||
import { cityCoords } from "../../components/cityCoords";
|
import { cityCoords } from "../../components/cityCoords";
|
||||||
import { MapResolution, resolutionProps, ResolutionPropsValue, windProps, WindProps } from "./mapConsts";
|
import { MapResolution, resolutionProps, windProps, WindProps } from "./mapConsts";
|
||||||
import { drawOnMap } from "./canvasDraw";
|
import { CityData, drawOnMap } from "./canvasDraw";
|
||||||
|
import { IconInputs } from "../../components/weatherIcons/IconInputs";
|
||||||
|
|
||||||
export const MapView: Component<{ type: MapResolution, data: () => ResultKeyVal[] }> = ({ type, data }) => {
|
export const MapView: Component<{ type: MapResolution, data: () => ResultKeyVal[] }> = ({ type, data }) => {
|
||||||
const [getCanvas, setCanvas] = createSignal<HTMLCanvasElement>();
|
const [getCanvas, setCanvas] = createSignal<HTMLCanvasElement>();
|
||||||
const [getImg, setImg] = createSignal(new Image());
|
const [getImg, setImg] = createSignal(new Image());
|
||||||
let lastCoords: [string, {x: number, y: number }, number][] = [];
|
const weatherIconsSingal = createSignal<{[key: string]: string;}>({});
|
||||||
|
const [getWeatherIcons] = weatherIconsSingal;
|
||||||
|
|
||||||
|
let lastCoords: CityData = [];
|
||||||
const props = resolutionProps[type];
|
const props = resolutionProps[type];
|
||||||
|
|
||||||
const arrowImg = new Image();
|
const arrowImg = new Image();
|
||||||
@@ -52,16 +56,18 @@ export const MapView: Component<{ type: MapResolution, data: () => ResultKeyVal[
|
|||||||
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
const ctx = getCanvas()!.getContext("2d")!;
|
const ctx = getCanvas()!.getContext("2d")!;
|
||||||
const coordsAndData: [string, {x: number, y: number }, number][] = data()
|
const weatherIcons = getWeatherIcons();
|
||||||
|
const coordsAndData: CityData = data()
|
||||||
.map(([city, value]) => [
|
.map(([city, value]) => [
|
||||||
city,
|
city,
|
||||||
cityCoords[city as keyof typeof cityCoords],
|
cityCoords[city as keyof typeof cityCoords],
|
||||||
typeof value === "number" ? value : -99,
|
typeof value === "number" ? value : -99,
|
||||||
|
weatherIcons[city],
|
||||||
]);
|
]);
|
||||||
lastCoords = coordsAndData;
|
lastCoords = coordsAndData;
|
||||||
drawOnMap(
|
drawOnMap(
|
||||||
ctx,
|
ctx,
|
||||||
[getImg(),arrowImg],
|
[getImg(), arrowImg],
|
||||||
coordsAndData,
|
coordsAndData,
|
||||||
getWindData(),
|
getWindData(),
|
||||||
props,
|
props,
|
||||||
@@ -76,7 +82,12 @@ export const MapView: Component<{ type: MapResolution, data: () => ResultKeyVal[
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{ props.showWind && <WindInputs signals={windSignals} /> }
|
<div class="grid-1-2">
|
||||||
|
<div>
|
||||||
|
{ props.showWind && <WindInputs signals={windSignals} /> }
|
||||||
|
</div>
|
||||||
|
<div><IconInputs weatherIconsSingal={weatherIconsSingal} /></div>
|
||||||
|
</div>
|
||||||
<canvas
|
<canvas
|
||||||
ref={setCanvas}
|
ref={setCanvas}
|
||||||
width={props.width+"px"}
|
width={props.width+"px"}
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
import { ResolutionPropsValue, WindProps, windProps } from "./mapConsts";
|
import { ResolutionPropsValue, WindProps, windProps } from "./mapConsts";
|
||||||
import { drawRotatedImage, getAngleFromString } from "./windAngles";
|
import { drawRotatedImage, getAngleFromString } from "./windAngles";
|
||||||
|
|
||||||
|
// cityName, {x, y}, weatherValue, icon
|
||||||
|
export type CityData = [string, {x: number, y: number }, number, string | undefined][];
|
||||||
|
|
||||||
export function drawOnMap(
|
export function drawOnMap(
|
||||||
ctx: CanvasRenderingContext2D,
|
ctx: CanvasRenderingContext2D,
|
||||||
imgArr: [HTMLImageElement, HTMLImageElement],
|
imgArr: [HTMLImageElement, HTMLImageElement],
|
||||||
coords: [string, {x: number, y: number }, number][],
|
cityData: CityData,
|
||||||
windData: [string, string, string, boolean, WindProps],
|
windData: [string, string, string, boolean, WindProps],
|
||||||
props: ResolutionPropsValue,
|
props: ResolutionPropsValue,
|
||||||
): void {
|
): void {
|
||||||
@@ -16,7 +19,7 @@ export function drawOnMap(
|
|||||||
|
|
||||||
// city boxes
|
// city boxes
|
||||||
ctx.fillStyle = "#FFFFFF";
|
ctx.fillStyle = "#FFFFFF";
|
||||||
coords.forEach(([, {x, y}, value]) => {
|
cityData.forEach(([, {x, y}]) => {
|
||||||
const localX = props.offsetX + x * props.scale;
|
const localX = props.offsetX + x * props.scale;
|
||||||
const localY = props.offsetY + y * props.scale;
|
const localY = props.offsetY + y * props.scale;
|
||||||
|
|
||||||
@@ -28,17 +31,24 @@ export function drawOnMap(
|
|||||||
ctx.fill();
|
ctx.fill();
|
||||||
|
|
||||||
// weather values
|
// weather values
|
||||||
ctx.font = `bold ${props.fontSize}px Rubik`;
|
cityData.forEach(([, {x, y}, value, icon]) => {
|
||||||
ctx.textAlign = "center";
|
|
||||||
ctx.textBaseline = "middle";
|
|
||||||
coords.forEach(([, {x, y}, value]) => {
|
|
||||||
const localX = props.offsetX + x * props.scale;
|
const localX = props.offsetX + x * props.scale;
|
||||||
const localY = props.offsetY + y * props.scale;
|
const localY = props.offsetY + y * props.scale;
|
||||||
|
|
||||||
|
ctx.font = `bold ${props.fontSize}px Rubik`;
|
||||||
|
ctx.textAlign = "center";
|
||||||
|
ctx.textBaseline = "middle";
|
||||||
ctx.fillStyle = "#000000";
|
ctx.fillStyle = "#000000";
|
||||||
const numericValue = roundValues ? Math.round(value) : value;
|
const numericValue = roundValues ? Math.round(value) : value;
|
||||||
const stringValue = numericValue.toString().replace(".", ",");
|
const stringValue = numericValue.toString().replace(".", ",");
|
||||||
ctx.fillText(stringValue, localX, localY);
|
ctx.fillText(stringValue, localX, localY);
|
||||||
|
|
||||||
|
if (icon) {
|
||||||
|
ctx.fillStyle = "#FFFFFF";
|
||||||
|
ctx.font = `normal ${props.fontSize * 5}px Daira by LTV grafika`;
|
||||||
|
const iconSize = ctx.measureText(icon);
|
||||||
|
ctx.fillText(icon, localX + props.boxSize/2 + 10 + iconSize.width/2, localY);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!props.showWind) return;
|
if (!props.showWind) return;
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ export const ResultView: Component<{
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div class="resultTitle">
|
<div class="resultTitle">
|
||||||
<h3>Result:</h3>
|
|
||||||
<span>
|
<span>
|
||||||
{resultViews.map(viewName =>
|
{resultViews.map(viewName =>
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import { Component, Signal } from "solid-js";
|
||||||
|
import { weatherIconCities, weatherIcons } from "./iconConsts";
|
||||||
|
|
||||||
|
import "../../css/weatherIcons.css";
|
||||||
|
|
||||||
|
export const IconInputs: Component<{ weatherIconsSingal: Signal<{[key: string]: string;}>; }> = ({
|
||||||
|
weatherIconsSingal: [getWeatherIcons, setWeatherIcons]
|
||||||
|
}) => {
|
||||||
|
|
||||||
|
function onIconChange(city: string, icon: string) {
|
||||||
|
const weatherIcons = { ...getWeatherIcons() };
|
||||||
|
weatherIcons[city] = icon;
|
||||||
|
if (icon === "") delete weatherIcons[city];
|
||||||
|
|
||||||
|
setWeatherIcons(weatherIcons);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div>
|
||||||
|
{ weatherIcons.map(icon =>
|
||||||
|
<span class="weatherIconButton" onClick={() => copyToClipboard(icon)}>{ icon }</span>)
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
{ weatherIconCities.map(city =>
|
||||||
|
<div style="float: left;">
|
||||||
|
{city}:
|
||||||
|
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
class="weatherIconInput"
|
||||||
|
size="1"
|
||||||
|
maxlength="1"
|
||||||
|
onInput={e => onIconChange(city, e.target.value)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
</div>)
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function copyToClipboard(icon: string) {
|
||||||
|
navigator.clipboard.writeText(icon);
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { Component } from "solid-js";
|
||||||
|
|
||||||
|
/* Put this in page so browser actually downloads ltv font */
|
||||||
|
export const WeatherIconStub: Component<{}> = () => {
|
||||||
|
return (
|
||||||
|
<div class="weatherIconStub">ABCDEF</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
/* font-family: 'Daira by LTV grafika'; */
|
||||||
|
export const weatherIcons = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i"];
|
||||||
|
export const weatherIconCities = ['Ainaži', 'Alūksne', 'Bauska', 'Daugavpils', 'Liepāja', 'Madona', 'Priekuļi', 'Rēzekne', 'Rīga', 'Saldus', 'Stende', 'Ventspils', 'Zīlāni'];
|
||||||
@@ -55,6 +55,14 @@ table tr:hover {
|
|||||||
background: #c0c0c0;
|
background: #c0c0c0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Daira by LTV grafika';
|
||||||
|
src: url('../assets/ltv_meteo.otf') format('truetype');
|
||||||
|
font-weight: normal;
|
||||||
|
font-style: normal;
|
||||||
|
font-display: swap;
|
||||||
|
}
|
||||||
|
|
||||||
.hidden {
|
.hidden {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
@@ -62,3 +70,15 @@ table tr:hover {
|
|||||||
.visible {
|
.visible {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.grid-1-1 {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-1-2 {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 2fr;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
.weatherIconButton {
|
||||||
|
font-family: 'Daira by LTV grafika';
|
||||||
|
font-size: 30px;
|
||||||
|
display: inline-block;
|
||||||
|
background-color: #ccc;
|
||||||
|
padding: 3px 4px;
|
||||||
|
margin: 0 3px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.weatherIconButton:hover {
|
||||||
|
background-color: #333;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.weatherIconInput {
|
||||||
|
font-family: 'Daira by LTV grafika';
|
||||||
|
font-size: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.weatherIconStub {
|
||||||
|
font-family: 'Daira by LTV grafika';
|
||||||
|
font-size: 20px;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user