Specify the z-index of Google Map Markers

前端 未结 4 558
离开以前
离开以前 2020-12-25 11:28

I am having a Google Map with lots of markers added using websockets. I am using custom marker images based on data availability. I want to make sure the newest marker stays

4条回答
  •  生来不讨喜
    2020-12-25 12:25

    Problem solved. Just set the zValue to 999 (I'm guessing higher will bring it more to the top) and it should come to the top. I guess the default is below 999:

    var zValue;
    
    if (someCondition) {
        zValue = 999;
    }
    
    var marker = new google.maps.Marker({
        map: map,
        position: {lat: lat, lng: lng},
        title: titleString,
        icon: image,
        zIndex: zValue
    });
    

提交回复
热议问题