Openlayers: Popups Compatible with Bootstrap 4/Tether

Created on 25 Jan 2017  路  3Comments  路  Source: openlayers/openlayers

Bootstrap v4 uses tether for positioning popovers, such as in https://openlayers.org/en/latest/examples/overlay.html. Tether requires manually triggering a call to its position function, since it uses transform: ... css instead of left and top.

https://v4-alpha.getbootstrap.com/components/popovers/

Essentially this can be accomplished with a postrender listener, as below. However something in the OpenLayers internals would be nice.

          postrender: function(e){
            var popover = $("#popup").data("bs.popover");
            if(angular.isDefined(popover))
            {
              var tether = popover._tether;
              if(angular.isDefined(tether))
              {
                tether.position()
              }
            }
          }

Most helpful comment

The release version of Bootstrap v4 uses popper.js for positioning instead of tether. The corresponding position() function in popper is update()/scheduleUpdate().

My code looks like this:

map.on('postrender', function(e) {
    let popover = $('#popup').data('bs.popover');
    if(!popover) return;
    let popper = popover._popper;
    if(!popper) return;
    popper.scheduleUpdate();
});

PS: Your postrender fix helped me a lot, thanks @pjdufour !

All 3 comments

The release version of Bootstrap v4 uses popper.js for positioning instead of tether. The corresponding position() function in popper is update()/scheduleUpdate().

My code looks like this:

map.on('postrender', function(e) {
    let popover = $('#popup').data('bs.popover');
    if(!popover) return;
    let popper = popover._popper;
    if(!popper) return;
    popper.scheduleUpdate();
});

PS: Your postrender fix helped me a lot, thanks @pjdufour !

Closing due to lack of activity.

Thank you very much _v1r0x_ for posting this solution!

Was this page helpful?
0 / 5 - 0 ratings