• Stars
    star
    267
  • Rank 153,621 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 10 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Leaflet Control Layers extended with support groups and icons

Leaflet Panel Layers

npm version

Leaflet Control Layers extended with support groups and icons

Copyright Stefano Cudini

If this project helped your work help me to keep this alive by Paypal DONATION

Tested in Leaflet v1.6.x

Demo:

opengeo.tech/maps/leaflet-panel-layers

Source code:

Github

Use Cases:

Image

Options

Option Default Description
compact false panel height minor of map height
collapsed false panel collapsed at startup
autoZIndex true set zindex layer by order definition
collapsibleGroups false groups of layers is collapsible by button
groupCheckboxes false adds a checkbox to the group title to de-/select all layers in the group
selectorGroup false select all layer of a group
buildItem null function that return row item html node(or html string)
title '' title of panel
className '' additional class name for panel
position 'topright' position of control

Events

Event Data Description
'panel:selected' {layerDef} fired after moved and show markerLocation
'panel:unselected' {} fired after control was expanded

Methods

Method Arguments Description
addBaseLayer() layerDef,group,collapsed add new layer item definition to panel as baselayers
addOverlay() 'Text message' add new layer item definition to panel as overlay
removeLayer() 'Text searched' remove layer item from panel
configToControlLayers() 'Text searched' convert config from Control.PanelLayers to Control.Layers

Usage

Panel Item Definition formats

	{
		name: "Bar",
		icon: iconByName('bar'),
		layer: L.geoJson(Bar, {pointToLayer: featureToMarker })
	}

definition in JSON format permit to store simply the configuration type contains a Leaflet method in this case L.geoJson() args is the arguments passed to the method: L.geoJson(river)

	{
		layer: {
			type: "geoJson",
			args: [ river ]
		},
	}

definition of a group

	{
		group: "Title Group",
		collapsed: true,
		layers: [
		...other items...
		]
	}

Multiple active layers with icons

var baseLayers = [
	{
		active: true,
		name: "OpenStreetMap",
		layer: L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png')
	}
];
var overLayers = [
	{
		name: "Drinking Water",
		icon: '<i class="icon icon-water"></i>',
		layer: L.geoJson(WaterGeoJSON)
	},
	{
		active: true,
		name: "Parking",
		icon: '<i class="icon icon-parking"></i>',
		layer: L.geoJson(ParkingGeoJSON)
	}
];
map.addControl( new L.Control.PanelLayers(baseLayers, overLayers) );

Build panel layers from pure JSON Config

var panelJsonConfig = {
    "baselayers": [
        {
            "active": true,
            "name": "Open Cycle Map",
            "layer": {
                "type": "tileLayer",
                "args": [
                    "https://{s}.tile.opencyclemap.org/cycle/{z}/{x}/{y}.png"
                ]
            }
        },
        {
            "name": "Landscape",
            "layer": {
                "type": "tileLayer",
                "args": [
                    "https://{s}.tile3.opencyclemap.org/landscape/{z}/{x}/{y}.png"
                ]
            }
        },        
        {
            "name": "Transports",
            "layer": {
                "type": "tileLayer",
                "args": [
                    "https://{s}.tile2.opencyclemap.org/transport/{z}/{x}/{y}.png"
                ]
            }
        }
    ],
    "overlayers": [
        {
            "name": "Terrain",
            "layer": {
            "type": "tileLayer",
            "args": [
                "https://toolserver.org/~cmarqu/hill/{z}/{x}/{y}.png", {
                "opacity": 0.5
                }
            ]
            }
        }
    ]
};
L.control.panelLayers(panelJsonConfig.baseLayers, panelJsonConfig.overLayers).addTo(map);

Grouping of layers

L.control.panelLayers(
	[
		{
			name: "Open Street Map",
			layer: osmLayer
		},
		{
			group: "Walking layers",
			layers: [
				{
					name: "Open Cycle Map",
					layer: L.tileLayer('https://{s}.tile.opencyclemap.org/cycle/{z}/{x}/{y}.png')
				},
				{
					name: "Hiking",
					layer: L.tileLayer("https://toolserver.org/tiles/hikebike/{z}/{x}/{y}.png")
				}
			]
		},
		{
			group: "Road layers",
			layers: [
				{
					name: "Transports",
					layer: L.tileLayer("https://{s}.tile2.opencyclemap.org/transport/{z}/{x}/{y}.png")
				}
			]
		}
	],
	{collapsibleGroups: true}
).addTo(map);

Collapse some layers' groups

L.control.panelLayers([
	{
		name: "Open Street Map",
		layer: osmLayer
	},
	{
		group: "Walking layers",
		layers: [
			{
				name: "Open Cycle Map",
				layer: L.tileLayer('https://{s}.tile.opencyclemap.org/cycle/{z}/{x}/{y}.png')
			},
			{
				name: "Hiking",
				layer: L.tileLayer("https://toolserver.org/tiles/hikebike/{z}/{x}/{y}.png")
			}			
		]
	},
	{
		group: "Road layers",
		collapsed: true,
		layers: [
			{
				name: "Transports",
				layer: L.tileLayer("https://{s}.tile2.opencyclemap.org/transport/{z}/{x}/{y}.png")
			}
		]
	}
]).addTo(map);

