3.0.11 • Published 1 year ago

layer-manager v3.0.11

Weekly downloads
1,038
License
MIT
Repository
github
Last release
1 year ago

Layer Manager

A library to manage the addition, and removal of layers in Leaflet and Cesium maps (Google coming soon). Furthermore it provides methods to set opacity, visibility, events and more.

Install

Using npm:

npm install layer-manager

or using git:

npm install vizzuality/layer-manager

How to use

// Import LayersManager and the corresponding Plugin depending on the
// map provider that you are using
import LayerManager, { PluginLeaflet } from 'layer-manager';

const map = L.map('map_canvas').setView([40, -3], 5);

const layerManager = new LayerManager(map, PluginLeaflet, {});

// Adding all layers to map
layerManager.add(layerSpec, {
	opacity: 0.5,
	visibility: true,
	zIndex: 2,
	interactivity: [], // It can be any type. It will depend on the layer provider
	events: {
		click: e => {},
		mouseover: e => {}
	}, // Only events supported by your map provider

	// Some layers need to be decoded
	params: {
		url: '', // Tile url to be decoded. * Mandatory
		iso: 'BRA',
		thresh: 30
	}, // * Mandatory
	sqlParams: {
		where: {
			iso: 'BRA',
			thresh: 30
		}
	},
	decodeParams: {}, // * Mandatory
	decodeFunction: (data, w, h, z) => {
		// ...stuff
	}
});

// remove all layers
layerManager.remove();

// removing specific layers
layerManager.remove(['layerID']);

// Setting opacity to specific layer
layerManager.setOpacity('layerID', 0.5);
// Setting visibility to specific layer
layerManager.setVisibility('layerID', false);
// Setting z-index to specific layer
layerManager.setZIndex('layerID', 500);

layerSpec is the response of http://api.resourcewatch.org/v1/layer?application=rw.

Support for promises:

spinner.start();

layerManager.add().then(layer => {
	spinner.stop();
	console.log('layer added');
});

Leaflet dependencies

<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.1/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.3.1/dist/leaflet.js"></script>
<script src="https://unpkg.com/esri-leaflet/dist/esri-leaflet.js"></script>
<script src="https://unpkg.com/leaflet-utfgrid/L.UTFGrid-min.js"></script>

Adding a custom provider

TODO

Available methods

Method nameDescriptionDefault
setOpacityTo set opacity. A value beetween 0 and 1.1
setVisibilityIt shows or hidden a layer. Boolean.true
setZIndexIt sets the layer position. Numberlast index
setEventsObject map with { event type: event handler } key value pairs

Available plugins

Plugin nameSupported methodsSupported providers
PluginLeafletsetOpacity, setVisibility, setZIndex, setEventscanvas, cartodb, carto, arcgis, featureservice, mapservice, tileservice, esrifeatureservice, esrimapservice, esritileservice, gee, loca, nexgddp, leaflet
PluginCesiumsetOpacity, setVisibility, setZIndex, setEventscartodb, carto

Components

React

There is a single React component that can be used to help with rendering layers via the layer manager. It can be imported and used as follows:

import { LayerManager, Layer } from 'layer-manager/lib/react';
import { PluginLeaflet } from 'layer-manager';

// map is a reference to whichever map API you are using
// For leaflet this would be
this.map = L.map('c-map', mapOptions);

<LayerManager map={this.map} plugin={PluginLeaflet}>
	{activeLayers.map(l => (
		<Layer key={l.id} {...l} />
	))}
</LayerManager>;
3.1.0-wri-gfw

1 year ago

3.0.0-video

3 years ago

3.0.10

3 years ago

3.0.11

3 years ago

2.0.12

3 years ago

2.0.11

3 years ago

2.0.10

3 years ago

3.0.9

4 years ago

1.16.0

4 years ago

3.0.8

4 years ago

3.0.7

4 years ago

3.0.6

4 years ago

3.0.5

4 years ago

3.0.4

5 years ago

3.0.3

5 years ago

3.0.2

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

3.0.0-alpha.3

5 years ago

3.0.0-alpha.1

5 years ago

3.0.0-alpha.2

5 years ago

3.0.0-beta.9

5 years ago

2.0.7

5 years ago

2.0.9

5 years ago

2.0.8

5 years ago

3.0.0-beta.8

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.6

5 years ago

3.0.0-beta.7

5 years ago

2.0.3

5 years ago

3.0.0-beta.6

5 years ago

3.0.0-beta.5

5 years ago

3.0.0-beta.4

5 years ago

3.0.0-beta.3

5 years ago

3.0.0-beta.2

5 years ago

3.0.0-beta.1

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

2.0.0-mapbox

5 years ago

1.17.9-mapbox

5 years ago

1.17.8-mapbox

5 years ago

1.15.3

5 years ago

1.17.7-mapbox

5 years ago

1.17.6-mapbox

5 years ago

1.17.5-mapbox

5 years ago

1.17.4-mapbox

5 years ago

1.17.3-mapbox

5 years ago

1.17.2-mapbox

5 years ago

1.17.1-mapbox

5 years ago

1.17.0-mapbox

5 years ago

1.16.13-mapbox

5 years ago

1.16.12-mapbox

5 years ago

1.16.11-mapbox

5 years ago

1.16.10-mapbox

5 years ago

1.16.9-mapbox

5 years ago

1.16.8-mapbox

5 years ago

1.16.7-mapbox

6 years ago

1.16.6-mapbox

6 years ago

1.16.5-mapbox

6 years ago

1.16.4-mapbox

6 years ago

1.16.3-mapbox

6 years ago

1.16.2-mapbox

6 years ago

1.16.1-mapbox

6 years ago

1.16.0-mapbox

6 years ago

1.15.14-beta

6 years ago

1.15.13-beta

6 years ago

1.15.12-beta

6 years ago

1.15.11-beta

6 years ago

1.15.10-beta

6 years ago

1.15.9-beta

6 years ago

1.15.8-beta

6 years ago

1.15.7-beta

6 years ago

1.15.6-beta

6 years ago

1.15.2

6 years ago

1.15.5-beta

6 years ago

1.15.1

6 years ago

1.15.0

6 years ago

1.15.4-beta

6 years ago

1.15.3-beta

6 years ago

1.15.2-beta

6 years ago

1.15.1-beta

6 years ago

1.15.0-beta

6 years ago

1.14.7

6 years ago

1.14.6

6 years ago

1.14.5

6 years ago

1.14.4

6 years ago

1.14.3

6 years ago

1.14.2

6 years ago

1.14.1

6 years ago

1.14.0

6 years ago

1.13.5

6 years ago

1.13.4

6 years ago

1.13.3

6 years ago

1.13.2

6 years ago

1.13.1

6 years ago

1.13.0

6 years ago

1.12.3

6 years ago

1.12.2

6 years ago

1.12.1

6 years ago

1.12.0

6 years ago

1.11.0

6 years ago

1.10.0

6 years ago

1.1.9

6 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.20

6 years ago

1.0.19

6 years ago

1.0.18

6 years ago

1.0.17

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago