Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default basemap when undefined #351

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
5 changes: 4 additions & 1 deletion dist/LeafletEnvironmentalLayers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> 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'],
Expand Down Expand Up @@ -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)) {
Expand Down
20 changes: 10 additions & 10 deletions example/oneLinerCodeExample.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,23 @@
}).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:
'&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> 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:
'&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
},
).addTo(map);

/* This is required, make this optional! */
// var oms = omsUtil(map, {
// keepSpiderfied: true,
// circleSpiralSwitchover: 0
// });
L.LayerGroup.EnvironmentalLayers({
baseLayers: {
'Grey-scale': baselayer1
},
// baseLayers: {
// 'Standard': baselayer1
// },
include: ['odorreport', 'asian', 'clouds', 'eonetFiresLayer', 'Unearthing'],
// exclude: ['mapknitter', 'clouds'],
hash: true,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "leaflet-environmental-layers",
"version": "2.1.7",
"version": "2.1.8",
"description": "",
"main": "index.js",
"directories": {
Expand Down
5 changes: 4 additions & 1 deletion src/AllLayers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> 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'],
Expand Down Expand Up @@ -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)) {
Expand Down