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

[WIP]Embed feature in demo page #296

Closed
wants to merge 10 commits into from

Conversation

crisner
Copy link
Contributor

@crisner crisner commented Dec 9, 2019

Fixes #252 (<=== 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 Dec 9, 2019

Screenshot of the feature:
embedFeature

@crisner
Copy link
Contributor Author

crisner commented Dec 9, 2019

I have added the embed feature only to the layers.js file as it was specifically for the demo page. Should this be implemented in AllLayers.js as well?

Also, when I was referring to the embed feature implemented in plots2 I noticed that the URL has query strings. Should that be implemented here as well?

@crisner
Copy link
Contributor Author

crisner commented Dec 9, 2019

Should the embed button follow the style guide and have a bootstrap styled button or should it be similar to the zoom controls in the map?

@crisner
Copy link
Contributor Author

crisner commented Dec 9, 2019

Embed code in use at the bottom of the page --> https://codepen.io/crisren/full/abzdJPV

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.

@jywarren @ebarry
Can you confirm if the position of embed button is fine? Thanks!


generateCode: function() {
var params = this.getUrlHashParameters();
var code = '<iframe style="border:none;" width="100%" height="900px" src="//publiclab.github.io/leaflet-environmental-layers/example/#' + params.zoom + '/' + params.lat + '/' + params.lng + '/' + params.layers +'"></iframe>';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hey @crisner ,
Instead of this URL, let's use the one i created in PL:
https://publiclab.org/map/

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 tried loading the mentioned URL but I am getting a 404 page.

return code;
},

onRemove: function(map) {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you verify if on calling remove function, the button gets removed?

Copy link
Contributor Author

@crisner crisner Dec 10, 2019

Choose a reason for hiding this comment

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

I didn't implement a remove function thinking there wasn't a need for it. I shall check it.

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 button gets removed using removeControl(control) on the map object. It looks like the onRemove method works as expected.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Okay cool! You never know what use-case the user may need :)

@@ -232,6 +232,8 @@
var hash = new L.Hash(map, allMapLayers);
var leafletControl = new L.control.layers(baseMaps,overlayMaps);
leafletControl.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.

AWESOME!!!
Let's add this to all HTML demo files :)

@@ -38,6 +38,8 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/OverlappingMarkerSpiderfier-Leaflet/0.2.6/oms.min.js"></script>

<script src="lib/glify.js"></script>

<script src="https://kit.fontawesome.com/92fa0312fd.js" crossorigin="anonymous"></script>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we download this font-awesome file and add that to LEL repo in /images folder so that the button image is there even if we are offline?

Copy link
Collaborator

Choose a reason for hiding this comment

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

And then remove this script also. Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

We could include it using NPM and then it'd be in node_modules?

@jywarren
Copy link
Member

jywarren commented Dec 9, 2019

Regarding the styling, i guess it might work best as a native Leaflet styled button, like the full screen buttons on https://publiclab.org/wiki/unearthing-pvd for example. Once you try it out can you share a screenshot?

Thank you! Looking awesome!

@crisner
Copy link
Contributor Author

crisner commented Dec 10, 2019

Thank you for the feedback @sagarpreet-chadha and @jywarren! I shall make the changes as suggested.

@crisner
Copy link
Contributor Author

crisner commented Dec 10, 2019

@jywarren, here's the screenshot of the embed button I have now. What do you think?
127 0 0 1_5500_example_index html (2)

@jywarren
Copy link
Member

jywarren commented Dec 10, 2019 via email

@crisner crisner changed the title Embed feature in demo page [WIP]Embed feature in demo page Dec 10, 2019
@crisner
Copy link
Contributor Author

crisner commented Dec 10, 2019

This is what I have so far:

  • Assuming the URL needed to be formatted as:
    http://localhost:3000/map/Unearthing,eonetFiresLayer,odorreport,asian#lat=30.600093873550072&lon=52.03125&zoom=3
    I tried to implement the hash but with the formatted code by modifying the fullHash library. -> https://github.com/crisner/leaflet-fullUrlHash. I have the following format now:
    http://127.0.0.1:5500/example/index.html#lat=43.00&lon=-83.00&zoom=3&layers=BL1
  • Added fontawesome to node modules
  • Added native leaflet style to embed icon

Issues I am facing:

  • When I click on the prompt buttons, generated more than once after loading the page, for some reason the location hash gets reset. I will be looking into this tomorrow.

@jywarren
Copy link
Member

jywarren commented Dec 10, 2019 via email

@crisner
Copy link
Contributor Author

crisner commented Dec 10, 2019

Thanks, @jywarren! I like the idea of spinning it out as a new issue. That way it is easier for me to focus.

@jywarren
Copy link
Member

jywarren commented Dec 10, 2019 via email

@crisner
Copy link
Contributor Author

