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

leaflet.featuregroup.subgroup

v1.0.2

Published

Creates a Leaflet Feature Group that adds its child layers into a parent group when added to a map

Downloads

19,359

Readme

Leaflet.FeatureGroup.SubGroup

Creates a Leaflet Feature Group that adds its child layers into a parent group when added to a map (e.g. through L.Control.Layers).

Typical usage is to dynamically add/remove groups of markers from Marker Cluster.

Leaflet.markercluster plugin provides beautiful animated Marker Clustering functionality.

Leaflet is the leading open-source JavaScript library for mobile-friendly interactive maps.

GitHub releases npm

Size: 2 kB minified, < 1 kB gzipped.

Requirements

Requires Leaflet 1.0.0

For Leaflet 0.7 use the v0.1.2 release or the leaflet-0.7 branch

Optional: Leaflet.markercluster plugin

Demos

Usage instructions

Quick Guide

HTML:

<!-- after Leaflet script -->
<script src="leaflet.featuregroup.subgroup.js"></script>

JavaScript:

var map = L.map("map"),
    parentGroup = L.markerClusterGroup(options), // Could be any other Layer Group type.

    // This is where the magic happens!
    mySubGroup = L.featureGroup.subGroup(parentGroup, arrayOfMarkers);

parentGroup.addTo(map);
mySubGroup.addTo(map);

Now adding the sub-group to the map adds clustered markers!

It should virtually be compatible with any LayerGroup plugin, not only MarkerCluster.

Installing the sub-plugin

Local copy

  1. Download the "leaflet.featuregroup.subgroup.js" file from the v1.0.2 release.
  2. Place the file alongside your page.
  3. Add the script tag (see Quick Guide > HTML) to your page after Leaflet script.

CDN

You can alternatively use the free unpkg CDN service, but keep in mind that it "is a free, best-effort service and cannot provide any uptime or support guarantees".

<!-- After Leaflet script -->
<script src="https://unpkg.com/[email protected]/dist/leaflet.featuregroup.subgroup.js"></script>

Creation

Simply use the L.featureGroup.subGroup factory instead of your regular L.featureGroup or L.layerGroup:

var mySubGroup = L.featureGroup.subGroup(parentGroup);

mySubGroup.addTo(map);

Do not forget to add the parent group to your map.

API Reference

Creation

| Factory | Description | | :------ | :---------- | | L.featureGroup.subGroup( <ILayer> parentGroup?, <ILayer[]> layersArray? ) | Creates a sub-group with events, optionally given a parent group and an initial array of child layers. |

Methods

| Method | Returns | Description | | :------ | :------- | :---------- | | setParentGroup( <ILayer> parentGroup ) | this | Changes the parent group into which child markers are added to / removed from. | | setParentGroupSafe( <ILayer> parentGroup ) | this | Removes the current sub-group from map before changing the parent group. Re-adds the sub-group to map if it was before changing. | | getParentGroup() | <ILayer> | Returns the current parent group. |

SubGroup does not provide any extra option or event beyond what L.LayerGroup and L.FeatureGroup already provide.

Limitations

If you change the parent group while the sub-group and/or its child markers are still on map, unexpected behaviour of the previous and/or new parent groups can happen.

Make sure the sub-group and its child layers are removed from map before changing the parent group, or use the setParentGroupSafe method instead.

License

license

Leaflet.FeatureGroup.SubGroup is distributed under the BSD 2-clause "Simplified" License, like Leaflet.