Note: I can't post a live link to my web app because the app is not
live yet. It is on my laptop running on localhost. With that preamble
out of the way, my question is, "Can I add event listeners to overlay
ImageMapType?"

Here is the background -- I am trying to add infowindow click listener
to an ImageMapType layer in Gmaps V3. My code is straightforward --

// Initialize the map
var map = new google.maps.Map(document.getElementById("map"), {
    "zoom"      : 10,
    "center"    : new google.maps.LatLng(43.13, -89.33),
    "mapTypeId" : google.maps.MapTypeId.TERRAIN
});

// Create an ImageMapType overlay
var layer = new google.maps.ImageMapType({
    "getTileUrl" : function (tile, zoom) {
        return url + tile.x + '+' + tile.y + '+' + zoom;
    },
    "tileSize"  : new google.maps.Size(256, 256),
    "isPng"     : false,
    "opacity"   : 0.5,
    "maxZoom"   : 17,
    "minZoom"   : 1
});

// Add a click event listener to poly layer to open infowindow
var infowindow = new google.maps.InfoWindow();
google.maps.event.addListener(layer, "click", function(event) {

    // Get infowindow content via Ajax
    $.ajax({
        "url": ajaxUrl,
        "data": "",
        "type": "GET",
        "success": function(data) {
            infowindow.setContent(str);
            infowindow.setPosition(event.latLng);
            infowindow.open(map);
        }
    });
});

// Add the overlay to the map
map.overlayMapTypes.insertAt(0, layer);

The map and the layer are drawn correctly, but the mouse click is not
trapped at all. Ideally, I would like to close any already open
infowindow and open a new one at the point of click.

If I make the following change to the above code

-- google.maps.event.addListener(layer, "click", function(event) {
++ google.maps.event.addListener(map, "click", function(event) {

then the infowindow opens just fine. Of course, now my entire map is
listening for the event, and that is not what I want. I only want the
custom layer to be doing so.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps JavaScript API v3" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Reply via email to