Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

Add click event to map for filtering by country or subdivision

Bill Yang9d6ef2368cff
diff --git a/client/src/app/[site]/main/components/sections/Map.tsx b/client/src/app/[site]/main/components/sections/Map.tsx
index 409ca369d..8ba122d4c 100644
--- a/client/src/app/[site]/main/components/sections/Map.tsx
+++ b/client/src/app/[site]/main/components/sections/Map.tsx
@@ -15,6 +15,7 @@ import { Layer } from "leaflet";
import { Feature, GeoJsonObject } from "geojson";
import "leaflet/dist/leaflet.css";
import { useSingleCol } from "@/api/analytics/useSingleCol";
+import { addFilter, FilterParameter } from "../../../../../lib/store";
const countriesGeoUrl = "/countries.json";
const subdivisionsGeoUrl = "/subdivisions.json";
@@ -155,6 +156,23 @@ export function Map() {
});
setTooltipContent(null);
},
+ click: () => {
+ const isCountryView = mapView === "countries";
+ const code = isCountryView
+ ? feature.properties?.["ISO_A2"]
+ : feature.properties?.["iso_3166_2"];
+
+ // Set filter based on the current map view
+ const filterParameter: FilterParameter = isCountryView
+ ? "country"
+ : "iso_3166_2";
+
+ addFilter({
+ parameter: filterParameter,
+ value: [code],
+ type: "equals",
+ });
+ },
});
};