Angular 从贴图旋转svg不起作用
我试图将Angular 从贴图旋转svg不起作用,angular,google-maps,typescript,svg,google-maps-api-3,Angular,Google Maps,Typescript,Svg,Google Maps Api 3,我试图将旋转应用于svg类型图标,但应用不正确,实际上图标中没有任何样式 我是这样做的: 首先,我初始化google maps变量,如下所示: marker: any = new google.maps.Marker; createMarker (location) { if (this.marker) { this.marker.setMap (null); } this.marker.setPosition (new google.maps.LatLng (locat
旋转
应用于svg
类型图标,但应用不正确,实际上图标中没有任何样式
我是这样做的:
marker: any = new google.maps.Marker;
createMarker (location) {
if (this.marker) {
this.marker.setMap (null);
}
this.marker.setPosition (new google.maps.LatLng (location.coords.latitude, location.coords.longitude));
this.marker.setMap (this.map);
const icon = {
url: 'assets / bus.svg',
anchor: new google.maps.Point (0, 0),
scaledSize: new google.maps.Size (32, 32)
};
this.marker.setIcon (icon);
this.map.setCenter (new google.maps.LatLng (location.coords.latitude, location.coords.longitude));
}
marker: any = new google.maps.Marker;
createMarker (location) {
if (this.marker) {
this.marker.setMap (null);
}
this.marker.setPosition (new google.maps.LatLng (location.coords.latitude, location.coords.longitude));
this.marker.setMap (this.map);
const icon = {
url: 'assets / bus.svg',
anchor: new google.maps.Point (0, 0),
scaledSize: new google.maps.Size (32, 32)
};
this.marker.setIcon (icon);
this.map.setCenter (new google.maps.LatLng (location.coords.latitude, location.coords.longitude));
}
标记时:
moveMarker (location) {
if (this.marker) {
const currentPos = this.marker.getPosition ();
const nextPos = new google.maps.LatLng (location.coords.latitude, location.coords.longitude);
const duration = this.calcMoveDuration (location.distanceFilter, location.coords.speed);
console.log ('currentPos', currentPos)
console.log ('next', nextPos)
let fraction = 0;
const steps = 30;
const fractionStep = 1 / steps;
let animateTimer = setInterval (() => {
fraction + = fractionStep;
const interpolate = google.maps.geometry.spherical.interpolate (currentPos, nextPos, fraction);
const icon = {
url: 'assets / bus.svg',
scaledSize: new google.maps.Size (32, 32),
anchor: new google.maps.Point (0, 0),
rotation: 50
};
this.marker.setIcon (icon);
if (fraction> = 1.0)
clearInterval (animateTimer);
animateTimer = null;
}
}, duration / steps);
}
}
Symbol
,它具有必需的属性path
,只需将svg路径直接作为字符串传递,而不是作为文件传递$('img[src="' + iconurl + '"]').css({
'transform': 'rotate(' + (heading - initial) + 'deg)'
});
Symbol
,它具有必需的属性path
,只需将svg路径直接作为字符串传递,而不是作为文件传递$('img[src="' + iconurl + '"]').css({
'transform': 'rotate(' + (heading - initial) + 'deg)'
});
我有多个标记,需要旋转它们。如果我一个接一个地添加它们,就可以访问DOM中最新的标记,并分配一个属性供以后访问。但是如果我把它们添加到一个循环中,我就不能得到最新的一个,因为异步添加。。我如何处理这个问题。@freezer简单的方法是使用不同的URL作为图标。只需在图标url中添加
?id=IDhere
,您就可以通过$('img[src=“'+iconurl+'?id='+id+''']')访问它代码>我有多个标记,需要旋转它们。如果我一个接一个地添加它们,就可以访问DOM中最新的标记,并分配一个属性供以后访问。但是如果我把它们添加到一个循环中,我就不能得到最新的一个,因为异步添加。。我如何处理这个问题。@freezer简单的方法是使用不同的URL作为图标。只需在图标url中添加?id=IDhere
,您就可以通过$('img[src=“'+iconurl+'?id='+id+''']')访问它代码>