gmap.js MouseOver event on an overlay? Is it possible?

泪湿孤枕 提交于 2019-12-02 08:44:43

One option would be to add onmouseover and onmouseout functions to the div that holds the overlay:

var map;
var infowindow = new google.maps.InfoWindow();

function mouseover() {
    infowindow.setContent("Mouse");
    infowindow.setPosition(new google.maps.LatLng(29.425967,-98.486142));
    infowindow.setOptions({pixelOffset:new google.maps.Size(-14,-16)});
    infowindow.open(map);
};
function mouseout() {
    infowindow.close();
};
$(document).ready(function () {
    map = new GMaps({
        el: '#map',
        lat: 29.425967,
        lng: -98.486142,
        zoom: 12,
        zoomControl: true,
        zoomControlOpt: {
            style: 'SMALL',
            position: 'TOP_LEFT'
        },
        panControl: false,
        streetViewControl: false,
        mapTypeControl: false,
        overviewMapControl: false
    });

    map.drawOverlay({
        lat: 29.425967,
        lng: -98.486142
        },
        content: "<div class='masterpin bounce' onmouseover='mouseover();' onmouseout='mouseout();'></div><div class='pulse'></div>"
    });

});

Working fiddle

Rather than create a global function like the other answer suggestions, you can add the listener to the element when the overlay's ready event fires.

var overlay = map.drawOverlay({
  lat: 29.425967,
  lng: -98.486142,
  layer: 'overlayMouseTarget',
  content: '<div>my overlay</div>'
});

overlay.addListener('ready', function () {
  overlay.el.addEventListener('mouseover', function (e) {
    console.log("mouseover");
  });
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!