crisner commented Dec 11, 2019

  • Issues I am facing:

    When I click on the prompt buttons, generated more than once after loading the page, for some reason the location hash gets reset. I will be looking into this tomorrow.

    Fixed this issue.

  • I tried changing this url:
    http://127.0.0.1:5500/example/index.html#lat=43.00&lon=-83.00&zoom=3&layers=BL1
    to http://localhost:3000/example/index.html/BL1#lat=-83.00&lon=-83.00&zoom=3

    I am getting a cannot GET error message for /BL1. I am assuming it is because there is no such path on the front end. So, presently the URL is http://127.0.0.1:5500/example/index.html#lat=43.00&lon=-83.00&zoom=3&layers=BL1

  • I have added the embed control to other pages as suggested. This works locally but the actual links point to a 404 page.
    publiclab github io_leaflet-environmental-layers_example_unearthing-pvd html

    These files have the permalinks issue #6889 for which we have a PR Fixes map permalinks overwrite issue on plots2 #293

@crisner
Copy link
Contributor Author

crisner commented Dec 11, 2019

Looking forward to your feedback on the changes @sagarpreet-chadha. :) I would also like your feedback on a couple of issues I have mentioned in my previous comment.

@crisner
Copy link
Contributor Author

crisner commented Dec 11, 2019

Should I also commit the package-lock.json file?

@jywarren
Copy link
Member

Just quickly, yes please do commit it, as it often includes updates or adjustments. We can pull it out if there's anything too weird in there :-)

Do you know how to test by setting up your own gh-pages branch? This is a good way to check that it'll work the same way without needing to first overwrite the publiclab gh-pages. But you do need to keep a separate branch with gh-pages with your node_modules all added, and commit and push them only to your own gh-pages branch. This gets a little complicated, but it's great for showing off a new version so it can be tested out before being merged!

@sagarpreet-chadha
Copy link
Collaborator

Awesome work so far!!!
@crisner ...do tell if you need help setting up gh-pages in your forked repo 😄 .

@crisner
Copy link
Contributor Author

crisner commented Dec 11, 2019

I have set up gh-pages before. But it has been a while. I'll give it a go and update my progress here.

@sagarpreet-chadha
Copy link
Collaborator

sagarpreet-chadha commented Dec 11, 2019 via email

@crisner
Copy link
Contributor Author

crisner commented Dec 12, 2019

It was harder than I expected to figure things out but I have managed to set up a working gh-pages from a 'development' branch on my forked repo.

Screenshot for index.html:

ghpages_index
Link: https://crisner.github.io/leaflet-environmental-layers/example/index.html#lat=20.55&lon=9.84&zoom=3&layers=BL1,STruth,OdorR

Screenshot for oneLinerCodeExample.html:

ghpages_oneLinerCodeExample
Link: https://crisner.github.io/leaflet-environmental-layers/example/oneLinerCodeExample.html#lat=38.20&lon=-4.04&zoom=3&layers=odorreport,asian,eonetFiresLayer,Unearthing

Screenshot for unearthing-pvd.html:

ghpages_unearthing-pvd
Link: https://crisner.github.io/leaflet-environmental-layers/example/unearthing-pvd.html#lat=41.8300&lon=-71.4400&zoom=10&layers=asian,clouds,Unearthing

@crisner
Copy link
Contributor Author

crisner commented Dec 12, 2019

I am also getting the following warning from GitHub in my mail,

The page build completed successfully, but returned the following warning for the gh-pages branch:

It looks like you're using GitHub Pages to distribute binary files. We strongly suggest that you use releases to ship projects on GitHub. Releases are GitHub's way of packaging and providing software to your users. You can think of it as a replacement to using downloads to provide software. We found the following file(s) which may be a good candidate for releases: node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs.exe.

@crisner
Copy link
Contributor Author

crisner commented Dec 13, 2019

The active baselayer appears unselected in the map's layer control which affects the url hash as well.
Screenshot of the issue:
baselayer-bug

I started another branch from the changes in this PR as the base and created issue #299 and linked PR #300 to it. Please let me know if this is not the right way to go about adding more changes in a separate PR. Thanks!

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.

just a small change and this looks good!!!

@@ -121,15 +121,18 @@ L.LayerGroup.environmentalLayers = L.LayerGroup.extend(
}

if(this.options.embed) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Redundant code?

return code;
},

onRemove: function(map) {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Okay cool! You never know what use-case the user may need :)

var HAS_HASHCHANGE = (function() {
var doc_mode = window.documentMode;
return ('onhashchange' in window) &&
(doc_mode === undefined || doc_mode > 7);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we need to add this to a separate folder outside example. Let's make one lib folder at the root level and change the script tag above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I move the whole lib folder to the root or just the fullUrlHash.js file?

@sagarpreet-chadha
Copy link
Collaborator

Continued to #300 (review)

@sagarpreet-chadha
Copy link
Collaborator

Yes the whole lib folder, but we should make note that we will have to change script src for glify.js in plots2 then. Thanks!

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.

"embed" button
3 participants