feat(follow-location): map wip

This commit is contained in:
devthejo 2025-05-31 11:59:12 +02:00
parent 30aeb2a0e4
commit ce11db9863
4 changed files with 64 additions and 17 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

View file

@ -8,6 +8,7 @@ import markerGreen from "~/assets/img/marker-green.png";
import markerRedDisabled from "~/assets/img/marker-red-disabled.png"; import markerRedDisabled from "~/assets/img/marker-red-disabled.png";
import markerYellowDisabled from "~/assets/img/marker-yellow-disabled.png"; import markerYellowDisabled from "~/assets/img/marker-yellow-disabled.png";
import markerGreenDisabled from "~/assets/img/marker-green-disabled.png"; import markerGreenDisabled from "~/assets/img/marker-green-disabled.png";
import markerOrigin from "~/assets/img/marker-origin.png";
const images = { const images = {
red: markerRed, red: markerRed,
@ -16,6 +17,7 @@ const images = {
redDisabled: markerRedDisabled, redDisabled: markerRedDisabled,
yellowDisabled: markerYellowDisabled, yellowDisabled: markerYellowDisabled,
greenDisabled: markerGreenDisabled, greenDisabled: markerGreenDisabled,
origin: markerOrigin,
}; };
export default function FeatureImages() { export default function FeatureImages() {

View file

@ -12,6 +12,11 @@ const hitbox = {
height: HITBOX_SIZE, height: HITBOX_SIZE,
}; };
const iconStyle = {
iconImage: ["get", "icon"],
iconSize: 0.5,
};
const useStyles = createStyles(({ theme: { colors } }) => ({ const useStyles = createStyles(({ theme: { colors } }) => ({
clusterCount: { clusterCount: {
textField: "{point_count_abbreviated}", textField: "{point_count_abbreviated}",
@ -46,6 +51,13 @@ export default function ShapePoints({ shape, children, ...shapeSourceProps }) {
<AlertSymbolLayer level="yellow" isDisabled /> <AlertSymbolLayer level="yellow" isDisabled />
<AlertSymbolLayer level="green" isDisabled /> <AlertSymbolLayer level="green" isDisabled />
<Maplibre.SymbolLayer
filter={["==", ["get", "icon"], "origin"]}
key="points-origin"
id="points-origin"
style={iconStyle}
/>
{children} {children}
</Maplibre.ShapeSource> </Maplibre.ShapeSource>
); );

View file

@ -3,6 +3,7 @@ import { getDistance } from "geolib";
import Supercluster from "supercluster"; import Supercluster from "supercluster";
import useShallowMemo from "~/hooks/useShallowMemo"; import useShallowMemo from "~/hooks/useShallowMemo";
import useShallowEffect from "~/hooks/useShallowEffect"; import useShallowEffect from "~/hooks/useShallowEffect";
import { deepEqual } from "fast-equals";
export default function useFeatures({ export default function useFeatures({
clusterFeature, clusterFeature,
@ -38,10 +39,8 @@ export default function useFeatures({
return computedList; return computedList;
}, [alertingList, userCoords, hasUserCoords]); }, [alertingList, userCoords, hasUserCoords]);
const featureCollection = useShallowMemo( const featureCollection = useShallowMemo(() => {
() => ({ const features = list.map((row) => {
type: "FeatureCollection",
features: list.map((row) => {
const { alert } = row; const { alert } = row;
const { level, state } = alert; const { level, state } = alert;
const [longitude, latitude] = alert.location.coordinates; const [longitude, latitude] = alert.location.coordinates;
@ -63,10 +62,44 @@ export default function useFeatures({
coordinates, coordinates,
}, },
}; };
}), });
}),
[list], // Add initial location marker if locations are different
); list.forEach((row) => {
const { alert } = row;
if (
alert.initialLocation &&
alert.location &&
!deepEqual(alert.initialLocation, alert.location)
) {
const [longitude, latitude] = alert.initialLocation.coordinates;
const coordinates = [longitude, latitude];
const id = `alert:${alert.id}:initial`;
features.push({
type: "Feature",
id,
properties: {
id,
icon: "origin",
level: alert.level,
alert,
coordinates,
isInitialLocation: true,
},
geometry: {
type: "Point",
coordinates,
},
});
}
});
return {
type: "FeatureCollection",
features,
};
}, [list]);
const superCluster = useShallowMemo(() => { const superCluster = useShallowMemo(() => {
const cluster = new Supercluster({ radius: 40, maxZoom: 16 }); const cluster = new Supercluster({ radius: 40, maxZoom: 16 });