Openlayers: Dynamic overlay positioning ("keep popup in map")

Created on 10 Jun 2014  路  4Comments  路  Source: openlayers/openlayers

It'd be useful if overlays would open in a direction which keeps them within the currently shown map viewport. I think this corresponds to the keepInMap property in OL2. This is in particular relevant as long as #2180 isn't possible.

A possible sketch would be:

  • The map is divided in compartments which define in which direction the popup open; e.g. if the referred element is in the top-left compartment, the map would open towards the bottom-right. There might be 1 to 3 compartment in each dimension. (There's different ways to do this, but this sounds relatively simple to me)
  • Allow to set automatic as possible ol.OverlayPositioning.
  • Allow to define number of overlay positioning compartments (1-3) per dimension. Default to x=3, y=2.
  • If the overlay is opened, a class (or two, one for each dimension) is set, depending on the chosen positioning, in order to choose the right bubble / offset etc. (I hope this is doable in pure CSS).

Does that make sense? Are there already other plans for this? Would you interested in a Pull Request with the above proposal?


Want to back this issue? Place a bounty on it! We accept bounties via Bountysource.

Most helpful comment

by using autopan we force the underlying map to move, is there any way pop should auto adjust its location. (like windows right click menu )(Because at the topmost corners of the map,where there is not enough space for popup to stay on maps, popups gets outside the maps.)

All 4 comments

We now have autoPan with #3256

by using autopan we force the underlying map to move, is there any way pop should auto adjust its location. (like windows right click menu )(Because at the topmost corners of the map,where there is not enough space for popup to stay on maps, popups gets outside the maps.)

I enabled autoPan , but the users logged it as a bug! They really disliked it.

  1. User places mouse/pointer to hover over a feature
  2. Hover causes a popup to display, but it's clipped - partially outside view so unreadable
  3. View pans until Popup is now inside view
    BUT User's pointer is no longer over the target feature. So the popup disappears (hover exit event)
    User has to chase the feature again to see the window.

A suggested solution would be for autoPan (or some other option) to move the popup window instead of pan the base view.

Something like this fiddle.
Its a poorly implemented reversal of ol.Overlay.panIntoView().
The real use case if for hover over features near the edge of the map.

Was this page helpful?
0 / 5 - 0 ratings