ol-ext icon indicating copy to clipboard operation
ol-ext copied to clipboard

Overlapping of overlay in Fixed popup

Open Bahaa-Fadhil opened this issue 2 years ago • 1 comments

I have come to the problem where I have several overlay popup elements that are close to each other, and since all overlays are created by the same function, and use the same div ID, each of them is located on different boxes, so they overlap each other. Is there any way to calculate where each overlay is located in the map and possibly determine the positioning for each of them separately according to where they are located in the map

Is there any way to avoid the overlay popup overlapping each other ?

See the attached illustration screenshot! overlay_overlapping

image

Bahaa-Fadhil avatar Aug 10 '22 13:08 Bahaa-Fadhil

You have to look by yourself at the position of the elements to prevent collisions. Offset properties on the popup element lets you know where it is placed.

const rect = [
  popup.element.offsetLeft, 
  popup.element.offsetTop, 
  popup.element.offsetLeft + popup.element.offsetWidth, 
  popup.element.offsetTop + popup.element.offsetHeight
]

The, you can move them each others to prevents overlaps. Use popup.getPixelPosition and popup.setPixelPosition to move the popups. You have to look at changes when the popup is moved or when the window resize.

You can also check for click on a popup to change its zIndex and have it on top of the other (they still overlaps buts the selected one is visible on top), more simple / less computation. That's what I use, see https://codepen.io/viglino/pen/MXYmxZ

Viglino avatar Aug 11 '22 07:08 Viglino