GoogleMapsAPIで円の半径の拡大/縮小をアニメーション化しようとしています。今私が持っているのは、与えられた時間、最終的な半径を取り、半径のデルタを計算するJSのメソッドです。これにより、時間率(またはサイクルの次の反復まで待機するミリ秒数)が計算されます。 。重要なのは、それがより長い時間(3秒以上など)で動作し、より短い時間ではそれが必要以上にかかることです(ほとんどすべてが1秒以下の場合、2秒のようにかかります)。方法は次のとおりです>
var animateRadius = function(change){
var radiusDelta = Math.abs(change.FinalRadius-Circle.getRadius());
var radiusChangeRate = 1;
var timeRate = (radiusChangeRate*change.FinalTime)/radiusDelta;
if(timeRate <= 1){
/*since the setInterval method only works with miliseconds
if the timespan is less than one milisecond, the radius change
rate has to be bigger in order to make it on time, and since this
only happens in smaller times, I think the error is around here..*/
timeRate = 1;
radiusChangeRate = (timeRate*radiusDelta)/change.FinalTime;
}
if(change.FinalRadius > Circle.getRadius()){
//This just tells if the circle is growing or shrinking
radiusChangeRate = radiusChangeRate*-1;
}
var interval = window.setInterval(function(){
if(visionRadiusCircle.getRadius() == change.FinalRadius){
window.clearInterval(interval);
interval = 0;
}
Circle.setRadius(Circle.getRadius() - radiusChangeRate);
}, timeRate);
}
なぜこれが機能しないのか理解できません。何かご意見は?たとえそれが別のアルゴリズムであっても、どんなアイデアでも歓迎します(これを行うためのより良い方法があるかどうかさえわかりません)。
ありがとう!