Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@googlemaps/markerclusterer

Package Overview
Dependencies
Maintainers
2
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@googlemaps/markerclusterer

Creates and manages per-zoom-level clusters for large amounts of markers.

  • 1.0.14
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
168K
decreased by-79.89%
Maintainers
2
Weekly downloads
 
Created

What is @googlemaps/markerclusterer?

@googlemaps/markerclusterer is an npm package that provides functionality for clustering a large number of markers on a Google Map. This helps in improving the performance and user experience by grouping nearby markers into clusters, which can be expanded to show individual markers as the user zooms in.

What are @googlemaps/markerclusterer's main functionalities?

Basic Marker Clustering

This feature allows you to create a basic marker clusterer on a Google Map. You initialize the map, create an array of markers, and then use the MarkerClusterer to cluster these markers.

const map = new google.maps.Map(document.getElementById('map'), {
  center: { lat: -28.024, lng: 140.887 },
  zoom: 4,
});

const markers = locations.map((location, i) => {
  return new google.maps.Marker({
    position: location,
  });
});

new MarkerClusterer({
  markers,
  map
});

Custom Cluster Icons

This feature allows you to customize the icons used for clusters. You can specify a custom renderer function that returns a marker with a custom icon and label.

const map = new google.maps.Map(document.getElementById('map'), {
  center: { lat: -28.024, lng: 140.887 },
  zoom: 4,
});

const markers = locations.map((location, i) => {
  return new google.maps.Marker({
    position: location,
  });
});

new MarkerClusterer({
  markers,
  map,
  renderer: {
    render: ({ count, position }) => {
      return new google.maps.Marker({
        position,
        label: String(count),
        icon: {
          url: 'path/to/custom/icon.png',
          scaledSize: new google.maps.Size(50, 50)
        }
      });
    }
  }
});

Cluster Click Event

This feature allows you to add an event listener for cluster clicks. When a cluster is clicked, you can access the markers within that cluster and perform custom actions.

const map = new google.maps.Map(document.getElementById('map'), {
  center: { lat: -28.024, lng: 140.887 },
  zoom: 4,
});

const markers = locations.map((location, i) => {
  return new google.maps.Marker({
    position: location,
  });
});

const markerCluster = new MarkerClusterer({
  markers,
  map
});

markerCluster.addListener('clusterclick', (cluster) => {
  const markers = cluster.getMarkers();
  console.log('Cluster clicked:', markers);
});

Other packages similar to @googlemaps/markerclusterer

Keywords

FAQs

Package last updated on 22 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc