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

Canvas shifts if map dragged to right #8

Open
michelwehrli opened this issue Jul 7, 2016 · 5 comments
Open

Canvas shifts if map dragged to right #8

michelwehrli opened this issue Jul 7, 2016 · 5 comments

Comments

@michelwehrli
Copy link

If you drag this map to the right, at some point the canvas shifts to the following left map.
Is there a way to prevent this behavior?

@michelwehrli michelwehrli changed the title Canvas shift if map dragged to right Canvas shifts if map dragged to right Jul 7, 2016
@donmccurdy
Copy link

Is this the same issue seen when panning the 2D demo to the east? When the top-left corner of the canvas crosses the international dateline, the red square disappears:

3f5e4df6-9380-4454-9fe4-b7fcf0de103a-73672-0000b7120e335917

I'm not very familiar with the projection math, but you can add a hack to work around this, modifying these lines in the demo as follows:

var topLeft = canvasLayer.getTopLeft();
var offset = mapProjection.fromLatLngToPoint(topLeft);
if (topLeft.lng() > 0) {
  offset.x = offset.x - 256;
}
context.translate(-offset.x, -offset.y);

Not a great fix... i'll keep looking at this. :/

@michelwehrli
Copy link
Author

Yes it is, this is exactly what happened in my demo (which I fixed now btw).

I added your work around and it seems to work as long as you don't zoom out too much. (https://wehrli.me/canvaslayer/)

Maybe I just limit the top 3 zoom levels or so... Let me know when you find the solution, I will also look into this once more as soon as I have time.

@brendankenny
Copy link
Owner

yeah, unfortunately the discontinuity is fundamentally difficult to work around. There are some brute force approaches, though, like just rendering everything twice, once with an offset to keep it to the left and then one two keep it to the right. Usually demos using canvaslayer are pixel-fillrate-limited, so the performance hit isn't too bad since the vast majority of the sprites (or whatever) are offscreen and so never make it to the pixel shader stage.

(if you do everything just twice, however, you do have to limit how far you can zoom out depending on the map container's size and aspect ratio, otherwise you might need to render three or more times :)

If on the other hand you're visualizing mostly local-scale data, you can also hack around the problem by just limiting zoom and how far the user can pan.

@pjsg
Copy link

pjsg commented Aug 16, 2017

In my app, I have to be able to deal with zoomed-out maps -- I've been wondering whether to just attach the canvas multiple times to the map (one per duplication of the world). However, this doesn't really work very well when you are zoomed in near the international date line....

@pjsg
Copy link

pjsg commented Aug 19, 2017

Actually, I just fixed my problem as I'm computing the color based on the latlng of the pixel. In my case, the longitude may exceed 360 (or more) but it is continuously increasing to the right.

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