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

In certain situations, closing the pane with information about an element moves the center of map to a different position #729

Open
micechal opened this issue Apr 17, 2014 · 15 comments

Comments

@micechal
Copy link

Steps to reproduce:

  1. Go to http://www.openstreetmap.org/#map=19/50.85551/20.47199&layers=D
  2. Move the map slightly in any direction
  3. Click on one of the nodes, for example the 45 house number
  4. Close the pane that opened on the left hand side
  5. Move the map in any direction or try zooming in/out

The map center seems to be a bit off after closing that pane, and it will stay so as long as you don't try to pan the map. Zooming out and in before trying to drag the map makes the map center stay in wrong position, resulting in weird zooming experience.

@tomhughes
Copy link
Member

I think this is a duplicate - sure there's another ticket for this somewhere.

@SomeoneElseOSM
Copy link

My fault - I mentioned on IRC that it might have been a duplicate of #629 , but should have said #634 (which is open, but not the same path to reproduce, although may be related).

@tomhughes
Copy link
Member

I don't really know what exactly it is I'm looking for here, but there didn't seem to be anything obviously wrong when I followed the steps described.

@micechal
Copy link
Author

You can clearly see the issue on this video I've just recorded:
https://youtu.be/Qj3ETy_bG2E
Skip to 0:32 to see how the problem looks like.

@tomhughes
Copy link
Member

Youtube is telling me that video is private.

@micechal
Copy link
Author

Ehh... Try it now.

@dracos
Copy link

dracos commented May 27, 2015

I have this happen to me all the time when using the OSM site, so I tried to help track it down. I think this is something to do with the multiple calls to update the state/hash when you close the sidebar, and it getting confused as to where the centre of the map is.

Here are my steps to reproduce:

  1. Go to http://www.openstreetmap.org/search?query=test#map=19/51.08844/-1.50910&layers=N (centred on the island in the river Test).
  2. Click first search result (River, Test, Test Valley).
  3. URL changes to http://www.openstreetmap.org/way/162828509 and then http://www.openstreetmap.org/way/162828509#map=18/51.08841/-1.50907&layers=N or similar (same centre, as you'd expect).
  4. Close search results. URL changes to http://www.openstreetmap.org/#map=18/51.08841/-1.50813&layers=N or similar (note the longitude changes to the East) but map jerks to be still showing centre of 51.08841/-1.50907 – the URL and the map now no longer match.
  5. Start panning the map, the map 'leaps' to be at these new hash co-ordinates immediately.

If you start the process at the end of step 3, i.e. load afresh http://www.openstreetmap.org/way/162828509#map=18/51.08841/-1.50907&layers=N and close the search results, the hashed co-ordinates do not change and so panning the map works fine.

Adding a catch to calls to replaceState shows that when you close the search results at step 4, replaceState is called three times, with:
#map=18/51.08841/-1.50813&layers=N
#map=18/51.08841/-1.51001&layers=N
#map=18/51.08841/-1.50813&layers=N

The second of these is what we want, and is what the map shows, just the URL ends up disagreeing. I tried investigating a bit further from the JavaScript, but am afraid I couldn't work it out, sorry. Hope that's helpful anyway!

@tomhughes
Copy link
Member

Yes I can do all that, but as fast as you fix it for one case you break it for two more.

On top of which is the fundamental problem that I don't understand which cases are supposed to move the map when the left side panel opens and which aren't. I don't think it ever moves for the right panel but for the left one I believe (it wasn't me that designed that but) that it is deliberate in some cases that the map adjusts.

Maybe @jfirebaugh or @samanpwbb has some insight into what the logic is supposed to be? Until I have a good grasp of what the desired result is it's hard to try and fix it...

@dracos
Copy link

dracos commented May 28, 2015

