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

Ol5 sidebar #144

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

Ol5 sidebar #144

wants to merge 13 commits into from

Conversation

umbe1987
Copy link

This PR makes the sidebar compatible with version 5 of OpenLayers, addressing #143.

I don't know if it fits your desire/requirements, but I added:

  • js/ol-sidebar.js: rewrite of the sidebar code as ES6 module

  • examples/ol5.js: map creation and addition of the sidebar (don't know if you prefer to keep this in the HTML as the other examples

  • examples/ol5.html: the HTML part. Here I included a full build of OL5, however one could also use specific imports.

I didn't include the dist/ol5-sidebar.js folder which the HTML <script> is pointing to. I created it using parcel via npm run build.

However, if you consider this PR useful and you'll need that file as well, I'll be happy to provide it.

I am open to any improvements/rework if you think it is a valuable addition to your project.

Thanks!

@Turbo87
Copy link
Owner

Turbo87 commented Sep 27, 2018

if possible we should avoid to use ES6 directly here. the files in this project should be written in a way that they don't need a build step as the code logic is easy enough and usually doesn't need the complexity of a build step aside from minifying.

@umbe1987
Copy link
Author

@Turbo87 ok, I'll try to see if I could make it without the need of a build step then.
Do you perhaps have any suggestions?
I think the first thing would be to remove imports and exports first.
One thing I could do if this is not feasible is to build on my own and just give you the built ol5-sidebar.js if that's fine. Anyway, I'll try to rework on it and come back with my findings.
Thank you for your feedback.

@umbe1987
Copy link
Author

umbe1987 commented Sep 27, 2018

Ok I am start thinking it's not a matter of compatibility with OL version 5.

Indeed, from a quick test, if you change the link and script tags in the ol3.html to point (e.g.) the actual version of OL, the code seems to work:

<link rel="stylesheet" href="https://openlayers.org/en/v5.2.0/css/ol.css" type="text/css">
<script src="//openlayers.org/en/v5.2.0/build/ol.js" type="text/javascript"></script>

I think the major problem is that one has to include the full build of OL library (namely, //openlayers.org/en/v5.2.0/build/ol.js), instead of taking advantage of the modern JS modules.
The OpernLayers already moved in this direction (that's what version 5 is all about).

As for the limitation of the actual state of this project to this regard, at present one is forced to adapt the various examples of OpenLayers v5.x to the old style.

Example (taken from Simple Map):

new style (v5.x)

import Map from 'ol/Map.js';
...
var map = new Map({

old style (v4/3.x) (same example)

<script src="https://openlayers.org/en/v4.6.5/build/ol.js"></script>
...
var map = new ol.Map({

This is not a problem per se, nor it breaks functionality. But as it stands, one could not take advantage of the modularity introduced by ES6, amd has to link to the whole ol build.

SOLUTION/PROPOSAL

To be consistent with the architecture of this project, take advantage of the enhancement of this PR, and assure compatibility with the already existing examples, I think it would be possible to include the new ol5-sidebar.js of the js folder AND adding the dist (or whatever you'd like to call it) folder containing the already built library (something similar to Walkermatt/ol-layerswitcher).

Eventually, I think it is enough to:

  1. Update version of OL in the script and link tags (as mentioned before) in the already existing ol3.html (maybe changing the filename to a more generic ol.html?), and

  2. Change <script src="../js/ol3-sidebar.js"></script> to <script src="../dist/ol5-sidebar.js"></script> in the same file.

(Number 1 should work also without merging this PR actually)

I am happy to rework on this PR if you think you'll merge it to your project, and If you don't want to I'd understand it.

@umbe1987
Copy link
Author

Just added the dist folder to give the possibility to try the implementation.

@umbe1987
Copy link
Author

I think the very last two commits should give more consistency to this PR in your project. Hope to have clarified my proposal and that you might take some time to consider it. Thank you.

@umbe1987
Copy link
Author

I just fixed a bug I noticed when the sidebar was closing. All should now be fine and I already tested the use of the fork both in the traditional way and with the new import way and both seem to work fine.

@umbe1987
Copy link
Author

@Turbo87 Did you have a chance to consider this PR? If there's anything not clear I'll be happy to clarify, or to make changes as you need.

@Turbo87
Copy link
Owner

Turbo87 commented Oct 10, 2018

sorry, been on vacation the past few days and driving to a conference right now. I'll try to have a look until next week.

Copy link
Owner

@Turbo87 Turbo87 left a comment

Choose a reason for hiding this comment

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

@umbe1987 first of all thanks for the PR! 🙏

the problem here though is that the PR mixes introducing a new build system, with shipping ES6 code, with implementing support for OpenLayers 5. if you think that we keep ES6 code in this project and use a compile step then please work on that first, before introducing new features. with the amount of things changing in this PR I don't feel comfortable merging it right now.

package.json Outdated
@@ -36,5 +40,8 @@
"gulp-uglify": "~3.0.0",
"gulp-zip": "~4.0.0",
"jshint": "^2.9.5"
},
"dependencies": {
"ol": "^5.2.0"
Copy link
Owner

Choose a reason for hiding this comment

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

this will add a dependency to all users, not just those that want the ol5 sidebar

Copy link
Author

Choose a reason for hiding this comment

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

You're totally right. Either I can remove it or move it in the devDependencies. I think the former would be better as sidebar focuses on other mapping libraries.

package.json Outdated
},
"devDependencies": {
"cssnano": "^4.1.3",
Copy link
Owner

Choose a reason for hiding this comment

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

what is this? why is this needed?

Copy link
Author

Choose a reason for hiding this comment

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

Sincerely I don't know how it got inside! Removing it makes no difference. So, out!

package.json Outdated
"test": "gulp lint"
"test": "gulp lint",
"start": "parcel ./examples/ol5.html",
"build": "parcel build --public-url ./ ./js/ol5-sidebar.js"
Copy link
Owner

Choose a reason for hiding this comment

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

we already use gulp for the basic build stuff. why do we need parcel?

Copy link
Author

Choose a reason for hiding this comment

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

Well, I used it because I knew how to use it and not gulp...

Hopefully, there seems to be this guide that says that it is possible "to compile ES6 and beyond into browser-compliant ES5". It seems to be using gulp-babel.

If you want I can dig into this and see what it can do to this regard.

package.json Outdated
@@ -21,10 +21,14 @@
"type": "git",
"url": "https://github.com/turbo87/sidebar-v2.git"
},
"main": "./examples/ol5.js",
Copy link
Owner

Choose a reason for hiding this comment

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

this is wrong for all other users that don't use the ol5 asset

Copy link
Author

Choose a reason for hiding this comment

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

That is definitely something I must remove! Sorry.

@@ -0,0 +1,141 @@
// JS imports
import Control from 'ol/control/Control';
Copy link
Owner

Choose a reason for hiding this comment

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

as I mentioned before this is invalid ES5 code and should not be shipped in the current state

Copy link
Author

@umbe1987 umbe1987 Oct 21, 2018

Choose a reason for hiding this comment

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

I know, but the example would not use this js but the one built (shipped in dist/ol5-sidebar.js). This is ES5 transpiled code, built with parcel (see the next comment where I say it can be done with gulp as well, although I still need to test it).

This should be there otherwise no one could be able to use the sidebar without using the entire ol library, (which version 5 of OL is stressing not to do), and would force OL5 compliant app to be rewritten from scratch to include the entire ol package (e.g. new Sidebar instead of new ol.control.Sidebar). And this is basically why i made this PR.

@umbe1987
Copy link
Author

umbe1987 commented Oct 21, 2018

@Turbo87 Thanks for taking the time to review this PR.

I replied to all your comments and I am writing here a summary.

I know the PR comes with lot of stuff, but I could make it clear saying that the only thing i really wanted to implement was to rewrite the "ol" js as a ES6 module, to guarantee OL5 compatibility.

As for the build process, I explained I used parcel because I simply didn't know how to transpile and build with gulp. Of course, this is something I had to consider, but I neglected it because I mainly focus on providing OL5 compatibility.

I guess I could spend some time to try implementing the build with gulp (mayb trying gulp-babel), removing the necessity of parcel and make another PR. I will keep the ES6 sidebar code as is because it is working and it was my main code to provide.

What do you think? If you are fine with it, feel free to reject this PR and I'll move on with providing another without parcel.

One last thing: I am not an expert programmer so any suggestion from your side (especially regarding gulp) is very welcome! 😸

@Turbo87
Copy link
Owner

Turbo87 commented Dec 7, 2018

What do you think? If you are fine with it, feel free to reject this PR and I'll move on with providing another without parcel.

as I said above, my goal for now is to keep this repo relatively simple and only include ES5 code. I'm okay with moving towards a solution where we offer ES5 and ESlatest and CJS files, but that shouldn't happen in a PR that implements support for ol5, it should be a dedicated PR.

severinstrobl and others added 2 commits April 30, 2019 11:16
OpenLayers 5 is implemented as a set of ES modules, requiring
major changes to the sidebar. Depending on how OL5 is used, the
sidebar will either be used as an ES module as well, or, in case the
full build of OL (ol.js) is used, a version compiled via webpack for
direct usage in a browser environment is required.
Reworked integration of OL5 support.
@severinstrobl
Copy link
Contributor

The updated pull request contains some modifications trying to integrate the OL5 support better with the other versions of the sidebar.
@Turbo87 Due to the fundamentally different nature of OL5 based on ES modules the sidebar code also has to be handled differently, but this is closer to what I feel you have in mind. Do you think this is acceptable for merging?

@umbe1987
Copy link
Author

@Turbo87
As this is PR getting pretty old (OpenLayers has now moved to version 6), would the improvements introduced by @severinstrobl be good enough to make this PR finally acceptable or do you think it would be better to close and rethinking it?

@Turbo87
Copy link
Owner

Turbo87 commented Nov 21, 2019

I'm still not sure why we need all of these changes. It looks like #156 achieved ol5/6 compatibility with much less changes 🤔

@severinstrobl
Copy link
Contributor

The changes in #156 are indeed minimal and are sufficient to use OpenLayers in the traditional way via the full JS build, while the modern and recommended way relies on ES modules. So IMHO in order for the sidebar to also be usable in more complex applications, the changes introduced in this PR are mandatory.

@umbe1987
Copy link
Author

To add to what @severinstrobl correctly said, since the advent of OpenLayers v5, many modern application based on OL has adopted the modern ES module import to avoid importing the whole OL library, hence decreasing the size of the final application in production.

Before this introduction, the size of the OL library was a major CON with respect to other alternatives (e.g. leaflet).

As it stands, the sidebar forces to include the entire OL build. This PR would make it possible to use the Sidebar with only the OL modules that it requires instead, still preserving the compatibility for the other libraries as it is now.

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

Successfully merging this pull request may close these issues.

None yet

3 participants