mickk80
mickk80

Reputation: 11

Show and Hide info window on Google Map Icons V3

I have a site i am working on and i would like to have the option where they can click on a rig name and then it will show the info window. The icons would be on show all the time but can be clicked on through the icon or side bar.

I have tried to solve this but i am having no luck.

Here is the test link with the code in source.http://excalibur.3peaksmedia.com/excalibur-rig-locator.asp

Any help appreciated.

Thanks Mike

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);
      });
    }

Upvotes: 1

Views: 1033

Answers (1)

levi
levi

Reputation: 25121

You can use google.maps.event.trigger to trigger a click event on a marker (which will cause the associated info-window to open). Example:

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

Upvotes: 1

Related Questions