1

在我的应用程序中,我在仪表板上有一张巨大的地图,并且在加载 ajax 内容时我正在放置标记。每个标记都有专门设计的信息框,其中我有一个包含两个类的链接:

  1. 工具提示
  2. 花式盒子

在鼠标悬停时,我希望工具提示打开,在鼠标移出时,我希望它关闭,点击时我希望有三件事:

  1. 要关闭的信息框
  2. 要打开的fancybox
  3. 要关闭的工具提示

问题是,在鼠标悬停和鼠标移出时,工具提示按预期运行,但是当我单击链接时,信息框关闭,花式框打开但工具提示没有关闭,它失去了父连接并且永远不会关闭。

这是我的代码:

        var infowindow_options = {
            content: '...<a class="bind_tooltip">...</a>...',
            disableAutoPan: false,
            maxWidth: 0,
            alignBottom: true,
            pixelOffset: new google.maps.Size( 10, 10 ),
            zIndex: null,
            boxClass: 'info_window',
            closeBoxMargin: '10px 10px 0 0',
            closeBoxURL: 'http://www.google.com/intl/en_us/mapfiles/close.gif',
            pane: 'floatPane',
            enableEventPropagation: true,
            infoBoxClearance: '10px',
            position: mrkr.position
        };
        google.maps.event.addListener( mrkr, 'click', function() {
            infowindow ? infowindow.close() : '';
            infowindow = new InfoBox( infowindow_options );
            infowindow.open( map );
            return false;
        } );
        google.maps.event.addListener( map, 'click', function() {
            if( infowindow ) {
                infowindow.close();
                $( '.bind_tooltip' ).tooltip( 'close' );
            }
            return false;
        } );
        $( document ).tooltip( {
            items: '.bind_tooltip',
            content: function() {
                return $( this ).parent().find( '.tooltip' ).html();
            },
            position: {my: 'left top+10', at: 'center center'}
        } );

我也收到此错误:

错误:无法在初始化之前调用工具提示上的方法;试图调用方法“关闭”

4

2 回答 2

0

在脚本中的其他任何地方使用它之前初始化工具提示。你最好在脚本的开头这样做。

    var infowindow_options = {
        content: '...<a class="bind_tooltip">...</a>...',
        disableAutoPan: false,
        maxWidth: 0,
        alignBottom: true,
        pixelOffset: new google.maps.Size( 10, 10 ),
        zIndex: null,
        boxClass: 'info_window',
        closeBoxMargin: '10px 10px 0 0',
        closeBoxURL: 'http://www.google.com/intl/en_us/mapfiles/close.gif',
        pane: 'floatPane',
        enableEventPropagation: true,
        infoBoxClearance: '10px',
        position: mrkr.position
    };
    google.maps.event.addListener( mrkr, 'click', function() {
        infowindow ? infowindow.close() : '';
        infowindow = new InfoBox( infowindow_options );
        infowindow.open( map );
        return false;
    } );


    $( document ).tooltip( {
        items: '.bind_tooltip',
        content: function() {
            return $( this ).parent().find( '.tooltip' ).html();
        },
        position: {my: 'left top+10', at: 'center center'}
    } );

    google.maps.event.addListener( map, 'click', function() {
        if( infowindow ) {
            infowindow.close();
            $( '.bind_tooltip' ).tooltip( 'close' );
        }
        return false;
    } );
于 2014-02-02T05:32:13.050 回答
0

一开始初始化工具提示并没有解决我的问题。所以我用这种方式解决了这个问题。我之前添加了一段代码,当点击地图时,infowwindow 应该关闭。这就是为什么我失去了我的 infowwindow 参考。所以删除自动关闭解决了我的问题。

于 2014-02-03T06:46:38.123 回答