Add layers dynamically at runtime

var panel = L.control.panelLayers();

$.getJSON('some/url/path.geojson', function(data){
	panel.addOverlay({
		name: "Drinking Water",
		icon: '<i class="icon icon-water"></i>',
		layer: L.geoJson(data)
	});
});

Build

This plugin support Grunt for building process. Therefore the deployment require NPM installed in your system. After you've made sure to have npm working, run this in command line:

npm install
grunt

More Repositories

1

leaflet-search

Search stuff in a Leaflet map
JavaScript
706
star
2

leaflet-gps

Simple leaflet control plugin for tracking gps position
JavaScript
112
star
3

bootstrap-list-filter

Search widget to filter Bootstrap lists
HTML
99
star
4

leaflet-geojson-selector

Show GeoJSON Layer like as Interactive Menu List
JavaScript
99
star
5

gpx-simplify-optimizer

Free Tracks Optimizer Online Service
JavaScript
92
star
6

leaflet-layerJSON

Build dynamic JSON Layer via Ajax/JSONP with caching
JavaScript
90
star
7

leaflet-compass

Leaflet plugin to show a rotating Compass!
JavaScript
85
star
8

leaflet-list-markers

A Leaflet Control for listing visible markers/features in a interactive box
JavaScript
61
star
9

leaflet-locationpicker

Simple location picker on Leaflet map
JavaScript
46
star
10

bootstrap-confirm-button

A simple button to confirm tasks, inline and unobtrusive confirm system
HTML
24
star
11

leaflet-loader

Simple control to show a gif loader to the center of the map
HTML
16
star
12

share-tracks

Simple way to Share/Embed GPX Tracks in Leaflet
JavaScript
15
star
13

node-fetch-dom

Magic utility that extract javascript global variables from a remote html page.
HTML
13
star
14

labshub

Static web site generator for create an Hub to organizing a set of NPM packages by keywords
HTML
9
star
15

orthogonalize-js

JavaScript polyline, linestring, path spatial orthogonalize library
Java
8
star
16

dns-320-command-line

COMMAND-LINE INTERFACE for D-LINK SHARECENTER DNS-320
PHP
8
star
17

osm-contributors-by-area

List of contributors who have participated in a given OSM area.
JavaScript
8
star
18

PeliasLite

Minimal Single Service Interface of Pelias Geocoder in Nodejs
JavaScript
7
star
19

GeoSFX

Self Extracting GeoJSON build compressed GeoJSON distributed over JSONP in a compact, no dependencies Javascript file
JavaScript
6
star
20

docker-ors-vroom

Docker service to test VRP(Vehicle Routing Problem) with OpenRouteService and VROOM
Jupyter Notebook
5
star
21

leaflet-webpack-example

Simple example to use Leaflet with webpack
JavaScript
5
star
22

geotiff-picker

Raster GeoTiff file data picker with API Restful/CLI interface
HTML
5
star
23

download-limiter-php

Download Bandwidth Limit by PHP/BASH
PHP
5
star
24

overpass-query-cache

Bounding boxes caching system for Overpass API requests
JavaScript
5
star
25

meteor-googlemaps-server

NPM wrapper for node-googlemaps to be used in Meteor projects, google maps api for server side
JavaScript
5
star
26

leaflet-tilelayer-blend

Apply CSS Blend Modes filters to a stack of tile layers
HTML
4
star
27

youtubecaster

Stream any youtube video as audio podcast
JavaScript
3
star
28

realtime-access-map

Map for realtime monitoring geo-referenced accesses
PHP
3
star
29

osm-tile-cacher

another tiles cacher using leaflet and little bit of php
HTML
2
star
30

Mega-Python-CommandLine-Tools

Mega Python CommandLine Tools
Python
2
star
31

gps-network-tracking-system

System for realtime tracking and archive of a mobile devices network
2
star
32

mWm

Mobile Web Monitor, *nix web interface monitoring for mobile
PHP
2
star
33

geojson-resources

static GeoJSON resources distributed via public cdn
2
star
34

dotfiles

my .files
Shell
1
star
35

share-location

publish gps position to remote gpx file
JavaScript
1
star
36

crop-avatar

Interactive interface for cropping and rotation of photos for creating an avatar's profile
PHP
1
star
37

leaflet-animation

Make a GIF animation from a Leaflet map
JavaScript
1
star
38

stefanocudini

Stefano Cudini - Curriculum Vitae
HTML
1
star
39

websocket-chess

Chess game multiplayer online via websocket
PHP
1
star
40

json-indent-beautifier

Simple and interactive JSON beatifier online
HTML
1
star
41

ubuntu-window-border-updater

set window border width in ubuntu themes
JavaScript
1
star