0.1.10 • Published 1 year ago

leaflet-markercluster-utils v0.1.10

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Introduction

Leaflet MarkerCluster Utils is a lib of some functions to help work with leaflet.markercluster. This lib is built using typescript to provide better type support.

Quick Start

Install

pnpm add leaflet-markercluster-utils

Usage

import L from 'leaflet';
import { getClusterAtCurrentZoom } from 'leaflet-markercluster-utils';

import 'leaflet.markercluster';

import 'leaflet/dist/leaflet.css';
import 'leaflet.markercluster/dist/MarkerCluster.css';
import 'leaflet.markercluster/dist/MarkerCluster.Default.css';

const map = L.map('map', {
  crs: L.CRS.Simple,
  maxZoom: 3,
}).setView([270.5, 400], 0);

const overlay = L.imageOverlay('Sample_Floorplan.jpeg', [
  [0, 0],
  [541, 800],
]);

const cluster = L.markerClusterGroup({
  showCoverageOnHover: false,
  zoomToBoundsOnClick: false,
  spiderfyOnEveryZoom: true,
});

let someMarker: Marker;

for (let index = 0; index < 1000; index++) {
  const randomLat = Math.random() * 541;
  const randomLng = Math.random() * 800;

  const marker = L.marker([randomLat, randomLng], {
    icon: L.icon({
      iconUrl: 'Marker.png',
      iconSize: [40, 40],
    }),
  });

  if (index === 0) {
    someMarker = marker;
  }

  cluster.addLayer(marker);
}

map.addLayer(cluster);
map.addLayer(overlay);

const clusterOfMarker = getClusterAtCurrentZoom(map.getZoom(), someMarker);
openCluster(cluster, clusterOfMarker);

You can clone this repo and run pnpm dev to see the example.

License

The MIT License.

0.1.10

1 year ago

0.1.9

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago