Changing the Google Maps Marker HTML after a function is ran

前端 未结 1 525
梦谈多话
梦谈多话 2020-12-21 07:30

So I\'m trying to figure out a way to change the HTML of Google Maps V3 markers after they have been pulled from the database but before they are pushed up to the array.

相关标签:
1条回答
  • 2020-12-21 08:09

    If you change your click listener to display the HTML saved in a member variable of the marker, you can change it at any time. If the InfoWindow is open, you may want to close it and reopen it (or update its content in place, but that gets more complicated).

    Something like:

      function bindInfoWindow4(marker, map, infoWindow, html) {
          marker.myHtmlContent = html;
          google.maps.event.addListener(marker, 'click', function() {
            infoWindow.setContent(marker.myHtmlContent);
            infoWindow.open(map, marker);
          });
      }
    

    Then update the content by changing the value in marker.myHtmlContent. To make it visible, somthing like this:

      marker.myHtmlContent = "<img id='1star' src='images/1star.png' style='visibility:visible'>";
    
    0 讨论(0)
提交回复
热议问题