Skip to content

Commit e622822

Browse files
committed
Fix cluster selected effect
1 parent 7b4958c commit e622822

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/components/WorldMap.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,13 @@ const WorldMap = ({ orchestrators, selectedKPI }) => {
214214
};
215215

216216
// Custom cluster icon
217-
const createClusterCustomIcon = (cluster) => {
217+
const createClusterCustomIcon = (cluster, selectedData) => {
218218
const childCount = cluster.getChildCount();
219219
const childMarkers = cluster.getAllChildMarkers();
220220

221+
const isSelected = Array.isArray(selectedData) && selectedData.length == childMarkers.length &&
222+
selectedData.every((marker, index) => marker.options.options.instanceObj.id == childMarkers[index].options.options.instanceObj.id);
223+
221224
const avgScore = (
222225
childMarkers
223226
.map((marker) => {
@@ -230,7 +233,11 @@ const WorldMap = ({ orchestrators, selectedKPI }) => {
230233
).toFixed(2);
231234

232235
let size = Math.min(36 + childCount * 2, 96);
233-
const color = getPinColor(avgScore);
236+
let color = getPinColor(avgScore);
237+
if (isSelected){
238+
size += 12;
239+
color = "var(--magenta)";
240+
}
234241

235242
return L.divIcon({
236243
className: "dummy",
@@ -280,11 +287,11 @@ const WorldMap = ({ orchestrators, selectedKPI }) => {
280287

281288
{/* Clustered Markers */}
282289
<MarkerClusterGroup
283-
key={"map-" + selectedKPI + searchTerm}
290+
key={"map-" + selectedKPI + searchTerm + (Array.isArray(selectedData) ? (selectedData.length + selectedData[0].options.options.instanceObj.id) : (selectedData ? selectedData.id : ""))}
284291
showCoverageOnHover={false}
285292
spiderfyOnMaxZoom={false}
286293
zoomToBoundsOnClick={false}
287-
iconCreateFunction={(cluster) => createClusterCustomIcon(cluster)}
294+
iconCreateFunction={(cluster) => createClusterCustomIcon(cluster, selectedData)}
288295
eventHandlers={{
289296
clusterclick: (e) => {
290297
const cluster = e.layer;
@@ -294,7 +301,7 @@ const WorldMap = ({ orchestrators, selectedKPI }) => {
294301
return;
295302
}
296303
const notChanged = Array.isArray(selectedData) && selectedData.length == markers.length &&
297-
selectedData.every((marker, index) => marker._leaflet_id === markers[index]._leaflet_id) || false;
304+
selectedData.every((marker, index) => marker.options.options.instanceObj.id == markers[index].options.options.instanceObj.id);
298305
if (!notChanged) {
299306
setSelectedData(markers);
300307
} else {

0 commit comments

Comments
 (0)