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
Problem with polylines/polygons over the date line #82
Comments
Hi, unfortunately Leaflet doesn't yet handle crossing of W180 automatically - the current workaround is to change the definition of points that are not drawing properly e.g. from this: This way Leaflet will know that the point should be drawn beyond the -180:180 interval and not automatically clamped inside (what But I'll try to figure out how to manage this automatically. |
Thanks Vladimir, we really appreciate all your work on Leaflet. |
Is there an automatic way to do this yet? Or is the above workaround still required? |
Is there a way to just have the polygon duplicated so it can be seen at two places at once. This is rather than having one object being shown and jumping around the world. This sucks when you create a object along the date line, then scroll a little, the object will disappear by jumping to another world. I'd rather it just exist in both worlds. |
I really could use the replicated feature capability described by masterofping. If this doesn't exist, I'm going to either 1) create two replicates of any feature I add to a geojson layer (one +360 and another -360 from the original feature) and add them to the same geojson layer, or 2) create a new feature class that extends layergroup or geojsonlayer and handles the replication to adjacent worlds automatically. #1 would happen in my application code. #2 would be an extension to the Leaflet library that could be ported in to the main lib. The most important thing is that mouse events and other interaction hooks for the original feature must also work for the replicates. I know there's been talk of development better dateline handling within leaflet but wonder when that might happen or what that might actually be. |
Anyone has any idea how google does this? They do it awesome.... I dk how, but it seems right. Try yourself with var p1 = new google.maps.LatLng( -10, 170); pg.setMap(map); When you zoom out.. you can see multiple polygons along with repeated maps. |
Not sure how Google does it but we would love to see the same behavior in Leaflet. At the moment when we create any polylines that cross over the date line (e.g. Honolulu to Tokyo), when we add the second polypoint (Tokyo) the polyline is connecting "the long way around" the world and goes east instead of taking the direct route going west. Another unintended behavior of the current code is that when we click on the map and open a popup to the east of the date line (Hawaii), then click again to the west of the date line (Japan) the map scrolls to the right a full cycle and the popup opens not where it was clicked but where the map thinks it was clicked a whole world away to the east. We are investigating a hack to get it to work for our project but we would much rather see the same behavior as Google Maps where the world is repeated and the lines of lng never go above/below +/-180. |
Any chance this feature is actively being worked on? If not, are there any updates to the best way to implement a workaround for this issue? |
Have you tried the workaround given above? Most likely nothing is updated in this area since then. |
Even if you do the workaround, unless you manually duplicate objects they will disappear as you scroll the map across the anti-meridian. Also need to get L.Bounds to be able to cross the anti-meridian, including the ability to do a map.fitBounds to a bounds that crosses the anti-meridian. Do you have an estimate of when this will be available? I really need this, and I'm about to write a bunch of manual code to get around this problem. Would hate to have your solution come out just when I finish duplicating that effort. Alternatively, if you have not started work on it, I can help write some of the code. |
I removed LatLng wrapping/clamping by default alltogether (there's now an explicit |
I very much enjoy using Leaflet. I was wondering if there is any other work done on this issue other than the work around. Keep up the good work! 😄 |
It was a while ago so I’m not sure, but I think they fixed this issue. —wm
|
i'm sorry for my english. there is a function that i found on leaflet 0.7.7 ("wrap" Conversion Methods). it has made me solved this problem with some additional code. but i can't run this function again on the newest leaflet (currently 1.0.1). i don't know why.. so for a while, i just use leaflet 1.0.1 but i change little bit code on "wrap function" (use leaflet 0.7.7 code). let me know if I missed anything or had some incorrect code for "wrap" methods on the newest leaflet. or maybe "wrap" methods has been removed or changed? |
I'm getting this with leaflet 1.0.1. Looks similar to previous screenshots of this issue: topojson/topojson#242 Here's a full explanation of why it is happening: topojson/topojson#242 (comment) I don't need antarctica so the workaround in that issue worked for me. |
I'm sorry, but I'm confused. @mourner said this:
What I understood from this that I shouldn't need any work around. But I still experience the issue: So I tried doing the workaround he suggested:
Recreating this "using d3 with Leaflet" tutorial, I had the similar part of code, but with dynamic values, so what I just tried adding the third This is that specific part of my code
Here's the [gist](https://gist.github.com/chrisregner/dff1bd7a6fa053fd898d1ef70c451c88#file-map-js-L64( of my code (anchored to that particular line). So my question is, how do I correctly apply the work around in my case? I can't use what @callumacrae has suggested because I want to keep Antartica. Thanks. |
For anyone who'll need it. I got a solution from topojson/topojson#242 (comment). |
The solution I came up with was to first collect all the LatLngs I was going to display in all objects and create a LatLng Mapper out of them. Then as I build the Leaflet objects I run the latlng through this mapper to decide if and how to convert the latlng before giving it to the leaflet object. Below is my solution in Typescript. I have not extensively tested this but it passes my basic test cases so far.
|
Hi guys, when a polyline straddles the W180 line of longitude, crossing from one side to the other, the polyline does not continue on the other side of the W180 line, but is drawn back on the other side of the "current iteration" of the world.
Here is an example, polyline has 3 points draw from left to right. The first two polypoints are drawn on the left side of the W180 line, but the third which is meant to be just past the W180 line is not drawn to the right of the W180 line. It is being drawn back to the left where the current world begins:
http://fswidgets.com/beta/leaflet_test.html
The text was updated successfully, but these errors were encountered: