2016-05-20 1 views
0

Le code ci-dessous est utilisé pour afficher infowindow sur Google maps sur le clic des marqueurs. Mais pour certaines raisons, l'événement 'closeclick' pour les fenêtres d'information ne fonctionne pas. Auparavant, cela fonctionnait bien, mais en raison de plus de complexité, d'autres exigences comme l'objet infowindow doivent être rouvertes comme c'est le cas après l'actualisation des cartes sur les appels Ajax. Ainsi, les cartes restent actualisées après une minute et l'exigence est que, infowindows devrait rester ouvert s'il n'est pas fermé lors des appels Ajax.GooglemapV3 infowindow L'événement closeclick ne prend pas feu

Nous dessinons également des lignes poly sur des cartes et nous ouvrons aussi un infowindow sur chaque point qu'il dessine sur la carte Google et la même exigence est également applicable pour les objets infowindows comme ci-dessus.

 $(".mainDiv").each(function() { 
    google.maps.event.trigger(map, 'click'); 
    if (PlayBackDevices.indexOf(removeSpaces($(this).find(".deviceid").html()).trim()) > -1) { 
      var image = new google.maps.MarkerImage($(this).find(".imagepath").html()); 
      myLatLng = new google.maps.LatLng($(this).find(".latitude").html(), $(this).find(".longitude").html()); 
      var beachMarker = new MarkerWithLabel({ 
       position: myLatLng, 
       map: map, 
       icon: image, 
       title: $(this).find(".deviceName").html().trim(), 
       labelContent: $(this).find(".deviceName").html().trim() 
      }); 
      markers.push(beachMarker); 
      var imgPath = trailImagePath + trailColor.trim() + ".png"; 
      var beachMarkerTemp = new RichMarker({ 
       position: myLatLng, 
       map: map, 
       draggable: false, 
       flat: true, 
       anchor: RichMarkerPosition.BOTTOM//, 
      }); 
      i = i + 1; 
      oms.addListener('click', function (beachMarker) { 
       infoWindow.close(); 
       infoWindowDevicePoints.length = 0; 
       if (deviceName.trim() == beachMarker.title.trim()) { 
        $.ajax({ 
         type: "Post", 
         url: "/Home/CommonLevel2Information", 
         data: { DeviceId: 101 }, 
         async: true, 
         dataType: "html", 
         cache: false, 
         success: function (result) { 
          result = createInfo('', result + '<br/><a href="' + linkToNextLevel + '" title="Click to view DeviceDetail"><%=GlanceWeb.Resources.Level2.Level2.RegMrDtl%>...</a>', deviceId); 
          beachMarker.desc = result; 
          if (result.toString().indexOf("divMainSnap") > 0) { 
           var checkExist = setInterval(function() { 
            $(".gm-style-iw").css("width", "400px !important;"); 
            infoWindow = new google.maps.InfoWindow({ content: beachMarker.desc, maxWidth: 400 }); 
            infoWindow.open(map, beachMarker); 
            position = beachMarker.position;// iw.getPosition(); 
            $(".gm-style-iw").each(function() { 
             if ($(this).find("div.divFirstSnap").length) { 
              $(this).removeClass("wiThouImage"); 
              $(this).css("max-width", "none"); 
             } 
            }) 
            clearInterval(checkExist); 
           }, 1000); 
          } 
          else { 
           var checkExist = setInterval(function() { 
            infoWindow = new google.maps.InfoWindow({ content: beachMarker.desc, maxWidth: 200 }); 
            infoWindow.open(map, beachMarker); 
            position = beachMarker.position;// iw.getPosition(); 
            if ($(".gm-style-iw").length > 0) { 
             $(".gm-style-iw").removeAttr("width"); 
             $(".gm-style-iw").each(function() { 
              if (!$(this).find("div.divFirstSnap").length) { 
               $(this).addClass("wiThouImage"); 
              } 
             }) 

             clearInterval(checkExist); 
            } 

           }, 1000); 
          } 

          //Following section is used to manage device pop-ups after ajax 
          for (var i = 0; i < infoWindowDevicePoints.length; i++) { 
           infoWindowDevicePoints[i].latLng 
           if (position == infoWindowDevicePoints[i].latLng) 
            isExist = false; 
          } 

          if (isExist) { 
           infoWindowDevicePoints.push({ 
            latLng: beachMarker.position, 
            popUpData: beachMarker.desc 
           }); 
          } 
          UnBlockGlanceScreen(); 
         } 
        }); 
        } 
      }); 
      google.maps.event.addListener(infoWindow, "closeclick", function() { 
       debugger; 

       var that = this; 
       that.getposition() 
       var latlnginfo = that.getposition(); 
       infowindowdevicepoints = $.grep(infowindowdevicepoints, function (value) { 
        return value.latlng != latlnginfo; 
       }); 
      }); 

       oms.addListener('spiderfy', function() { 
        infoWindow.close(); 
        infoWindowDevicePoints.length = 0; 
       }); 
       oms.addMarker(beachMarker); 

      } 

     }); 


}); 

Merci à l'avance pour toute aide offerte.

+0

Vous ajoutez des écouteurs d'événements 'de FermerCliquer' à 5 différents lieux. Certains d'entre eux sont-ils exécutés? Votre code est assez complexe, plus de 400 lignes. Pouvez-vous le simplifier à un [MCVE] (http://stackoverflow.com/help/mcve) pour cette question? – duncan

+0

Bonjour Duncan, j'ai raccourci les lignes de code pour les rendre plus claires à comprendre. Infowindow s'ouvre mais l'événement closeclick ne prend pas feu. J'essayais de garder les événements à différents endroits afin de vérifier si cela ne fonctionne pas mais en vain. Il y a aussi beaucoup d'autres endroits d'où l'Infowindow apparaît dans différentes conditions. – Vijay

+0

Vous créez l'infowindow à l'intérieur de votre gestionnaire de succès ajax. L'avez-vous déjà défini comme une variable globale? Au point où vous attachez le gestionnaire d'événements closeclick, qu'obtenez-vous si vous faites simplement 'console.log (infoWindow)'? – duncan

Répondre

1

Le problème est que vous créez uniquement l'infoWindow en réponse à la requête ajax. Toutefois, lorsque vous ajoutez l'écouteur d'événement closeclick, il s'exécute probablement avant la réponse ajax.

Vous devez déplacer ce bloc:

google.maps.event.addListener(infoWindow, "closeclick", function() { 
    debugger; 

    var that = this; 
    that.getposition() 
    var latlnginfo = that.getposition(); 
    infowindowdevicepoints = $.grep(infowindowdevicepoints, function(value) { 
     return value.latlng != latlnginfo; 
    }); 
}); 

... à l'intérieur de ce bloc, après l'instruction if-else qui crée la InfoWindow

$.ajax({ 
    ... 
    success: function(result) { 
      // add a call to the event listener here 
    } 
+0

Merci pour votre aide Duncan, le bon endroit où cela a fonctionné est 'var checkExist = setInterval (function() {});'. Travaille maintenant. Merci encore. – Vijay