Calling Fancybox from Event Listener in Google Maps Instead of Default Infowindow

社会主义新天地 提交于 2019-12-11 07:29:55

问题


I'm looking to replace the default Google Maps API InfoWindow with a Fancybox overlay.

Version

Google Maps API 3.0

Goal

Replace the default Infowindow with a Fancybox popup

Use Case

  1. Google map is loaded up in full screen (100% by 100%)
  2. Markers are placed onto the map
  3. User clicks on a marker and is shown a Fancybox popup that overlays the map
  4. User clicks on "X" in the top right hand corner of the Fancybox to close it

I'm at a loss as to how best to tackle this. Is it easiest to call Fancybox using the addListener event handler, passing in the marker as a parameter? If so, how would any of you recommend doing this?

For example:

google.maps.event.addListener(marker, 'click', function(){
    // Call Fancybox, but how?
});

Thank you in advance,

Graham Kennedy


回答1:


I've found that the best way to go about this is to pass in your content manually with Fancybox's href method. Works like a charm for me.

function addMarker(data) {

    // build the window contents
    var contentForBox = data;

    google.maps.event.addListener(marker, 'click', function() {

        $.fancybox({
            href: contentForBox
            // other options
        });


    });
}


来源:https://stackoverflow.com/questions/4801488/calling-fancybox-from-event-listener-in-google-maps-instead-of-default-infowindo

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