Disable point-of-interest information window using Google Maps API v3

前端 未结 7 815
忘掉有多难
忘掉有多难 2020-12-08 04:43

I have a custom map with an information bubble and custom markers. When I zoom into points of interest such as parks and universities appear and when I click an information

7条回答
  •  一个人的身影
    2020-12-08 04:47

    If you want the data without getting the InfoWindow HTML showing at all, you simply have to re-work the prototype of google.maps.InfoWindow:

    google.maps.InfoWindow.prototype.open = function () {
      return this; //prevent InfoWindow to appear
    }
    google.maps.InfoWindow.prototype.setContent = function (content) {
      if (content.querySelector) {
        var addressHTML = content.querySelector('.address');
        var address = addressHTML.innerHTML.replace(/<[^>]*>/g, ' ').trim();
        var link = content.querySelector('a').getAttribute('href');
        var payload = {
          header: 'event',
          eventName: 'place_picked',
          data: {
            name: content.querySelector('.title').innerHTML.trim(),
            address: address,
            link: link
          }
        };
        console.log('emit your event/call your function', payload);
      }
    };
    

提交回复
热议问题