Skip to content

Commit

Permalink
Merge branch 'master' into water-quality-data
Browse files Browse the repository at this point in the history
  • Loading branch information
yaodingyd authored Dec 3, 2024
2 parents 73d6b53 + 728e660 commit 2d8ecc8
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 106 deletions.
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"@turf/turf": "^6.5.0",
"@types/bluebird": "^3.5.32",
"@types/node-xlsx": "^0.15.3",
"axios": "^1.7.4",
"axios": "^1.7.8",
"axios-retry": "^3.8.1",
"bluebird": "^3.7.2",
"class-transformer": "^0.3.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ exports[`MultipleSensorsCharts should render with given state from Redux store 1
>
36.1
psu
ppt
</mock-typography>
</div>
<div
Expand All @@ -807,7 +807,7 @@ exports[`MultipleSensorsCharts should render with given state from Redux store 1
>
34.9
psu
ppt
</mock-typography>
</div>
<div
Expand All @@ -820,7 +820,7 @@ exports[`MultipleSensorsCharts should render with given state from Redux store 1
>
33.8
psu
ppt
</mock-typography>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export function metricFields(
{
label: 'Salinity',
value: `${formatNumber(data?.salinity, 1)}`,
unit: 'psu',
unit: source === 'hui' ? 'ppt' : 'psu',
xs: 6,
},
];
Expand Down
2 changes: 1 addition & 1 deletion packages/website/src/constants/chartConfigs/huiConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type SondeMetricsKeys = Extract<
export const huiConfig: Record<SondeMetricsKeys, BaseSourceConfig> = {
salinity: {
title: 'Salinity',
units: 'psu',
units: 'ppt',
description: '',
visibility: 'public',
order: 1,
Expand Down
3 changes: 2 additions & 1 deletion packages/website/src/helpers/dates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ export const rangeOverlapWithRange = (
) => {
return (
(minDate2 <= minDate1 && minDate1 <= maxDate2) ||
(minDate2 <= maxDate1 && maxDate1 <= maxDate2)
(minDate2 <= maxDate1 && maxDate1 <= maxDate2) ||
(minDate1 <= maxDate2 && maxDate2 <= maxDate1)
);
};
4 changes: 2 additions & 2 deletions packages/website/src/helpers/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ export const useSensorIcon = (
color: string,
) => {
const classes = useMarkerStyles();
const iconWidth = sensor === 'spotter' ? 20 : 25;
const iconHeight = sensor === 'spotter' ? 20 : 25;
const iconWidth = sensor === 'spotter' ? 15 : 20;
const iconHeight = sensor === 'spotter' ? 15 : 20;
return L.divIcon({
iconSize: [iconWidth, iconHeight],
iconAnchor: [iconWidth / 2, 0],
Expand Down
36 changes: 32 additions & 4 deletions packages/website/src/routes/HomeMap/Map/Markers/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useSelector } from 'react-redux';
import { LayerGroup, useLeaflet } from 'react-leaflet';
import MarkerClusterGroup from 'react-leaflet-markercluster';
import React, { useCallback, useEffect } from 'react';
import React, { useCallback, useEffect, useState, useMemo } from 'react';
import L from 'leaflet';
import { sitesToDisplayListSelector } from 'store/Sites/sitesListSlice';
import { Site } from 'store/Sites/types';
Expand Down Expand Up @@ -34,9 +34,13 @@ const clusterIcon = (cluster: any) => {

export const SiteMarkers = ({ collection }: SiteMarkersProps) => {
const storedSites = useSelector(sitesToDisplayListSelector);
const sitesList = collection?.sites || storedSites || [];
const sitesList = useMemo(
() => collection?.sites || storedSites || [],
[collection?.sites, storedSites],
);
const siteOnMap = useSelector(siteOnMapSelector);
const { map } = useLeaflet();
const [visibleSites, setVisibleSites] = useState(sitesList);

const setCenter = useCallback(
(inputMap: L.Map, latLng: [number, number], zoom: number) => {
Expand All @@ -50,7 +54,31 @@ export const SiteMarkers = ({ collection }: SiteMarkersProps) => {
},
[],
);
// zoom in and center on site marker when it's clicked

const filterSitesByViewport = useCallback(() => {
if (!map) return;

const bounds = map.getBounds();
const filtered = sitesList.filter((site: Site) => {
if (!site.polygon || site.polygon.type !== 'Point') return false;
const [lng, lat] = site.polygon.coordinates;
return bounds.contains([lat, lng]);
});
setVisibleSites(filtered);
}, [map, sitesList]);

useEffect(() => {
if (!map) return undefined;

filterSitesByViewport();
map.on('moveend', filterSitesByViewport);

return () => {
map.off('moveend', filterSitesByViewport);
return undefined;
};
}, [map, filterSitesByViewport]);

useEffect(() => {
if (map && siteOnMap?.polygon.type === 'Point') {
const [lng, lat] = siteOnMap.polygon.coordinates;
Expand All @@ -64,7 +92,7 @@ export const SiteMarkers = ({ collection }: SiteMarkersProps) => {
iconCreateFunction={clusterIcon}
disableClusteringAtZoom={1}
>
{sitesList.map((site: Site) => (
{visibleSites.map((site: Site) => (
<SiteMarker key={site.id} site={site} setCenter={setCenter} />
))}
</MarkerClusterGroup>
Expand Down
1 change: 1 addition & 0 deletions packages/website/src/routes/HomeMap/Map/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ const HomepageMap = ({
id="sites-map"
ref={ref}
preferCanvas
renderer={L.canvas()}
maxBoundsViscosity={1.0}
className={classes.map}
center={initialCenter}
Expand Down
Loading

0 comments on commit 2d8ecc8

Please sign in to comment.