From 9aae60dbe054b45672646ffc98ade192a063c6d7 Mon Sep 17 00:00:00 2001 From: crisner Date: Thu, 16 Jan 2020 14:26:05 +0530 Subject: [PATCH 1/2] Add default basemap when undefined --- README.md | 8 ++++++++ dist/LeafletEnvironmentalLayers.js | 5 ++++- example/oneLinerCodeExample.html | 20 ++++++++++---------- src/AllLayers.js | 5 ++++- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index cb740151c..d7dbd137e 100644 --- a/README.md +++ b/README.md @@ -285,6 +285,14 @@ We're going to try spinning this out into its own library; see: https://github.c include: ['mapknitter', 'clouds'], }).addTo(map); +## Add base layers: + + L.LayerGroup.EnvironmentalLayers({ + baseLayers: { // Grayscale base map is used by default when this is undefined + 'Standard': baselayer1 + }, + }).addTo(map); + ## Turn on Leaflet Hash in the URL: L.LayerGroup.EnvironmentalLayers({ diff --git a/dist/LeafletEnvironmentalLayers.js b/dist/LeafletEnvironmentalLayers.js index 28b6b04ff..a2013999e 100644 --- a/dist/LeafletEnvironmentalLayers.js +++ b/dist/LeafletEnvironmentalLayers.js @@ -25855,6 +25855,9 @@ L.LayerGroup.environmentalLayers = L.LayerGroup.extend( hash: false, embed: false, // activates layers on map by default if true. currentHash: location.hash, + defaultBaseLayer: L.tileLayer('https://a.tiles.mapbox.com/v3/jywarren.map-lmrwb2em/{z}/{x}/{y}.png', { + attribution: '© OpenStreetMap contributors', + }), // Source of Truth of Layers name . // please put name of Layers carefully in the the appropriate layer group. layers0: ['purpleLayer', 'toxicReleaseLayer', 'pfasLayer', 'aqicnLayer', 'osmLandfillMineQuarryLayer', 'Unearthing'], @@ -25914,7 +25917,7 @@ L.LayerGroup.environmentalLayers = L.LayerGroup.extend( onAdd: function(map) { this._map = map; this.overlayMaps = {}; - var baseMaps = this.options.baseLayers; + var baseMaps = this.options.baseLayers ? this.options.baseLayers : { "Grey-scale": this.options.defaultBaseLayer.addTo(map) }; for (let layer of this.options.layers.include) { if (this.options.layers0.includes(layer)) { diff --git a/example/oneLinerCodeExample.html b/example/oneLinerCodeExample.html index 1d0b62bc1..3e9edddc5 100644 --- a/example/oneLinerCodeExample.html +++ b/example/oneLinerCodeExample.html @@ -61,13 +61,13 @@ }).setView([43, -83], 3); map.options.minZoom = 3; - var baselayer1 =L.tileLayer( - "https://a.tiles.mapbox.com/v3/jywarren.map-lmrwb2em/{z}/{x}/{y}.png", - { - attribution: - '© OpenStreetMap contributors' - } - ).addTo(map); + var baselayer1 = L.tileLayer( + 'https://api.tiles.mapbox.com/v4/mapbox.emerald/{z}/{x}/{y}.png?access_token=pk.eyJ1Ijoic2FnYXJwcmVldDk3IiwiYSI6ImNqaXhlZjgwaDJtb3EzcW1zdDdwMzJkODcifQ.MA2YIv6VpGLLAo-QYUudTA', + { + attribution: + '© OpenStreetMap contributors', + }, + ).addTo(map); /* This is required, make this optional! */ // var oms = omsUtil(map, { @@ -75,9 +75,9 @@ // circleSpiralSwitchover: 0 // }); L.LayerGroup.EnvironmentalLayers({ - baseLayers: { - 'Grey-scale': baselayer1 - }, + // baseLayers: { + // 'Standard': baselayer1 + // }, include: ['odorreport', 'asian', 'clouds', 'eonetFiresLayer', 'Unearthing'], // exclude: ['mapknitter', 'clouds'], hash: true, diff --git a/src/AllLayers.js b/src/AllLayers.js index cbe06cca3..f5d5e33d7 100644 --- a/src/AllLayers.js +++ b/src/AllLayers.js @@ -5,6 +5,9 @@ L.LayerGroup.environmentalLayers = L.LayerGroup.extend( hash: false, embed: false, // activates layers on map by default if true. currentHash: location.hash, + defaultBaseLayer: L.tileLayer('https://a.tiles.mapbox.com/v3/jywarren.map-lmrwb2em/{z}/{x}/{y}.png', { + attribution: '© OpenStreetMap contributors', + }), // Source of Truth of Layers name . // please put name of Layers carefully in the the appropriate layer group. layers0: ['purpleLayer', 'toxicReleaseLayer', 'pfasLayer', 'aqicnLayer', 'osmLandfillMineQuarryLayer', 'Unearthing'], @@ -64,7 +67,7 @@ L.LayerGroup.environmentalLayers = L.LayerGroup.extend( onAdd: function(map) { this._map = map; this.overlayMaps = {}; - var baseMaps = this.options.baseLayers; + var baseMaps = this.options.baseLayers ? this.options.baseLayers : { "Grey-scale": this.options.defaultBaseLayer.addTo(map) }; for (let layer of this.options.layers.include) { if (this.options.layers0.includes(layer)) { From f6eec6e8e4100cc10347675c5dbc52c3e83e5b67 Mon Sep 17 00:00:00 2001 From: crisner Date: Thu, 16 Jan 2020 14:44:31 +0530 Subject: [PATCH 2/2] Update version number indicating bug-fix --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 893d74fa5..98266fa8e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "leaflet-environmental-layers", - "version": "2.1.7", + "version": "2.1.8", "description": "", "main": "index.js", "directories": {