以下是旋转标记的代码,但是如何旋转自定义标记。有什么想法吗?
var angleDegrees = 150;
new google.maps.Marker({
position: a,
map: map,
icon: {
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
scale: 6,
fillColor: "red",
fillOpacity: 0.8,
strokeWeight: 2,
rotation: angleDegrees //this is how to rotate the pointer
}
});
答案 0 :(得分:21)
旋转。 https://developers.google.com/maps/documentation/javascript/examples/overlay-symbol-custom
var icon = {
...
path: '...',
scale: 1,
rotation: [degrees]
};
marker = new google.maps.Marker({
map: [...],
icon: icon,
...
});
答案 1 :(得分:2)
API reference没有具体说明旋转是如何完成的,但由于path
采用SVG元素,我会说他们是如何设置旋转它的。如果您使用SVG创建自定义标记,则可以使用transform="rotate(deg centerX centerY")
轻松完成。
答案 2 :(得分:0)
您可以使用以下功能旋转图像,元素是图像,度数是您想要旋转的角度,零是箭头向北的时候:
function (element, degree) {
if (navigator.userAgent.match("Chrome")) {
element.style.WebkitTransform = "rotate(" + degree + "deg)";
}
else if (navigator.userAgent.match("Firefox")) {
element.style.MozTransform = "rotate(" + degree + "deg)";
}
else if (navigator.userAgent.match("MSIE")) {
element.style.msTransform = "rotate(" + degree + "deg)";
}
else if (navigator.userAgent.match("Opera")) {
element.style.OTransform = "rotate(" + degree + "deg)";
}
else {
element.style.transform = "rotate(" + degree + "deg)";
}
}
致以最诚挚的问候,
陈