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

Implement new menu in one liner code #353

Merged

Conversation

crisner
Copy link
Contributor

@crisner crisner commented Jan 17, 2020

Fixes #347 (<=== Add issue number here)

Make sure these boxes are checked before your pull request (PR) is ready to be reviewed and merged. Thanks!

  • PR is descriptively titled 📑 and links the original issue above 🔗
  • tests pass -- look for a green checkbox ✔️ a few minutes after opening your PR
  • code is in uniquely-named feature branch and has no merge conflicts 📁
  • screenshots/GIFs are attached 📎 in case of UI updation
  • ask @publiclab/reviewers for help, in a comment below

We're happy to help you get this ready -- don't be afraid to ask for help, and don't be discouraged if your tests fail at first!

If tests do fail, click on the red X to learn why by reading the logs.

Please be sure you've reviewed our contribution guidelines at https://publiclab.org/contributing-to-public-lab-software

Thanks!

@crisner
Copy link
Contributor Author

crisner commented Jan 17, 2020

Things done:

  • Implemented new menu in one liner code
  • Add new menu dependancies to one-liner code example files
  • Fix styles from overriding default leaflet styles

Things to do:

  • Fix error from layer when refreshing map view when the layer is out of bounds(when using include)
  • Add option to use default layer control when needed
  • Add option to display all layers when map is initialized
  • Add documentation

@crisner crisner changed the title Implement new menu in one liner code [WIP] Implement new menu in one liner code Jan 17, 2020
@jywarren
Copy link
Member

jywarren commented Jan 17, 2020 via email

@crisner
Copy link
Contributor Author

crisner commented Jan 17, 2020

This is still a work in progress. Things to do are what's left to do in this PR. I shall make sure to mention when the PR is ready. Thanks!

@jywarren
Copy link
Member

jywarren commented Jan 17, 2020 via email

src/AllLayers.js Outdated
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)) {
this.overlayMaps[layer] = window['L']['layerGroup'][layer]();
if (layer === 'purpleLayer' && !this.groupedOverlayMaps.PurpleAir) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey this is getting messy, can we use switch case instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will do.

overflow-y: hidden;
}

.leaflet-control-layers-overlays {
.leaflet-control-layers-menu .leaflet-control-layers-overlays {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need this CSS as well in plots2, right?
Also we need to make sure that we use different CSS for different custom bars. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need this CSS as well in plots2, right?

Thanks for mentioning this. I had assumed it would be bundled into dist. I think it is safe to move the styles to LeafletEnvironmentalLayers.css in /dist. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also we need to make sure that we use different CSS for different custom bars.

Yes, you are right. That is why I had added .leaflet-control-layers-menu which is a custom class so that it does not override leaflet's default .leaflet-control-layers-overlays.

@@ -129,7 +178,8 @@ L.LayerGroup.environmentalLayers = L.LayerGroup.extend(
) : L.control.embed().addTo(map);
}

L.control.layers(baseMaps, this.overlayMaps).addTo(map);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just add if option has param to show default, use this line else use the below layerbrowser line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working on this.

@crisner crisner changed the title [WIP] Implement new menu in one liner code Implement new menu in one liner code Jan 20, 2020
@crisner
Copy link
Contributor Author

crisner commented Jan 20, 2020

PR ready for review. The implementation can be checked at https://crisner.github.io/leaflet-environmental-layers/example/oneLinerCodeExample.html

Dependencies:
```
<!-- Bootstrap -->
<link rel="stylesheet" href="../node_modules\bootstrap\dist\css\bootstrap.min.css">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sagarpreet-chadha, this just occurred to me. To add these dependencies shouldn't I point it to LEL's node modules? So here, shouldn't I be writing "leaflet-environmental-layers/node_modules" instead to make sense? It wouldn't work otherwise unless the destination repo had bootstrap installed, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found that only LBL was in the node_modules folder in LEL when installing as a package. I was of the impression that all dependencies of a package would be included in the node_modules of that package. So I am assuming we should explicitly mention in the documentation that bootstrap needs to be installed? The new menu needs bootstrap load correctly.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes let's do that!

Dependencies:
```
<!-- Bootstrap -->
<link rel="stylesheet" href="../node_modules\bootstrap\dist\css\bootstrap.min.css">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes let's do that!

@@ -42,6 +47,11 @@
<script src="../lib/glify.js"></script>

<script src="../lib/leaflet-fullUrlHash.js"></script>

<script src="../node_modules/leaflet-google-places-autocomplete/src/js/leaflet-gplaces-autocomplete.js"></script>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have documented this also?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. This needs to be added too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to readme.md

src/AllLayers.js Outdated
@@ -46,7 +47,7 @@ L.LayerGroup.environmentalLayers = L.LayerGroup.extend(
this.options.baseLayers = param.baseLayers;
}
if (!!param.include) {
this.options.addLayersToMap = true;
this.options.addLayersToMap = param.addLayersToMap === false ? false : true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.options.addLayersToMap = param.addLayersToMap === false ? false : true;
this.options.addLayersToMap = param.addLayersToMap;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. To display layers by default on inline maps in plots2 we'll need to add addLayersToMap: true to the LEL initialization.

Comment on lines +471 to +476
if (isPageRefreshed < 2 && window.performance.navigation.type !== 1) {
isPageRefreshed++; // Track page moveend events to prevent errors on map.removeLayer when a page is reloaded
}
if(isPageRefreshed > 1) {
self._hideElements(obj, data, layerName, elements, true);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What these lines do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new layer menu removes the map on 'moveend' event if the layer is displayed on the map but is out of bounds. The 'moveend' event was being triggered on page refresh causing the error on the unearthing layer where it couldn't find the layer to remove from the map.

This was weird because that line of code would only run if map.hasLayer() returned true. And also I could see the layer displayed on the map and could access it on the console. So I set this up to avoid running that code if it is the first 'moveend' event after a page refresh.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay

Copy link
Collaborator

@sagarpreet-chadha sagarpreet-chadha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is good to go now :) Thanks!

@sagarpreet-chadha sagarpreet-chadha merged commit 7cf1aa1 into publiclab:master Jan 23, 2020
@jywarren
Copy link
Member

Awesome!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Display new layers menu when instantiating LEL with one liner code
3 participants