How to hook into the “close infobubble” event in HERE maps Javascript API

浪尽此生 提交于 2020-02-08 07:05:26

问题


I can create infobubbles using the HERE maps Javascript API - eg from their documentation:

    function addInfoBubble(map) {
      map.set('center', new nokia.maps.geo.Coordinate(53.430, -2.961));
      map.setZoomLevel(7);

      var infoBubbles = new nokia.maps.map.component.InfoBubbles(),
        TOUCH = nokia.maps.dom.Page.browser.touch,
        CLICK = TOUCH ? 'tap' : 'click',
        container = new nokia.maps.map.Container();

      container.addListener(CLICK, function (evt) {
        infoBubbles.openBubble(evt.target.html, evt.target.coordinate);
      }, false);
      map.components.add(infoBubbles);
      map.objects.add(container);

      addMarkerToContainer(container, [53.439, -2.221],
        '<div><a href=\'http://www.mcfc.co.uk\' >Manchester City</a>' +
        '</div><div >City of Manchester Stadium<br>Capacity: 48,000</div>');

      addMarkerToContainer(container, [53.430, -2.961],
        '<div ><a href=\'http://www.liverpoolfc.tv\' >Liverpool</a>' +
        '</div><div >Anfield<br>Capacity: 45,362</div>');
    }
    function addMarkerToContainer(container, coordinate, html) {
      var marker = new nokia.maps.map.StandardMarker(
        coordinate,
        {html: html}
      );
      container.objects.add(marker);
    }

I would like to hook into the close event of the infobubble. I realise I could use jQuery to find the span that contains the close button (examining the markup, I believe it has the class nm_bubble_control_close) and do something when this is clicked. However I thought there would be a built-in event that I could use.

Does anyone know if there is a built-in event that fires when the infobubble is closed? I can't find anything in the documentation.


回答1:


AFAIK there is no built-in event, there's also no related property which may be observed.

Possible workaround: override the built-in close-method with a custom function:

  container.addListener(CLICK, function (evt) {
    var b = infoBubbles.openBubble(evt.target.html, evt.target.coordinate),
        c = b.close;
    b.close = function(){
      //do what you want to
      alert('bubble will be closed');
      //execute the original close-method
      c.apply(b)
    }
  }, false);



回答2:


The InfoBubbles component has a property "openBubbleHandles". It's an OList you can observe to see when bubbles are opened (i.e. added to the list) or closed (removed from the list).




回答3:


For the current HERE Javascript API version (3.x) the working solution can be found here:

HERE Maps - Infobubble close event / hook



来源:https://stackoverflow.com/questions/31781884/how-to-hook-into-the-close-infobubble-event-in-here-maps-javascript-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!