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

Changes for Leaflet update to >1.* #6

Merged
merged 6 commits into from
Oct 23, 2017
Merged

Conversation

afirte
Copy link
Contributor

@afirte afirte commented Oct 19, 2017

@rvdkooy
Copy link
Owner

rvdkooy commented Oct 22, 2017

This PR breaks the demo in this repo and I can see why (the code is depending on 2 coords and you just pick the first one and continue from there)

Btw:
If I upgrade to the lastest version of leaflet, I don't need to change anything, it just works with 1.2.0.
So what does this PR fix?

TIP:

  • if you create a PR, please describe what it does (enhancement, bugfix, feature etc etc)

@afirte
Copy link
Contributor Author

afirte commented Oct 23, 2017

Idk, but it didn't just work for me, there's is a breaking change in a method, as you can see in the diff. That results in a null exception and, this change fixes that... at least in how it's used in AppShaping... let's talk more about it when you're back...

So if you check this link, you'll see what it fixes.

I thought the commit description was clear/simple enough... I'll add more thorough descriptions...

Also, running the demo with this update seems to work (i.e. I can produce straight lines with any JS errors), although I do get some other errors (404 for map PNGs)...

@rvdkooy
Copy link
Owner

rvdkooy commented Oct 23, 2017

if you get latest master, the demo will work with leaflet 1.2.0 (npm install first)

I think what the problem is:

there is a difference between creating straightlines with polylines and a polygons, both are possible!
image

the top one creates a polyline, the other a polygon

your change probably only works with the polygon, so I think you have to do some check with what you are dealing with

R

@afirte
Copy link
Contributor Author

afirte commented Oct 23, 2017

Just an observation... leaflet is not installable/upgradable via npm, it's just committed to the repository in example/js/leaflet.js... ?!???? so i have to copy the new version manually...

@afirte
Copy link
Contributor Author

afirte commented Oct 23, 2017

Good point, indeed it's not working with polygons...

The thing is that in AppShaping I don't have this error, because I've made a generic method (getLatLngsOuter) which does have proper checks, but obviously I couldn't reference AppShaping scripts in leaflet.straightlines repository...

@afirte
Copy link
Contributor Author

afirte commented Oct 23, 2017

Hey @rvdkooy , does it work alright now?

@@ -53,6 +53,10 @@
var currentLine = getLayerOfType(L.Polyline);
if (currentLine) {
var latLngs = currentLine.getLatLngs();

if (latLngs != undefined && latLngs.length === 1 && latLngs[0].constructor === Array) //then it's a nested array
Copy link
Owner

Choose a reason for hiding this comment

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

does Array.isArray not work?
it is supported from IE9 onward

this should work:

if (latLngs && latLngs.length === 1 && Array.isArray(latLngs[0]))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it would, but .constructor seemed like the most common way to test if the type is array... is it not good enough?

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 could use jQuery's $.isArray... is that better?

Copy link
Owner

Choose a reason for hiding this comment

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

Array.isArray is part of the ecmascript 5 spec, is safe to depend on that

jQuery is wrong because leaflet is not depending on jQuery, now I need to add jQuery as a depencency to make this work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, so should I just use Array.isArray?

Copy link
Owner

Choose a reason for hiding this comment

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

yep

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

@rvdkooy rvdkooy merged commit 6460553 into rvdkooy:master Oct 23, 2017
@rvdkooy
Copy link
Owner

rvdkooy commented Oct 23, 2017

version 2.0.0 is published on npm

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.

None yet

2 participants