Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support new fields #3

Merged
merged 5 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const API_BASE_URL = `http://${location.hostname}:8000/v1`;
export const API_STATIONS_QUERY_URL = `${API_BASE_URL}/stations/?start=2000-01-01&end=2024-01-01`;
19 changes: 12 additions & 7 deletions src/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ import type OlMapBrowserEvent from 'ol/MapBrowserEvent';

import { BASEMAP } from '@src/basemap';
import { PROJECTION } from '@src/projection';
import { API_STATIONS_QUERY_URL } from '@src/api';

const EVENT_COUNT_FIELD_NAME = 'matching_event_count';
const EVENT_COUNT_FIELD_NAME = 'matching_rain_on_snow_event_count';
const EVENT_SCALE_MIN = 10;
const EVENT_SCALE_MAX = 1000;

export const useMap = () => { useEffect(() => {
/////////
Expand All @@ -27,7 +30,7 @@ export const useMap = () => { useEffect(() => {
const stationsLayer = new OlVectorLayer({
source: new OlVectorSource({
format: new OlGeoJSON(),
url: 'http://localhost:8000/v1/stations/?start=2000-01-01&end=2024-01-01',
url: API_STATIONS_QUERY_URL,
}),
// @ts-ignore: Allow lists for circle-radius and circle-fill-color
style: {
Expand All @@ -37,18 +40,18 @@ export const useMap = () => { useEffect(() => {
'interpolate',
['linear'],
['get', EVENT_COUNT_FIELD_NAME],
2000,
EVENT_SCALE_MIN,
3,
10000,
EVENT_SCALE_MAX,
10,
],
'circle-fill-color': [
'interpolate',
['linear'],
['get', EVENT_COUNT_FIELD_NAME],
2000,
EVENT_SCALE_MIN,
'hsl(210 100% 40% / 0.9)',
10000,
EVENT_SCALE_MAX,
'hsl(0 80% 60% / 0.9)',
],
},
Expand Down Expand Up @@ -82,8 +85,10 @@ export const useMap = () => { useEffect(() => {

const featureText = (feature: OlFeatureLike) => {
return `<strong>${feature.get("name") as string}</strong>
<br/>
Elevation: ${String(feature.get('elevation_meters'))} meters
<hr/>
Matching events: ${feature.get(EVENT_COUNT_FIELD_NAME) as string}`;
Matching rain on snow events: ${feature.get(EVENT_COUNT_FIELD_NAME) as string}`;
};

const displayFeatureInfo = function (pixel: OlPixel, target: Element) {
Expand Down
Loading