From 9532a333bef466cfed443ca6f2360d60cd6a5aa7 Mon Sep 17 00:00:00 2001
From: muerwre <gotham48@gmail.com>
Date: Wed, 27 Feb 2019 09:42:11 +0700
Subject: [PATCH] cluster as last marker in it

---
 src/utils/arrow.ts | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/utils/arrow.ts b/src/utils/arrow.ts
index ce050f6..7d7fa5a 100644
--- a/src/utils/arrow.ts
+++ b/src/utils/arrow.ts
@@ -1,5 +1,4 @@
 import { divIcon, LatLngLiteral, Marker, marker, DivIcon } from "leaflet";
-import { dist2 } from "$utils/geom";
 
 export const createArrow = (latlng: LatLngLiteral, angle: number): Marker => marker(latlng, {
   draggable: false,
@@ -21,11 +20,12 @@ export const createArrow = (latlng: LatLngLiteral, angle: number): Marker => mar
 export const arrowClusterIcon = (cluster): DivIcon => {
   const markers = cluster.getAllChildMarkers();
 
-  const nearest = markers.sort((a, b) => (
-    dist2(a.getLatLng(), cluster.getLatLng()) - dist2(b.getLatLng(), cluster.getLatLng())
-  ));
+  // search for nearest marker to cluster (slow)
+  // const nearest = markers.sort((a, b) => (
+  //   dist2(a.getLatLng(), cluster.getLatLng()) - dist2(b.getLatLng(), cluster.getLatLng())
+  // ));
 
-  cluster.setLatLng(nearest[0].getLatLng());
-
-  return nearest[0].options.icon;
+  // faster way
+  cluster.setLatLng(markers[markers.length - 1].getLatLng());
+  return markers[markers.length - 1].options.icon;
 };