Remove shadow and bounce contraction for cleaner look

This commit is contained in:
Timothy Armes
2023-07-19 15:58:56 +02:00
parent e8dd1c935a
commit 4fe1318893
3 changed files with 65 additions and 15 deletions
+11 -9
View File
@@ -30,7 +30,7 @@ import { generatePieSVG } from "@/lib/pie";
import { TimeControlColours } from "@/app/constants"; import { TimeControlColours } from "@/app/constants";
import Legend from "./Legend"; import Legend from "./Legend";
import { TournamentMarker } from "./TournamentMarker"; import { TournamentMarker, TournamentMarkerRef } from "./TournamentMarker";
import TimeControlFilters from "./TimeControlFilters"; import TimeControlFilters from "./TimeControlFilters";
// Declare a class type that adds in methods etc. defined by leaflet.smooth_marker_bouncing // Declare a class type that adds in methods etc. defined by leaflet.smooth_marker_bouncing
@@ -100,7 +100,7 @@ export default function TournamentMap() {
debouncedHoveredListTournamentIdAtom, debouncedHoveredListTournamentIdAtom,
); );
const markerRefs = useRef<Record<string, L.Marker<any> | null>>({}); const markerRefs = useRef<Record<string, TournamentMarkerRef>>({});
const clusterRef = useRef<L.MarkerClusterGroup | null>(null); const clusterRef = useRef<L.MarkerClusterGroup | null>(null);
const expandedClusterMarkerRef = useRef<L.MarkerCluster | null>(null); const expandedClusterMarkerRef = useRef<L.MarkerCluster | null>(null);
@@ -134,7 +134,9 @@ export default function TournamentMap() {
const markerRef = markerRefs.current[tournament.groupId]; const markerRef = markerRefs.current[tournament.groupId];
if (markerRef) { if (markerRef) {
if (clusterRef.current) { if (clusterRef.current) {
const visibleMarker = clusterRef.current.getVisibleParent(markerRef); const visibleMarker = clusterRef.current.getVisibleParent(
markerRef.getMarker(),
);
if (!visibleMarker) return; if (!visibleMarker) return;
// @ts-ignore // @ts-ignore
@@ -163,7 +165,7 @@ export default function TournamentMap() {
if (!marker.isBouncing()) { if (!marker.isBouncing()) {
stopBouncingMarkers(); stopBouncingMarkers();
marker.bounce(); markerRef.bounce();
} }
} }
@@ -186,11 +188,9 @@ export default function TournamentMap() {
if (!tournament) return; if (!tournament) return;
expandedClusterMarkerRef.current = e.cluster; expandedClusterMarkerRef.current = e.cluster;
const markerRef = markerRefs.current[ const markerRef = markerRefs.current[tournament.groupId];
tournament.groupId
] as BouncingMarker;
if (markerRef && e.markers.includes(markerRef)) { if (markerRef && e.markers.includes(markerRef.getMarker())) {
stopBouncingMarkers(); stopBouncingMarkers();
markerRef.bounce(); markerRef.bounce();
} }
@@ -284,7 +284,9 @@ export default function TournamentMap() {
return ( return (
<TournamentMarker <TournamentMarker
ref={(ref) => (markerRefs.current[groupId] = ref)} ref={(ref) => {
markerRefs.current[groupId] = ref!;
}}
key={groupId} key={groupId}
tournamentGroup={tournamentGroup} tournamentGroup={tournamentGroup}
colour={colours[timeControl]} colour={colours[timeControl]}
+25 -6
View File
@@ -1,7 +1,7 @@
"use client"; "use client";
import { forwardRef, useMemo, useRef } from "react"; import { forwardRef, useMemo, useImperativeHandle, useRef } from "react";
import { TimeControl, Tournament } from "@/types"; import { Tournament } from "@/types";
import L from "leaflet"; import L from "leaflet";
import { Marker, Popup, MarkerProps } from "react-leaflet"; import { Marker, Popup, MarkerProps } from "react-leaflet";
import { useTranslations } from "next-intl"; import { useTranslations } from "next-intl";
@@ -9,18 +9,38 @@ import { useSetAtom } from "jotai";
import { FaTrophy } from "react-icons/fa"; import { FaTrophy } from "react-icons/fa";
import { last } from "lodash"; import { last } from "lodash";
import type { BouncingMarker } from "@/leafletTypes";
import { debouncedHoveredMapTournamentGroupIdAtom } from "@/app/atoms"; import { debouncedHoveredMapTournamentGroupIdAtom } from "@/app/atoms";
export type TournamentMarkerRef = {
getMarker: () => L.Marker<any>;
bounce: () => void;
};
type TournamentMarkerProps = { type TournamentMarkerProps = {
tournamentGroup: Tournament[]; tournamentGroup: Tournament[];
colour: string; colour: string;
} & Omit<MarkerProps, "position">; } & Omit<MarkerProps, "position">;
export const TournamentMarker = forwardRef< export const TournamentMarker = forwardRef<
L.Marker<any> | null, TournamentMarkerRef,
TournamentMarkerProps TournamentMarkerProps
>(({ tournamentGroup, colour, ...markerProps }, ref) => { >(({ tournamentGroup, colour, ...markerProps }, ref) => {
const t = useTranslations("Tournaments"); const t = useTranslations("Tournaments");
const markerRef = useRef<L.Marker<any> | null>(null);
useImperativeHandle(
ref,
() => ({
getMarker: () => markerRef.current!,
bounce: () => {
const bouncingMarker = markerRef.current as BouncingMarker;
bouncingMarker.setBouncingOptions({ contractHeight: 0 });
bouncingMarker.bounce();
},
}),
[],
);
const { date, latLng, groupId, timeControl } = tournamentGroup[0]; const { date, latLng, groupId, timeControl } = tournamentGroup[0];
@@ -32,11 +52,10 @@ export const TournamentMarker = forwardRef<
() => () =>
new L.Icon({ new L.Icon({
iconUrl: `/images/leaflet/marker-icon-2x-${colour}.png`, iconUrl: `/images/leaflet/marker-icon-2x-${colour}.png`,
shadowUrl: "/images/leaflet/marker-shadow.png",
iconSize: [25, 41], iconSize: [25, 41],
iconAnchor: [12, 41], iconAnchor: [12, 41],
popupAnchor: [1, -34], popupAnchor: [1, -34],
shadowSize: [41, 41],
timeControl, timeControl,
}), }),
[colour, timeControl], [colour, timeControl],
@@ -47,7 +66,7 @@ export const TournamentMarker = forwardRef<
return ( return (
<Marker <Marker
ref={ref} ref={markerRef}
position={latLng} position={latLng}
icon={iconOptions} icon={iconOptions}
eventHandlers={{ eventHandlers={{
+29
View File
@@ -0,0 +1,29 @@
import { Marker } from "leaflet";
declare class BouncingOptions {
bounceHeight: number;
contractHeight: number;
bounceSpeed: number;
contractSpeed: number;
shadowAngle: number;
elastic: number;
exclusive: number;
constructor(options: Partial<BouncingOptions>);
}
// Declare a class type that adds in methods etc. defined by leaflet.smooth_marker_bouncing
// to keep Typescript happy
export declare class BouncingMarker extends Marker {
isBouncing(): boolean;
bounce(): void;
stopBouncing(): void;
getBouncingMarkers(): Marker[];
setBouncingOptions(options: BouncingOptions | Partial<BouncingOptions>): void;
stopAllBouncingMarkers(): void;
_icon: HTMLElement;
_bouncingMotion?: {
bouncingAnimationPlaying: boolean;
};
}