谷歌地图标记 - 链接到div类

时间:2015-06-12 11:21:05

标签: javascript google-maps url google-maps-api-3 marker

我需要在Google地图标记上添加一个链接。它适用于外部URL(http://..。)但它没有div链接。 当我们点击一​​个标记时,我希望它打开一个带有模态效果的div。

以下是要打开div的HTML:

<div class="modal faune">     
  <div class="barre_gallery">                                
        <img alt="" class="close" onclick="$.fn.custombox('close');" src="img_content/croix.png" width="30"/>
        <h1>Test</h1>    
   </div>    

    <p>Paragraphe test</p>

</div> 

这是JS:

var gmarkers1 = [];
    var markers1 = [];
    var infowindow = new google.maps.InfoWindow({
        content: ''
    }); 

markers1 = [

     ['4', "Les ânes de Pontisse",  50.692001,  5.639683, 'faune', 'content/pictos/picto_faune.png', '$(".modal.faune")'],

     ]

function addMarker(marker) {
            var category = marker[4];
            var title = marker[1];
            var pos = new google.maps.LatLng(marker[2], marker[3]);
            var content = marker[1];
            var icon = marker[5];
            var url = marker[6]

marker1 = new google.maps.Marker({
                title: title,
                position: pos,
                category: category,
                map: map,
                icon : icon,
                url: url,
});

gmarkers1.push(marker1);

// Marker click listener
    google.maps.event.addListener(marker1, 'click', function() {
                window.location.href = this.url;
               this.addClass("list-group-item blur");
            });         

}

你有什么想法吗?谢谢!

2 个答案:

答案 0 :(得分:0)

window.location.href = $(".modal.faune")无法上班。如果它是一个外部href或div链接(例如每个标记上的布尔属性),你需要有一些逻辑来解决。

if (external link)
   window.location.href = this.url;
else 
   this.url.trigger('click');

答案 1 :(得分:0)

如何从标记事件侦听器调用模态?

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

    Custombox.open({
        target: '.faune',
        effect: 'fadein'
    });
    e.preventDefault();

});   

编辑:知道你使用的模态以及帮助你是很好的。

假设http://dixso.github.io/custombox/这是您正在使用的模式。