在Google Map Icons V3上显示和隐藏信息窗口

时间:2014-01-20 21:15:29

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

我有一个我正在处理的网站,我希望有一个选项,他们可以点击一个工具名称,然后它将显示信息窗口。图标将一直显示,但可以通过图标或侧栏单击。

我试图解决这个问题,但我没有运气。

以下是源代码中的代码的测试链接。http://excalibur.3peaksmedia.com/excalibur-rig-locator.asp

任何帮助表示感谢。

由于 麦克

function load() {
      var map = new google.maps.Map(document.getElementById("map"), {
        center: new google.maps.LatLng(53.705027, -110.470963),
        zoom: 6,
        mapTypeId: 'roadmap'
      });
      var infoWindow = new google.maps.InfoWindow;

      // Change this depending on the name of your PHP file
      downloadUrl("phpsqlajax_genxml3.php", function(data) {
        var xml = data.responseXML;
        var markers = xml.documentElement.getElementsByTagName("marker");
        for (var i = 0; i < markers.length; i++) {
          var name = markers[i].getAttribute("name");
          var address = markers[i].getAttribute("address");
          var inventory = markers[i].getAttribute("inventory");
          var layout = markers[i].getAttribute("layout");
          var specs = markers[i].getAttribute("specs");
          var url = markers[i].getAttribute("url");
          var type = markers[i].getAttribute("type");
          var point = new google.maps.LatLng(
              parseFloat(markers[i].getAttribute("lat")),
              parseFloat(markers[i].getAttribute("lng")));
          var html = "<div class='balloon' style='width:190px; height:140px; font-family:Eau;'>" + "<b>" + name + "</b> <br>" + address + "<br>" + "> <a target=_blank href='/pdf/" + markers[i].getAttribute("inventory") + "'> Rig Inventory PDF</a> <br>" + "><a target=_blank href='/pdf/" + markers[i].getAttribute("layout") + "'> Rig Layout PDF</a> " + "<br>> <a target=_blank href='/pdf/" + markers[i].getAttribute("specs") + "'> Pump & Well Control Specs </a> <br>" + "> <a href='" + markers[i].getAttribute("friendlyurl") + "'>View Gallery</a>";
          var icon = customIcons[type] || {};
          var marker = new google.maps.Marker({
            map: map,
            position: point,
            icon: icon.icon,
            shadow: icon.shadow
          });
          bindInfoWindow(marker, map, infoWindow, html);
        }
      });
    }

    function bindInfoWindow(marker, map, infoWindow, html) {
      google.maps.event.addListener(marker, 'click', function() {
        infoWindow.setContent(html);
        infoWindow.open(map, marker);
      });
    }

1 个答案:

答案 0 :(得分:1)

您可以使用google.maps.event.trigger触发标记上的点击事件(这将导致关联的信息窗口打开)。例如:

$("#sidebarLink1").click(function(){ 
    google.maps.event.trigger(marker1, 'click');
});