cluster as last marker in it

This commit is contained in:
muerwre 2019-02-27 09:42:11 +07:00
parent 64b057c708
commit 9532a333be

View file

@ -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;
};