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 🙏

© 2026 – Pkg Stats / Ryan Hefner

leaflet.styledlayercontrol

v1.0.0

Published

A Leaflet plugin that implements the management and control of layers by organization into categories or groups. The StyledLayerControl class extends the original L.control.layers control. The plugin uses HTML5 and CSS3 to style the presentation in a mode

Readme

Leaflet.StyledLayerControl

What is Leaflet.StyledLayerControl?

A Leaflet plugin that implements the management and control of layers by organization into categories or groups. The StyledLayerControl class extends the original L.control.layers control. The plugin uses HTML5 and CSS3 to style the presentation in a modern way. The initial ideas were based in the plugin: Leaflet.Groupedlayercontrol

preview

Tested with Leaflet 0.7.3

Main features

  • Organization of the layers into groups or categories. The layers can be an overlay or basemap
  • Groups may appear initially expanded or not
  • Groups can be opened exclusively
  • A layer can be defined as removable
  • The main container control behaves responsively, automatically adjusting the vertical resizing the map and the screen

Live Demos

How to use?

1 - Create the reference to Leaflet

	<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />
	<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>

2 - Insert references to styledLayerControl.css and styledLayerControl.js

	<link rel="stylesheet" href="../css/styledLayerControl.css" />
	<script src="../src/styledLayerControl.js"></script>

3 - Define your layers (base maps and overlays)


	// Google layers
	var g_roadmap   = new L.Google('ROADMAP');
	var g_satellite = new L.Google('SATELLITE');
	var g_terrain   = new L.Google('TERRAIN');
	
	// OSM layers
	var osmUrl='http://{s}.tile.osm.org/{z}/{x}/{y}.png';
	var osmAttrib='Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors';
	var osm = new L.TileLayer(osmUrl, {attribution: osmAttrib});
	
	// ... more Base Maps
	
	// Sao Paulo Soybeans Plant
	var soybeans_sp = new L.LayerGroup();
	L.marker([-22, -49.80]).addTo(soybeans_sp),
	L.marker([-23, -49.10]).addTo(soybeans_sp),
	L.marker([-21, -49.50]).addTo(soybeans_sp);
	
	// Rio de Janeiro Corn Plant
	var corn_rj = new L.LayerGroup();
	L.marker([-22, -43.20]).addTo(corn_rj),
	L.marker([-23, -43.50]).addTo(corn_rj);
	
	// ... more Overlays

4 - Create the Leaflet Map Object and add the layer that will be default basemap

	var map = L.map('map', {
		center: [-16, -54],
		zoom: 4
	});
	
	map.addLayer(g_roadmap);

5 - Define structure of groups and layers of basemap

	var baseMaps = [
					{ 
						groupName : "Google Base Maps",
						expanded : true,
						layers    : {
							"Satellite" :  g_satellite,
							"Road Map"  :  g_roadmap,
							"Terreno"   :  g_terrain
						}
					}, {
						groupName : "OSM Base Maps",
						layers    : {
							"OpenStreetMaps" : osm
						}
					}, {
						groupName : "Bing Base Maps",
						layers    : {
							"Satellite" : bing1,
							"Road"      : bing2
						}
					}							
	];	

5 - Define structure of groups and layers of overlays

	var overlays = [
					 {
						groupName : "Sao Paulo",
						expanded  : true,
						layers    : { 
							"Soybeans Plant" : soybeans_sp,
							"Corn Plant" 	 : corn_sp
						}	
					 }, {
						groupName : "Rio de Janeiro",
						expanded  : true,
						layers    : { 
							"Bean Plant"     : bean_rj,
							"Corn Plant" 	 : corn_rj,
							"Rice Plant"	 : rice_rj		
						}	
					 }, {
						groupName : "Belo Horizonte",
						layers    : { 
							"Sugar Cane Plant"	: sugar_bh,
							"Corn Plant" 	 	: corn_bh		
						}	
					 }							 
	];

6 - Declare which layers can be deleted and visible (create the removable property with true in the options StyledLayerControl that can be created in the layer object). Each layer declared as removable = true will show an icon to delete the user to remove the layer

    soybeans_sp.StyledLayerControl = {
		removable : true,
		visible : false
	}
	// ... more layers

7 - Define the options for StyledLayerControl

  • container_width - define the main container width - the default is automatic width

  • container_maxHeight - define the max height to the main container - the default is automatic depending of map and screen height

  • group_maxHeight - define the max height space of group container - the default is 100px

  • exclusive - define that the opened group is exclusive

  • All the properties are optional

  • You can also include all properties available under "Options" of control L.control.layers in the same list

	var options = {
		container_width 	: "300px",
		container_maxHeight : "350px", 
		group_maxHeight     : "80px",
		exclusive       	: false
	};

8 - Create the StyledLayerControl

	var control = L.Control.styledLayerControl(baseMaps, overlays, options);
	map.addControl(control);

How to add and remove layers and groups dynamically ?

  • To add a new base layer dynamically, simply use addBaseLayer and declare that the group layer will belong. Also note that to add a new group, simply specify a group name that does not exist yet, and a new group will be created.
	control.addBaseLayer( bing1, "Bing Satellite", {groupName : "Bing Maps", expanded: true} );
	control.addBaseLayer( bing2, "Bing Road", {groupName : "Bing Maps"} );
  • To add a new overlay layer dynamically, simply declare the group that de layer will belong.
	control.addOverlay( corn_bh, "Corn Plant", {groupName : "Belo Horizonte"} );
  • To remove a layer dynamically, specify the instance variable of the layer using the method removeLayer. (the method ignore the removable property of layers )
	control.removeLayer( corn_sp );
  • To remove a group, specify the name of the group in the removeGroup method. By doing so all layers belonging to the group will also be excluded
	control.removeGroup( "Rio de Janeiro");

How to select and unSelect layers dynamically ?

  • To force select a layer dynamically, simply use selectLayer function like this :
    control.selectLayer( corn_sp );
  • So.. to un-select the layer :
    control.unSelectLayer( corn_sp );

How to select and unSelect group layers dynamically ?

  • To force select all layer of a group, use like this :
    control.selectGroup( "Rio de Janeiro" );
  • So.. to un-select the all layer of group :
    control.unSelectGroup( "Rio de Janeiro" );

License

This work is licensed under a Creative Commons Attribution 3.0 Unported License.