Google Maps API v3 : Click events not triggered in firefox for custom marker

给你一囗甜甜゛ 提交于 2019-12-04 01:49:52

I did something very similar for an open-source disaster software package. In this case, lets assume I selected "Fire" in my dropdown menu and this triggers addFire(). The listener on the markers will delete the point on a click or allow you to drag it. The map can only have one listener at a time, but each marker can still have its own listener at the same time.

Here is the code that worked on Chrome, Firefox and IE8:

//This function sets up the map for adding a fire icon
function addFire() {
 //Kill old listener
 if(listening)
  google.maps.event.removeListener(listenerhandle);

 //Start new listener
 listenerhandle = google.maps.event.addListener(disasterMap, 'click', addFirePoint);
 listening = true;
}//end addFire

//This function adds new fire points to the map and controls dragging and clicking
function addFirePoint(event) {
 //Create the marker
 var fireMarker = new google.maps.Marker({
  icon: "./mapimgs/fire.png", position: event.latLng, map: disasterMap, draggable: true });

 newFireMarkers.push(fireMarker);
 fireMarker.setTitle("Fire");

 //Listen for clicks on the new marker
 google.maps.event.addListener(fireMarker, 'click', function() {
      fireMarker.setMap(null);
   //remove the marker from the array
   for(i=0;i
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!