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

Support for crossing the date line (anti-meridian) for polylines and polygons #553

Open
schloerke opened this issue May 25, 2018 · 7 comments

Comments

@schloerke
Copy link
Contributor

Original reference from #550

Leaflet.Antimeridian

See this plugin that could be used with leaflet: https://github.com/briannaAndCo/Leaflet.Antimeridian

Normal leaflet (from plugin README)
image

With anti-meridian plugin: (from plugin README)
image

While this is typically something that would be better for leaflet.extras, I believe this is a VERY common situation and should be apart of the core leaflet R package.

Bad Example

The polygon should be over the Atlantic ocean, not all of Eurasia.

library(leaflet)
leaflet() %>% 
  addTiles() %>% 
  addPolygons(c(140.0, -120.0, 170.0), c(20, 50, 70))

image

@tim-salabim
Copy link
Contributor

Without having had a look at the plugin, does it also work for raster images? See the first ever mapview issue r-spatial/mapview#6

@schloerke
Copy link
Contributor Author

I don't believe so.

It should be possible to adjust the raster to have longitudes larger than +- 180. This is Leaflet.js's suggested method (The requirement of true is no longer needed.)

Doing the adjustment with polyline...

library(leaflet); 
leaflet() %>% 
  addTiles() %>% 
  addPolygons(c(140.0, -120.0 + 360, 170.0), c(20, 50, 70))

image

This R package implements adjusting a raster to wrap from [0, 360] instead of [-180, 180]. (Even with a comment to an existing issue!)

@tim-salabim, Would either of these work?

@tim-salabim
Copy link
Contributor

@schloerke thanks for the quick reply. Unfortunately, the suggested adjustment does not work with rasterImages. The solution with crop and shift is close, but not optimal. I'll have a closer look again... Sorry to hijack this!

@schloerke
Copy link
Contributor Author

Np! I've seen this "feature" issue multiple times now. Thought I'd formalize it into an issue.

Would be interesting to try an treat it as a "set-able" line for polyline and polygons. Would not need to force the wrapping to occur at -180 or at 0. Could easily be done with any other value, like 42, which would cause the range to be [42, 42 + 360].

@jmlondon
Copy link

jmlondon commented May 30, 2018

Thanks for keeping this topic moving forward. For those of us who regularly work in the Pacific, it will be great to have a straightforward workflow in place. Down the line, I would be happy to contribute a vignette with example code and workflow best practices when dealing with the anti-meridian issue.

@schloerke
Copy link
Contributor Author

Linking to raster issue: #225

@rjwicks
Copy link

rjwicks commented May 28, 2020

Original reference from #550

Leaflet.Antimeridian

See this plugin that could be used with leaflet: https://github.com/briannaAndCo/Leaflet.Antimeridian

Normal leaflet (from plugin README)
image

With anti-meridian plugin: (from plugin README)
image

While this is typically something that would be better for leaflet.extras, I believe this is a VERY common situation and should be apart of the core leaflet R package.

Bad Example

The polygon should be over the Atlantic ocean, not all of Eurasia.

library(leaflet)
leaflet() %>% 
  addTiles() %>% 
  addPolygons(c(140.0, -120.0, 170.0), c(20, 50, 70))

image

Thanks for keeping this topic moving forward. For those of us who regularly work in the Pacific, it will be great to have a straightforward workflow in place. Down the line, I would be happy to contribute a vignette with example code and workflow best practices when dealing with the anti-meridian issue.

My team is running into this issue. Are you aware of any effort to fix it and integrate it with the core leaflet R package.

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

No branches or pull requests

4 participants