@tomhughes Sorry, I don't follow; I haven't mentioned the left side panel opening, the issue is when you close the side panel. If you do my step 1 and immediately close the search box, the map doesn't move. If you do my step 3 as a fresh page load and close the way box, the map does not move. It is only if you start with a search box, click a search result, then close the search box, that the map/URL gets confused, not doing the same thing as starting with step 3 afresh. So that seems like a clear bug to me, having the URL hash ever not matching the centre point of the shown map, and I'm not sure what problems fixing that particular instance would cause; it's certainly the only issue I get frequently using OSM. Sorry if I've misunderstood.

@tomhughes
Copy link
Member

@dracos You're talking about one specific example, but there are many different paths you can take which produce different results. What we need before trying to fix anything is a concrete specification of what the intended results are.

The reason the map sometimes moves back when you close the sidebar is that is sometimes moves when the sidebar opens, and when it does it needs to move back when the sidebar closes. If you just stop it moving back in this case you will probably break a case where it was meant to move back.

Extra complications come if you open the sidebar in a mode where the map is supposed (?) to move and then transition it to a mode in which it wouldn't normally have moved - should it move back immediately in that case? or only when you eventually close it.

The whole thing is a mess, and insanely fragile. I've attempted to fix it many times - some of those fixes and have been committed and some have been abandoned. I have now reached the stage where I am unwilling to touch it at all without some kind of clear specification of what the overall intended behaviour is.

@dracos
Copy link

dracos commented May 28, 2015

I hear you. I'm sure this isn't helpful, but I can't find an example where opening the left sidebar moves the map (and I agree with you, I also don't really see why there should be one). Starting with a normal map page (nothing in URL but location hash): opening History sidebar, doesn't move map (just clicking History sidebar and closing sidebar is a quick way to see the pan of this ticket). Export sidebar, doesn't move map. New note sidebar, doesn't move map. Search sidebar, doesn't move map. Directions sidebar, fits to bounds of direction lookup, not a "move" that needs resetting when sidebar closed (and it doesn't do that anyway). Query features, click feature, sidebar doesn't move map. Search results/query results - fitBounds of way/relation, again not related to sidebar.

When you go direct to a directions page, e.g. http://www.openstreetmap.org/directions?engine=osrm_car&route=53.479%2C-2.245%3B51.507%2C-0.128 it does pan the map out of the way of the sidebar; and then (correctly IMO) does nothing when you close the sidebar. So there's already precedent there. If you go directly to some other type of pages e.g. a way page, such as http://www.openstreetmap.org/way/168906294 – then the map pans out of the way of the sidebar, and closing that sidebar causes the issue of this ticket. Doing the same as directions and doing nothing upon sidebar closure seems okay to me, I don't expect the map to pan just because I've closed the sidebar (and indeed as you say, the right sidebar never does).

How about just trying never moving the map on sidebar closure, and seeing if anyone raises a bug? ;-) It sounds like that might simplify your code a little anyway. And this issue appears much more obvious. Thanks for your time and work on this, regardless!

@jfirebaugh
Copy link
Member

The way it's intended to work is that the map never visually changes position when sidebars open or close -- i.e. the visual appearance is the same as if the sidebars were "covering up" portions of the map. But since what's actually happening is that the width of the map container is changing, accomplishing this means that the center of the map (in Leaflet terms) does have to change. In other words: visually speaking the map is staying put, but programmatically speaking it's moving.

@tomhughes
Copy link
Member

Thanks for that @jfirebaugh - maybe I'll have a look at it during the hack day at SOTM-NY and see what I can do...

@HolgerJeromin
Copy link
Contributor

Perhaps it is easier to keep the map DIV in its size and let overlay the sidebar over the map. So the center leaflet is calculating does not change.
The few tile which will be downloaded but not shown under the sidebar would be a downside.

@jfirebaugh
Copy link
Member

@HolgerJeromin It's not easy to do that and still have the map controls move as expected. The scale control needs to move out of the way of the left sidebar, and the attribution and buttons need to move out of the way of the right sidebar.

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

6 participants