npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-leaflet-cluster-layer

v0.0.3

Published

A custom layer for react-leaflet that makes plotting and clustering react components simple

Downloads

103

Readme

react-leaflet-cluster-layer

react-leaflet-cluster-layer provides a simple <ClusterLayer /> component for plotting React components as markers and clusters in a react-leaflet map.

A screenshot of a cluster on a leaflet map

Usage

import React from 'react';
import { render } from 'react-dom';
import { Map, Marker, Popup, TileLayer } from 'react-leaflet';
import ClusterLayer from 'react-leaflet-cluster-layer';

const position = { lng: -122.673447, lat: 45.522558 };
const markers = [
  {
    position: { lng: -122.673447, lat: 45.5225581 },
    text: 'Voodoo Doughnut',
  },
  {
    position: { lng: -122.6781446, lat: 45.5225512 },
    text: 'Bailey\'s Taproom',
  },
  {
    position: { lng: -122.67535700000002, lat: 45.5192743 },
    text: 'Barista'
  }
];

class ExampleClusterComponent extends React.Component {

  render() {
    const style = {
      border: 'solid 2px darkgrey',
      borderRadius: '8px',
      backgroundColor: 'white',
      padding: '1em',
      textAlign: 'center'
    };
    const cluster = this.props.cluster;

    if (cluster.markers.length == 1) {
      return (
        <div style={style} >{cluster.markers[0].text}</div>
      );
    }

    return (
      <div style={style}>{cluster.markers.length} items</div>
    );
  }

}

const map = (
  <Map center={position} zoom={13}>
    <ClusterLayer
      markers={markers}
      clusterComponent={ExampleClusterComponent} />
    <TileLayer
      url='http://{s}.tile.osm.org/{z}/{x}/{y}.png'
      attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
    />
  </Map>
);

render(map, document.getElementById('app'));

API

The ClusterLayer component takes the following props:

  • markers: an array of objects that expose the properties defined in the Marker type
  • clusterComponent: (required) the React component to be rendered for each marker and cluster, this component will receive the following props
    • cluster: a Cluster object, as defined by the Cluster Flow type
    • style: a style object for positioning
    • map: the Leaflet map object from the react-leaflet MapLayer
    • ...propsForClusters: the component will also receive the properties of propsForClusters as props
  • propsForClusters: props to pass on to marker and cluster components
  • gridSize: optional prop to control how bounds of clusters expand while being generated (default: 60)
  • minClusterSize: optional prop to enforce a minimum cluster size (default: 2)

Example

To try the example:

  1. Clone this repository
  2. run npm install in the root of your cloned repository
  3. run npm run example
  4. Visit localhost:8000

Contributing

See CONTRIBUTING.md

License

react-leaflet-cluster-layer is MIT licensed.

See LICENSE.md for details.