openlayers / ol2

OpenLayers v2 - deprecated!
Other
1.47k stars 771 forks source link

FramedCloud + restrictedExtent could play a bit nicer. #596

Open JDeuce opened 12 years ago

JDeuce commented 12 years ago

I have a map with bounds limited by restrictedExtent, and people are able to get a framed cloud popup with large height to open partially outside of the restricted Extents, causing it to be totally unusable (since the close button is hidden).

I'm filing this as a bug because I think OpenLayers should be opening the popup in a different orientation, since even though there are restrictedExtents, there is still available placements where the popup could be fully shown instead of partially hidden.

Here's a minimal jsfiddle showing the problem:

http://jsfiddle.net/VRWTw/

Note that you must click off the feature before clicking again to open a new popup.

Steps to open the popup normally:

  1. Load the fiddle
  2. Scroll the map so the feature is at the top of the viewport
  3. Click the feature
  4. Popup should display fully

Steps to open the popup so that it is blocked:

  1. Load the fiddle
  2. Scroll the map so the feature is at the bottom of the viewport
  3. Click the feature
  4. Popup should be partially hidden

Things to keep in mind:

The calculation for which direction the popup should open should be done against the remaining viewport after taking into account the 'paddingForPopups'.

JDeuce commented 12 years ago

I've traced through the code and believe I've found where it's making the decision about which orientation to open the popup:

https://github.com/openlayers/openlayers/blob/master/lib/OpenLayers/Popup/Anchored.js#L149

If we ignore paddingForPopups for now then a simple fix might be to check here if a restrictedExtent has been set, and if so, use that instead of the map extent.

Any thoughts?

JDeuce commented 12 years ago

I tried out the above patch earlier today. It appears to resolve the issue on my development site (unfortunately non-public).

I forked the jsfiddle here http://jsfiddle.net/v4bss/ with a new version of the javascript. Note that at the current time I could only host the updated javascript file publicly through my google site. I couldn't get the popup background images to host at the required paths there, so they currently aren't loading correctly. However the fiddle should still be sufficient to see how the popup reacts with the restricted extent.