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

Map layer permalinks get overwritten on page open #6889

Closed
jywarren opened this issue Dec 2, 2019 · 11 comments · Fixed by publiclab/leaflet-environmental-layers#293
Closed
Labels
help wanted requires help by anyone willing to contribute JavaScript

Comments

@jywarren
Copy link
Member

jywarren commented Dec 2, 2019

part of #6801 -
Leaflet Environmental Layers has a great feature which appends the displayed layers to the URL hash; so, if you enable the "pfasLayer" layer while on https://publiclab.org/maps, the URL will look like this:

https://publiclab.org/maps#3/41.00/-71.00/pfasLayer

Note that it also includes the latitude/longitude.

However, if you copy that link and open it somewhere else, that's not preserved; it overwrites with just the lat/lon/zoom:

https://publiclab.org/maps#3/41.00/-71.00/

We should, instead, see that page with the corresponding layers already enabled:

image

We'd love help with this! Maybe @crisner would be interested? Also cc'ing @nstjean and @sagarpreet-chadha as this is a tiny part of the overall Outreachy/Geographic features projects you're both working on!

@jywarren jywarren added help wanted requires help by anyone willing to contribute JavaScript labels Dec 2, 2019
@jywarren jywarren added this to the Geographic features milestone Dec 2, 2019
@crisner
Copy link
Contributor

crisner commented Dec 3, 2019

I checked this out and looked over the code. But I can't seem to reproduce the behaviour in my local environment so that I could locate the code causing the issue. @IshaGupta18, would you be able to guide me on how to go about this?

@sagarpreet-chadha
Copy link
Contributor

Hey @crisner ,
When you open this link: https://publiclab.org/maps#3/41.00/-71.00/pfasLayer
Notice that pfaLayer is removed automatically, right?

The reason is the leaflet-hash library in LEL. We need to store the 'hash' variable somewhere such that it does not get re-initialize.

@crisner
Copy link
Contributor

crisner commented Dec 3, 2019

Thanks for the reply @sagarpreet-chadha. I managed to figure out that I need to store the hash so it does not change but I had trouble figuring out where to do it. It has become harder as I couldn't replicate the behaviour in my local environment which means I can't confirm if I am working on the right file. Not sure if I am missing something. I'll try to look at it again tomorrow.

@crisner
Copy link
Contributor

crisner commented Dec 3, 2019

Ah, I am not sure if I just misunderstood your reply. Did you mean the problem lies in the LEL repo? Anyway shall take a look at it again.

@jywarren
Copy link
Member Author

jywarren commented Dec 3, 2019 via email

@crisner
Copy link
Contributor

crisner commented Dec 5, 2019

When I open the link(https://publiclab.org/maps#3/41.00/-71.00/pfasLayer) elsewhere the coordinates in the URL also changes. It overwrites to https://publiclab.org/maps#2/15.0/2.8/. As @sagarpreet-chadha mentioned the problem lies with the leaflet-hash library in LEL, specifically how the hash instance is saved in the environmental layers LayerGroup. Please correct me if I am wrong.

I am stuck at the moment trying to prevent the hash from getting reinitialized. Tried to save the hash globally as well but I think the trick is to have it initialized after the map instance? Trying to figure out how to get that done.

@sagarpreet-chadha
Copy link
Contributor

Hey, yes you understand the issue correctly. The bug is in LEL.
One way to solve this be to initialize the hash variable outside library in .html example file. We need to pass the object of layers to hash function. This object should be returned/exposed from the library. Makes sense? Thanks!

@jywarren
Copy link
Member Author

jywarren commented Dec 5, 2019 via email

@crisner
Copy link
Contributor

crisner commented Dec 7, 2019

Just wanted to bring it to attention that the following lines outputs an error and does not let the layer control render on the map when I run plots2 locally. This is because the omsUtil function is not available outside of LEL. I came across this when I was trying to fix this issue #6889.

var oms = omsUtil(map, {
keepSpiderfied: true,
circleSpiralSwitchover: 0
});

@crisner
Copy link
Contributor

crisner commented Dec 7, 2019

I will need to debug the error a bit more to be sure.

@crisner
Copy link
Contributor

crisner commented Dec 7, 2019

I apologize for the confusion. Looks the LEL copy in my plots2 copy didn't have the omsUtil defined. 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted requires help by anyone willing to contribute JavaScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants