Skip to content

Commit

Permalink
feat: add marker clustering setting (#13)
Browse files Browse the repository at this point in the history
closes #10
  • Loading branch information
mfrederic authored Apr 23, 2024
2 parents e1a89be + 7d4e9db commit 740fd67
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 9 deletions.
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "realt-properties-map-frontend",
"version": "1.3.1",
"version": "1.4.0",
"license": "Apache-2.0",
"scripts": {
"start": "PORT=3010 react-scripts start",
Expand Down
9 changes: 5 additions & 4 deletions frontend/src/components/Map/MapMarkers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export function MapMarkers({
displayRmm,
differentiateOwned,
markerOpacity,
markerClustering,
} = useAppSelector((state) => state.mapOptions);
const selectedUrlParam = useAppSelector(selectedProperty);

Expand Down Expand Up @@ -166,9 +167,9 @@ export function MapMarkers({
map.removeEventListener('moveend');
}

function getCleanMarkerCluster() {
function getCleanMarkerCluster(clustering: number = 14) {
return markerClusterGroup({
disableClusteringAtZoom: 14,
disableClusteringAtZoom: clustering,
showCoverageOnHover: false,
chunkedLoading: true,
maxClusterRadius: 100,
Expand All @@ -179,7 +180,7 @@ export function MapMarkers({

useEffect(() => {
clearMap();
markerCluster = getCleanMarkerCluster();
markerCluster = getCleanMarkerCluster(markerClustering);

filterProperties(properties, displayAll, displayGnosis, displayRmm, selectedUrlParam)
.forEach((property) => {
Expand Down Expand Up @@ -213,7 +214,7 @@ export function MapMarkers({
clearMap();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [properties, displayAll, displayGnosis, displayRmm, differentiateOwned, markerOpacity]);
}, [properties, displayAll, displayGnosis, displayRmm, differentiateOwned, markerOpacity, markerClustering]);

return null;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Grid, Slider } from "@mantine/core";
import OpacityIcon from '@mui/icons-material/Opacity';
import { useAppDispatch, useAppSelector } from "../../../../hooks/useInitStore";
import { setMarkerClustering } from "../../../../store/mapOptions/mapOptionsReducer";
import { selectMarkerClustering } from "../../../../store/mapOptions/mapOptionsSelector";
import { useTranslation } from "react-i18next";

export function MapMarkerClustering() {
const { t } = useTranslation('common');
const dispatch = useAppDispatch();
const markerClustering = useAppSelector(selectMarkerClustering);

function onClusteringChange(value: number) {
dispatch(setMarkerClustering(value));
}

return (
<Grid className="mt-2">
<Grid.Col span={12}>
<h3 className="text-base font-semibold leading-7">
<OpacityIcon className="inline-block mr-2" />
{ t('settings.markersClustering') }
</h3>
</Grid.Col>
<Grid.Col span={12} className="mt-4">
<Slider
label={(value) => `zoom: ${value}`}
step={1}
min={10}
max={18}
defaultValue={markerClustering}
thumbLabel={t('settings.mapMarkersClustering')}
onChangeEnd={onClusteringChange}
marks={[
{ value: 10, label: '10' },
{ value: 14, label: `14 (${t('extra.default')})` },
{ value: 18, label: '18' },
]}/>
</Grid.Col>
</Grid>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { setDifferentiateOwned, setDisplayAll, setDisplayGnosis, setDisplayRmm }
import { SettingsPanelSection } from "../../SettingsPanelSection";
import { selectWalletAddresses } from "../../../../store/settings/settingsSelector";
import { MapMarkerOpacity } from "./MapMarkerOpacity";
import { MapMarkerClustering } from "./MapMarkerClustering";

export function MapOptions() {
const { t } = useTranslation('common', { keyPrefix: 'mapOptions' });
Expand Down Expand Up @@ -65,6 +66,7 @@ export function MapOptions() {
disabled={walletAddresses.length === 0}
onChange={(e) => onDifferentiateOwned(e)} />
<MapMarkerOpacity />
<MapMarkerClustering />
</SettingsPanelSection>
)
}
5 changes: 4 additions & 1 deletion frontend/src/i18next/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@
"french": "French",
"english": "English",
"markersOpacity": "Markers Opacity",
"markersClustering": "Markers Clustering",
"mapMarkersOpacity": "Map Markers Opacity",
"mapClustersOpacity": "Map Clusters Opacity",
"generalOptions": {
"title": "General Options",
"displayStartTooltip": "Display start tooltip"
Expand Down Expand Up @@ -104,6 +106,7 @@
"madeBy": "Made with ❤️ by",
"baseOn": "Based on the work of",
"startTooltip": "Add your wallets to get started",
"reportIssue": "Report an issue"
"reportIssue": "Report an issue",
"default": "Default"
}
}
5 changes: 4 additions & 1 deletion frontend/src/i18next/locales/fr/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@
"french": "Français",
"english": "Anglais",
"markersOpacity": "Opacité des marqueurs",
"markersClustering": "Regroupement des marqueurs",
"mapMarkersOpacity": "Opacité des marqueurs sur la carte",
"mapMarkersClustering": "Regroupement des marqueurs sur la carte",
"generalOptions": {
"title": "Options Générales",
"displayStartTooltip": "Afficher l'info-bulle de démarrage"
Expand Down Expand Up @@ -104,6 +106,7 @@
"madeBy": "Fait avec ❤️ par",
"baseOn": "Basé sur le travail de",
"startTooltip": "Ajouter vos portefeuilles pour commencer",
"reportIssue": "Signaler un problème"
"reportIssue": "Signaler un problème",
"default": "Défaut"
}
}
17 changes: 16 additions & 1 deletion frontend/src/store/mapOptions/mapOptionsReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface MapOptionsState {
displayRmm: boolean;
differentiateOwned: boolean;
markerOpacity: number;
markerClustering: number;
}

const initialState: MapOptionsState = getItem<MapOptionsState>(LOCAL_STORAGE_NAME, {
Expand All @@ -17,6 +18,7 @@ const initialState: MapOptionsState = getItem<MapOptionsState>(LOCAL_STORAGE_NAM
displayRmm: true,
differentiateOwned: true,
markerOpacity: .8,
markerClustering: 14,
});

export const mapOptionsSlice = createSlice({
Expand All @@ -30,6 +32,7 @@ export const mapOptionsSlice = createSlice({
displayRmm: action.payload.displayRmm,
differentiateOwned: action.payload.differentiateOwned,
markerOpacity: action.payload.markerOpacity,
markerClustering: action.payload.markerClustering,
};
setItem<MapOptionsState>(LOCAL_STORAGE_NAME, newState);
return newState;
Expand All @@ -56,10 +59,22 @@ export const mapOptionsSlice = createSlice({
}
state.markerOpacity = action.payload;
setItem<MapOptionsState>(LOCAL_STORAGE_NAME, state);
},
setMarkerClustering: (state, action: PayloadAction<number>) => {
state.markerClustering = action.payload;
setItem<MapOptionsState>(LOCAL_STORAGE_NAME, state);
}
}
});

export const { setAll, setDisplayAll, setDisplayGnosis, setDisplayRmm, setDifferentiateOwned, setMarkerOpacity } = mapOptionsSlice.actions;
export const {
setAll,
setDisplayAll,
setDisplayGnosis,
setDisplayRmm,
setDifferentiateOwned,
setMarkerOpacity,
setMarkerClustering,
} = mapOptionsSlice.actions;

export default mapOptionsSlice.reducer;
4 changes: 3 additions & 1 deletion frontend/src/store/mapOptions/mapOptionsSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ export const selectMapOptions = (state: RootState) => state.mapOptions;

export const selectMarkerOpacity = (state: RootState) => state.mapOptions.markerOpacity;

export const selectDifferentiateOwned = (state: RootState) => state.mapOptions.differentiateOwned;
export const selectDifferentiateOwned = (state: RootState) => state.mapOptions.differentiateOwned;

export const selectMarkerClustering = (state: RootState) => state.mapOptions.markerClustering;

0 comments on commit 740fd67

Please sign in to comment.