爲什麼不創建一個具有較低z-index的額外標記?它比創建自定義疊加層的工作量更少,可以說是更正確的方法。 (如果您創建的影子爲所建議的圖標圖像的一部分,一個標記圖標,影子也可點擊,這是不可取的)
createMarkerShadow = function(map, data) {
var latLng = new google.maps.LatLng(data.latitude, data.longitude);
var markerShadow = new google.maps.Marker({
clickable: false,
position: latLng,
map: map,
icon:{
url: '/frontend/img/icons/google-map-marker-shadow.svg',
//The size image file.
size: new google.maps.Size(225, 120),
//The point on the image to measure the anchor from. 0, 0 is the top left.
origin: new google.maps.Point(0, 0),
//The x y coordinates of the anchor point on the marker. e.g. If your map marker was a drawing pin then the anchor would be the tip of the pin.
anchor: new google.maps.Point(115, 82)
},
zIndex: (Math.round(latLng.lat()*-100000)<<5)-1
});
return markerShadow;
};
setMarkerShadows = function (map, locations, bound) {
for (var i = 0; i < locations.length; i++) {
var data = locations[i];
var markerShadow = createMarkerShadow(map, data);
bound.extend(markerShadow.getPosition());
}
};
bound = new google.maps.LatLngBounds();
這偉大的工作,我只是用自定義疊加產生的陰影。謝謝! –
如果您將陰影添加到標記圖像中,它們最終會被塗在具有較低z-索引的標記上,這看起來是錯誤的。 – johncip