旋转谷歌地图自定义图标中心的SVG

旋转谷歌地图自定义图标中心的SVG,svg,google-maps-markers,Svg,Google Maps Markers,我有以下代码用于在谷歌地图上绘制旋转图标: function createMarker(device) { var wtf = new google.maps.Marker({ map: window.map_, position: new google.maps.LatLng(device.lat, device.lng), icon: { path: 'M350,0 700,700 350,550

我有以下代码用于在谷歌地图上绘制旋转图标:

    function createMarker(device) {
        var wtf = new google.maps.Marker({
        map: window.map_,
        position: new google.maps.LatLng(device.lat, device.lng),
        icon: {
            path: 'M350,0 700,700 350,550 0,700',
            fillColor: "limegreen",
            fillOpacity: 0.8,
            scale: 0.04,
            strokeColor: 'limegreen',
            strokeWeight: 1,
            anchor: new google.maps.Point(800, 800),
            rotation: device.head,
        }
      });
      return wtf;
}
问题是旋转在SVG的一个角上旋转,而不是在中心。我在某处找到了svg路径,通过尝试和错误对其进行缩放,并猜测了锚点。当我添加一个标签,而不是标签下的图标,它是所有的混乱。标签使用与标记相同的纬度/长度

见示例:


我发现不可能让图标在标签上方“当场”旋转。你有什么办法让它发挥作用吗?谢谢

这不太理想,但效果不错。这是打字脚本代码。在用TypeScript编写之后,您不能回到JavaScript,这太痛苦了

鉴于pos是一个板条:

let pos = new this.google.maps.LatLng(lat, lng);
方法:

public createMarker(heading: number, pos: any) {
    let marky = new this.google.maps.Marker({
        position: pos,
        map: this.google_map,
        icon: {
            path: this.google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
            fillOpacity: 1,
            fillColor: 'orange',
            strokeWeight: 1.5,
            scale: 2,
            strokeColor: 'darkblue',
            rotation: heading,
            anchor: this.getRotation(heading),
        },
    });
    return marky;
}

public createLabel(name: string, pos: any) {
    let label = new MapLabel({
        text: name,
        position: pos,
        map: this.google_map,
        fontSize: 17,
        fontColor: 'darkred',
        align: 'center'
    });
    return label;
}

public getRotation(angle: number) {
    if (angle <= 30) return new this.google.maps.Point(0, 5);
    if (angle <= 45) return new this.google.maps.Point(0, 5);
    if (angle <= 60) return new this.google.maps.Point(2, 4);
    if (angle <= 120) return new this.google.maps.Point(3, 0);
    if (angle <= 150) return new this.google.maps.Point(0, 0);
    if (angle <= 210) return new this.google.maps.Point(0, 0);
    if (angle <= 220) return new this.google.maps.Point(-1, 0);
    if (angle <= 240) return new this.google.maps.Point(-3, 0);
    if (angle <= 280) return new this.google.maps.Point(-3, -3);
    return new this.google.maps.Point(0, 5);
}
public createMarker(标题:编号,位置:任意){
让marky=newthis.google.maps.Marker({
职位:pos,,
地图:这是谷歌地图,
图标:{
路径:this.google.maps.SymbolPath.FORWARD\u CLOSED\u箭头,
不透明度:1,
fillColor:'橙色',
冲程重量:1.5,
比例:2,
strokeColor:'暗蓝色',
轮换:标题,
锚定:这个.getRotation(标题),
},
});
返回标记;
}
公共createLabel(名称:字符串,位置:任意){
let label=新地图标签({
文本:名称,
职位:pos,,
地图:这是谷歌地图,
尺寸:17,
fontColor:“暗色”,
对齐:“居中”
});
退货标签;
}
公共旋转(角度:编号){

如果(角度)你找到任何解决方案了吗?如果你找到了解决方案,任何更新?通过尝试和错误完成。应该有更好的方法。