Ciao a tutti
sto inserendo dei marker in una mappa di google e vorrei aprire differenti infowindows in base all'evento che si verifica.
Ho fatto così:
così funziona solo la infowindow associata all'evento mouseover e mouseout. Al click non fa nulla.codice:function addMarker(i, objStruttura) { ... if (lat != null && lng != null) { myLatLng = new google.maps.LatLng(lat, lng); bounds = new google.maps.LatLngBounds(); var imageUrl = '/Img/marker.png'; var markerImage = new google.maps.MarkerImage(imageUrl); eval('var marker' + i + ' = new google.maps.Marker({ position: myLatLng, map: map, icon: markerImage, zIndex: i});'); var marker_obj = eval('marker' + i); bounds.extend(marker_obj.position); markersArray.push(eval('marker' + i)); marker_obj.title = struttura; var li_obj = '.js-map-num' + i; image = ''; if (img != '') { image = '<img src="' + img + '" width="200" />'; } var content = '<div class="col-sm-12 row box-mappa">' + '<h5><span class="titolo-mappa">' + struttura + '</span> ' + stelle + '</h5>' + image + '<h6>' + indirizzo + '</h6>' + '<div class="text-left box-prezzo">' + notti + ' ' + lgNotti + ' ' + (totale < scontato ? '<span class="scontato-mappa">€ ' + scontato + '</span> ' : '') + '<span class="prezzo-mappa">€ ' + totale + '</span>' + '</div>' + '<div class="pull-right margin-top10">' + '<a id="hlPrenota" class="prenotaEvent button-mappa pointer" data-code="' + codiceStruttura + '">' + lgPrenota + '</a>' + '</div>' + '</div>'; eval('var infowindow' + i + ' = new google.maps.InfoWindow({ content: content, maxWidth: 350});'); var infowindow_obj = eval('infowindow' + i); var marker_obj = eval('marker' + i); google.maps.event.addListener(marker_obj, 'click', function () { infowindow_obj.open(map, marker_obj); }); content = '<div class="col-sm-12 row box-mappa">' + '<h5><span class="titolo-mappa">' + struttura + '</span> ' + stelle + '</h5>' + '<div class="text-right box-prezzo">' + notti + ' ' + lgNotti + ' ' + (totale < scontato ? '<span class="scontato-mappa">€ ' + scontato + '</span> ' : '') + '<span class="prezzo-mappa">€ ' + totale + '</span>' + '</div>' + '</div>'; eval('var infowindowInfo' + i + ' = new google.maps.InfoWindow({ content: content, maxWidth: 370});'); infowindow_obj = eval('infowindowInfo' + i); marker_obj = eval('marker' + i); google.maps.event.addListener(marker_obj, 'mouseover', function () { infowindow_obj.open(map, marker_obj); }); google.maps.event.addListener(marker_obj, 'mouseout', function () { infowindow_obj.close(); }); } }
Dove sbaglio?
Grazie

Rispondi quotando