2016-07-07 202 views
1

在这里,我只想信息框 - 无箭头:如何删除地图上的信息窗口箭头?

Here I only want the info box - without arrow.

<info-window id="foo-iw" position="AK"> 
<div ng-non-bindable> 
    <div class="header" ng-click="expand()"> 
     <span>Alaska <i class="caret"></i> 
     </span> 
    </div> 
</info-window> 
+0

有很多解决方案可以使用:[javascript](http://stackoverflow.com/a/15522574/5995040),使用[maps utility](http://code.google.com/p/google (https://groups.google.com/forum/#!topic/google-maps-api/Zpmtmy6Zabk)创建自定义infoWindow和一些[第三方替代方案](https://groups.google.com/forum/#!topic/google-maps-api/Zpmtmy6Zabk) –

回答

0

您可以用jQuery做到这一点,以隐藏绘制箭头的div。 只需添加以下代码到您的JS文件:

// Hide infowindow arrow/marker pointer 
setTimeout(function() { 
    var arrow_div = $(".gm-style-iw").prev(); 

    $("div:eq(0)", arrow_div).hide(); 
    $("div:eq(2)", arrow_div).hide(); 
}, 2000); 
0

这里的香草JS,无插件的解决方案:

// Find where you actually open the infowindow. 
infowindow.open(map); 

// Paste the following: 

// In OP's case, the element ID is actually 'foo-iw', as they're using a template. 
el = document.getElementById('infowindow-content').parentNode.parentNode; 

el = el.previousElementSibling || el.previousSibling; 
el.children[0].setAttribute('class', 'hidden'); 
el.children[2].setAttribute('class', 'hidden'); 
// And of course, in CSS, have a generic .hidden{display:none;} rule. 

这需要你打开信息窗口后运行,因为谷歌地图做了一些DOM更改,如果您太早使用.parentNode,则会遍历HTML的错误区域,尝试查找要处理的元素。如果你为你的infowindow定义了一个自定义的HTML模板,那么情况尤其如此...... GM将采取它并在DOM中转移它。


反正,使用上述方法可以为所有信息窗口元件设置类,像这样:

el.setAttribute('class', 'infoWindowEntireBackground'); 

el.children[0].setAttribute('class', 'infoWindowArrowShadow'); 
el.children[2].setAttribute('class', 'infoWindowArrow'); 
el.children[1].setAttribute('class', 'infoWindowBGShadow'); 
el.children[3].setAttribute('class', 'infoWindowBG'); 

警告:不限如果Google更改infowindow元素的结构,这种DOM遍历方法将会中断nts与未来版本。在这种情况下,无论您是注意它(愚蠢)还是只运行特定版本的GM脚本(这会为您带来其他优势,即控制权)。

仅供参考,有infowindow自定义插件,如infobox,snazzy-info-window,但据我所知大多数提供没有箭头隐藏功能。

其他选项:infobubble有一个箭头大小属性等等,如果将其设置为0px,则该箭头将被隐藏。