mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-28 05:34:47 +01:00
Improved dateline crossing handling
This commit is contained in:
parent
eda5046518
commit
7432459c93
@ -29,7 +29,7 @@ PathItem::PathItem(const Path &path, Map *map, QGraphicsItem *parent)
|
|||||||
QBrush brush(Qt::SolidPattern);
|
QBrush brush(Qt::SolidPattern);
|
||||||
_pen = QPen(brush, _width);
|
_pen = QPen(brush, _width);
|
||||||
|
|
||||||
updatePainterPath(map);
|
updatePainterPath();
|
||||||
updateShape();
|
updateShape();
|
||||||
|
|
||||||
_marker = new MarkerItem(this);
|
_marker = new MarkerItem(this);
|
||||||
@ -47,33 +47,35 @@ void PathItem::updateShape()
|
|||||||
_shape = s.createStroke(_painterPath);
|
_shape = s.createStroke(_painterPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PathItem::updatePainterPath(Map *map)
|
void PathItem::addSegment(const Coordinates &c1, const Coordinates &c2)
|
||||||
|
{
|
||||||
|
if (fabs(c1.lon() - c2.lon()) > 180.0)
|
||||||
|
_painterPath.moveTo(_map->ll2xy(c2));
|
||||||
|
else
|
||||||
|
_painterPath.lineTo(_map->ll2xy(c2));
|
||||||
|
}
|
||||||
|
|
||||||
|
void PathItem::updatePainterPath()
|
||||||
{
|
{
|
||||||
_painterPath = QPainterPath();
|
_painterPath = QPainterPath();
|
||||||
|
|
||||||
_painterPath.moveTo(map->ll2xy(_path.first().coordinates()));
|
_painterPath.moveTo(_map->ll2xy(_path.first().coordinates()));
|
||||||
for (int i = 1; i < _path.size(); i++) {
|
for (int i = 1; i < _path.size(); i++) {
|
||||||
const PathPoint &p1 = _path.at(i-1);
|
const PathPoint &p1 = _path.at(i-1);
|
||||||
const PathPoint &p2 = _path.at(i);
|
const PathPoint &p2 = _path.at(i);
|
||||||
unsigned n = segments(p2.distance() - p1.distance());
|
unsigned n = segments(p2.distance() - p1.distance());
|
||||||
|
|
||||||
if (n > 1) {
|
if (n > 1) {
|
||||||
Coordinates c1(p1.coordinates());
|
GreatCircle gc(p1.coordinates(), p2.coordinates());
|
||||||
Coordinates c2(p2.coordinates());
|
Coordinates last = p1.coordinates();
|
||||||
GreatCircle gc(c1, c2);
|
|
||||||
double prev = c1.lon();
|
|
||||||
|
|
||||||
for (unsigned j = 1; j <= n; j++) {
|
for (unsigned j = 1; j <= n; j++) {
|
||||||
Coordinates c(gc.pointAt(j/(double)n));
|
Coordinates c(gc.pointAt(j/(double)n));
|
||||||
double current = c.lon();
|
addSegment(last, c);
|
||||||
if (fabs(current - prev) > 180.0)
|
last = c;
|
||||||
_painterPath.moveTo(map->ll2xy(c));
|
|
||||||
else
|
|
||||||
_painterPath.lineTo(map->ll2xy(c));
|
|
||||||
prev = current;
|
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
_painterPath.lineTo(map->ll2xy(p2.coordinates()));
|
addSegment(p1.coordinates(), p2.coordinates());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,7 +101,7 @@ void PathItem::setMap(Map *map)
|
|||||||
|
|
||||||
_map = map;
|
_map = map;
|
||||||
|
|
||||||
updatePainterPath(map);
|
updatePainterPath();
|
||||||
updateShape();
|
updateShape();
|
||||||
|
|
||||||
_marker->setPos(position(_markerDistance));
|
_marker->setPos(position(_markerDistance));
|
||||||
|
@ -43,8 +43,10 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QPointF position(qreal distance) const;
|
QPointF position(qreal distance) const;
|
||||||
void updatePainterPath(Map *map);
|
void updatePainterPath();
|
||||||
void updateShape();
|
void updateShape();
|
||||||
|
void addSegment(const Coordinates &c1, const Coordinates &c2);
|
||||||
|
|
||||||
|
|
||||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
||||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
||||||
|
Loading…
Reference in New Issue
Block a user