【发布时间】:2020-02-15 12:11:50
【问题描述】:
我正在开发用于绘制地铁地图的图形界面。一条线用车站表示为圆圈和一条折线来连接它们。您可以用鼠标拖动移动车站,当然它会实时更新显示的地图。我的问题是,当车站到达某个角度时,会出现折线变形,并且由 2 条线创建的角超出车站圆形显示,我想知道是否有办法避免这种情况。
screenshots of the app with the polyline issue
这是我绘制折线的代码
//x and y point array creation
xPoints = new int[this.stationViews.size()];
yPoints = new int[this.stationViews.size()];
for (int i=0;i<this.stationViews.size();i++) {
//fill arrays with the center point of circles representing stations
xPoints[i] = this.stationViews.get(i).getStation().getPosX()-this.stationViews.size()/2;
yPoints[i] = this.stationViews.get(i).getStation().getPosY()-this.stationViews.size();
}
//setting color
g2D.setColor(this.line.getColor());
//set stroke width relative to the zoom level
int strokeWidth=5;
if(!this.stationViews.isEmpty()) {
if (this.stationViews.get(0).getStationSize()>14) {
strokeWidth = this.stationViews.get(0).getStationSize()-13;
}else {
strokeWidth = 3;
}
}
g2D.setStroke(new BasicStroke(strokeWidth));
//draw the polyline
if (this.stationViews.size() >1) {
g2D.drawPolyline(xPoints, yPoints, this.stationViews.size());
}
//draw the station (g2D.drawCircle)
for (StationView stationView : stationViews) {
stationView.affiche(g2D,this.line.getColor());
}
感谢您的帮助
【问题讨论】:
标签: java graphics2d polyline