publiclab / leaflet-environmental-layers

Collection of different environmental map layers in an easy to use Leaflet library, similar to https://github.com/leaflet-extras/leaflet-providers#leaflet-providers
https://publiclab.github.io/leaflet-environmental-layers/example/
GNU General Public License v3.0
99 stars 77 forks source link

Standardize baselayers #365

Open nstjean opened 4 years ago

nstjean commented 4 years ago

Our current method for displaying a base layer is this:

https://github.com/publiclab/leaflet-environmental-layers/blob/7cf1aa1b19e9b3728901465255d13ab3f028a786/example/oneLinerCodeExample.html#L69-L93

I feel like we can clean this up further by saving the baselayer data in the source code instead of requiring the user to provide it each time. The usage would look like this:

      L.LayerGroup.EnvironmentalLayers({
        base: ['Greyscale', 'Standard'],
        include: ['odorreport', 'asian', 'clouds', 'eonetFiresLayer', 'pLpeopleLayer'],
      }).addTo(map);

We could allow people to provide their own baselayers in addition, just as they do now. But this way it would be much easier to create a map, you just have to name which bases you want.

crisner commented 4 years ago

Awesome. Right now LEL will default to grey-scale if a user does not pass in a baseLayer. It is done in this line here: https://github.com/publiclab/leaflet-environmental-layers/blob/7cf1aa1b19e9b3728901465255d13ab3f028a786/src/AllLayers.js#L79

If we have plans to add more than one baselayer option for the user to choose we could initialize those layers within LEL just like how we've done for the overlay layers.

jywarren commented 4 years ago

Awesome!!!

nstjean commented 4 years ago

Oh great! It didn't seem to be working in plots2, but I wonder if it will now. I'll check on that while I'm working on /map/ !

nstjean commented 4 years ago

So your lovely changes aren't in plots2 yet, so I bumped the LEL version here: https://github.com/publiclab/leaflet-environmental-layers/pull/368

crisner commented 4 years ago

So your lovely changes aren't in plots2 yet, so I bumped the LEL version here: #368

There was a bug that did allow the default base layer in the one-liner code to appear when multiple maps were added to the same page. It should work now with this change once this version is added to plots2. 😄 https://github.com/publiclab/leaflet-environmental-layers/blob/4109b587196fbe35b2adfc24ce9503e206d54bee/src/AllLayers.js#L76-L79