B Seven
B Seven

Reputation: 45943

Using Javascript Google Map API V3, how to set click even for map, but not for markers?

Here's the functionality I am looking for:

  1. When you click on the marker, the marker info shows up.
  2. When you click on the map in the background, it takes you to a big version of the map. I can create that page on a separate URL.

How do you create the click events for the above?

Also, how do you disable the pan functionality? I tried panControl: false but that didn't seem to do anything.

Upvotes: 0

Views: 134

Answers (1)

duncan
duncan

Reputation: 31912

panControl just removes the pan control thing that normally appears in the top-left corner, it doesn't prevent the user actually being able to pan the map. You probably want to set draggable:false

For the click events, you do something like:

var infowindow =  new google.maps.InfoWindow({
    content: 'Hello World!'
});

google.maps.event.addListener(marker, 'click', function() {
    infowindow.open(map, this);
});

google.maps.event.addListener(map, 'click', function() {
    document.location.href = "bigmap.html";
});

Upvotes: 1

Related Questions