我在 javafx 中绘制时间线动画。这是创建行的代码:
public Line getLine() {
Point startPoint = FigureUtil.translateGeographicalToViewCoords(center.longitude, center.latitude, mapViewState);
line = new Line();
line.setStartX(startPoint.x);
line.setStartY(startPoint.y);
line.setStrokeWidth(4);
line.setStyle("-fx-stroke: rgba(37, 176, 79, 0.5);");
return line;
}
public void stop(){
timer.stop();
timeline.stop();
}
private KeyFrame getFrame() {
Duration duration = Duration.millis(60/speedOfRotating);
EventHandler<ActionEvent> onFinished = new EventHandler<ActionEvent>() {
public void handle(ActionEvent t) {
LatLong latLong = LongitudeLatitudeUtil.getLatLongByDistanceAndAngle(center, time, size);
Point endPoint = FigureUtil.translateGeographicalToViewCoords(latLong.longitude, latLong.latitude, mapViewState);
line.setEndX(endPoint.x);
line.setEndY(endPoint.y);
time++;
}
};
KeyFrame keyFrame = new KeyFrame(duration, onFinished);
return keyFrame;
}
private void startTimer() {
timer = new AnimationTimer() {
@Override
public void handle(long l) {
time++;
if (time > 360) {
time = 0;
}
}
};
timer.start();
}
public void start() {
startTimer();
timeline = new Timeline();
timeline.setCycleCount(Timeline.INDEFINITE);
timeline.setAutoReverse(true);
// You can add a specific action when each frame is started.
// timeline.getKeyFrames().remove(1);
timeline.getKeyFrames().add(getFrame());
timeline.play();
}
当我将其添加到窗格时,我遇到了这样的问题:[1]:http: //img.image-storage.com/69224197/be380fee3e074.jpg。线条在我添加到的窗格中不可见(它由虚线分隔)。