Specify the z-index of Google Map Markers

前端 未结 4 556
离开以前
离开以前 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:10

    By default map will make z-index higher for markers lower on the map so they visibly stack top to bottom

    You can set zIndex option for a marker. You would just need to create a increment zIndex counter as you add markers and add that to the marker options object:

    marker=new google.maps.Marker({
        position:pin,
        icon:markerIcon,
        zIndex: counterValue
    });
    

    I'm not quite sure what the base start value needs to be

提交回复
热议问题