简体   繁体   中英

Google maps api: force map to do not handle click inside infobox

In my app user create marker when he click by map. So code like this:

function placeMarker(map, location) {
     var marker = new google.maps.Marker({
         position: location,
         map: map
     //other...
     var infowindow = new google.maps.InfoWindow({
         content: ballon.get(0)
     });

     ballon.find("#delete-btn").click(function(){
        infowindow.close();
        $mapPreview.data("markers")[id].marker.setMap(null);
        delete $this.data("markers")[id];
     });
});

"#delete-btn" is inside infowindow . Problem is when user click on "#delete-btn" he also create new marker on map. How can I avoid this?

baloon.find("#delete-btn").click(function(e){
    e.stopPropagation();

Pass the event variable through to the click function (e) , and then stop the event propagation using e.stopPropagation()

This will stop the event from bubbling up through the DOM and getting picked up by various other listeners, like those on the map.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM