1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-30 22:51:16 +01:00

Fixed MultiGeometry handling

This commit is contained in:
Martin Tůma 2022-09-24 13:20:58 +02:00
parent c0f2c1b7ad
commit 36b5746456
2 changed files with 68 additions and 76 deletions

View File

@ -487,43 +487,6 @@ void KMLParser::multiTrack(TrackData &t)
} }
} }
void KMLParser::multiGeometry(QList<TrackData> &tracks, QList<Area> &areas,
QVector<Waypoint> &waypoints, const QString &name, const QString &desc,
const QDateTime &timestamp)
{
TrackData *tp = 0;
Area *ap = 0;
while (_reader.readNextStartElement()) {
if (_reader.name() == QLatin1String("Point")) {
waypoints.append(Waypoint());
Waypoint &w = waypoints.last();
w.setName(name);
w.setDescription(desc);
w.setTimestamp(timestamp);
point(w);
} else if (_reader.name() == QLatin1String("LineString")) {
if (!tp) {
tracks.append(TrackData());
tp = &tracks.last();
tp->setName(name);
tp->setDescription(desc);
}
tp->append(SegmentData());
lineString(tp->last());
} else if (_reader.name() == QLatin1String("Polygon")) {
if (!ap) {
areas.append(Area());
ap = &areas.last();
ap->setName(name);
ap->setDescription(desc);
}
polygon(*ap);
} else
_reader.skipCurrentElement();
}
}
void KMLParser::photoOverlay(const Ctx &ctx, QVector<Waypoint> &waypoints, void KMLParser::photoOverlay(const Ctx &ctx, QVector<Waypoint> &waypoints,
PointStyleMap &pointStyles) PointStyleMap &pointStyles)
{ {
@ -580,15 +543,44 @@ void KMLParser::photoOverlay(const Ctx &ctx, QVector<Waypoint> &waypoints,
} }
} }
void KMLParser::multiGeometry(QList<TrackData> &tracks, QList<Area> &areas,
QVector<Waypoint> &waypoints)
{
TrackData *tp = 0;
Area *ap = 0;
while (_reader.readNextStartElement()) {
if (_reader.name() == QLatin1String("Point")) {
waypoints.append(Waypoint());
Waypoint &w = waypoints.last();
point(w);
} else if (_reader.name() == QLatin1String("LineString")) {
if (!tp) {
tracks.append(TrackData());
tp = &tracks.last();
}
tp->append(SegmentData());
lineString(tp->last());
} else if (_reader.name() == QLatin1String("Polygon")) {
if (!ap) {
areas.append(Area());
ap = &areas.last();
}
polygon(*ap);
} else
_reader.skipCurrentElement();
}
}
void KMLParser::placemark(const Ctx &ctx, QList<TrackData> &tracks, void KMLParser::placemark(const Ctx &ctx, QList<TrackData> &tracks,
QList<Area> &areas, QVector<Waypoint> &waypoints, PointStyleMap &pointStyles, QList<Area> &areas, QVector<Waypoint> &waypoints, PointStyleMap &pointStyles,
PolygonStyleMap &polyStyles, LineStyleMap &lineStyles) PolygonStyleMap &polyStyles, LineStyleMap &lineStyles)
{ {
QString name, desc, phone, address, id; QString name, desc, phone, address, id;
QDateTime timestamp; QDateTime timestamp;
Waypoint *wp = 0; int trkIdx = tracks.size();
TrackData *tp = 0; int wptIdx = waypoints.size();
Area *ap = 0; int areaIdx = areas.size();
while (_reader.readNextStartElement()) { while (_reader.readNextStartElement()) {
if (_reader.name() == QLatin1String("name")) if (_reader.name() == QLatin1String("name"))
@ -607,58 +599,59 @@ void KMLParser::placemark(const Ctx &ctx, QList<TrackData> &tracks,
} else if (_reader.name() == QLatin1String("StyleMap")) } else if (_reader.name() == QLatin1String("StyleMap"))
styleMap(pointStyles, polyStyles, lineStyles); styleMap(pointStyles, polyStyles, lineStyles);
else if (_reader.name() == QLatin1String("MultiGeometry")) else if (_reader.name() == QLatin1String("MultiGeometry"))
multiGeometry(tracks, areas, waypoints, name, desc, timestamp); multiGeometry(tracks, areas, waypoints);
else if (_reader.name() == QLatin1String("Point")) { else if (_reader.name() == QLatin1String("Point")) {
waypoints.append(Waypoint()); waypoints.append(Waypoint());
wp = &waypoints.last(); point(waypoints.last());
point(*wp);
} else if (_reader.name() == QLatin1String("LineString") } else if (_reader.name() == QLatin1String("LineString")
|| _reader.name() == QLatin1String("LinearRing")) { || _reader.name() == QLatin1String("LinearRing")) {
tracks.append(TrackData()); tracks.append(TrackData());
tp = &tracks.last(); tracks.last().append(SegmentData());
tp->append(SegmentData()); lineString(tracks.last().last());
lineString(tp->last());
} else if (_reader.name() == QLatin1String("Track")) { } else if (_reader.name() == QLatin1String("Track")) {
tracks.append(TrackData()); tracks.append(TrackData());
tp = &tracks.last(); tracks.last().append(SegmentData());
tp->append(SegmentData()); track(tracks.last().last());
track(tp->last());
} else if (_reader.name() == QLatin1String("MultiTrack")) { } else if (_reader.name() == QLatin1String("MultiTrack")) {
tracks.append(TrackData()); tracks.append(TrackData());
tp = &tracks.last(); multiTrack(tracks.last());
multiTrack(*tp);
} else if (_reader.name() == QLatin1String("Polygon")) { } else if (_reader.name() == QLatin1String("Polygon")) {
areas.append(Area()); areas.append(Area());
ap = &areas.last(); polygon(areas.last());
polygon(*ap);
} else if (_reader.name() == QLatin1String("styleUrl")) } else if (_reader.name() == QLatin1String("styleUrl"))
id = styleUrl(); id = styleUrl();
else else
_reader.skipCurrentElement(); _reader.skipCurrentElement();
} }
if (wp) { PointStyleMap::iterator pit = pointStyles.find(id);
wp->setName(name); LineStyleMap::iterator lit = lineStyles.find(id);
wp->setDescription(desc); PolygonStyleMap::iterator ait = polyStyles.find(id);
wp->setTimestamp(timestamp);
wp->setAddress(address); for (int i = wptIdx; i < waypoints.size(); i++) {
wp->setPhone(phone); Waypoint &w = waypoints[i];
PointStyleMap::iterator it = pointStyles.find(id); w.setName(name);
wp->setStyle(it == pointStyles.end() w.setDescription(desc);
? PointStyle(QColor(0x55, 0x55, 0x55)) : *it); w.setTimestamp(timestamp);
} else if (tp) { w.setAddress(address);
tp->setName(name); w.setPhone(phone);
tp->setDescription(desc); w.setStyle(pit == pointStyles.end()
LineStyleMap::iterator it = lineStyles.find(id); ? PointStyle(QColor(0x55, 0x55, 0x55)) : *pit);
tp->setStyle(it == lineStyles.end() }
? LineStyle(QColor(0x55, 0x55, 0x55), 2) : *it); for (int i = trkIdx; i < tracks.size(); i++) {
} else if (ap) { TrackData &t = tracks[i];
ap->setName(name); t.setName(name);
ap->setDescription(desc); t.setDescription(desc);
PolygonStyleMap::iterator it = polyStyles.find(id); t.setStyle(lit == lineStyles.end()
ap->setStyle(it == polyStyles.end() ? LineStyle(QColor(0x55, 0x55, 0x55), 2) : *lit);
}
for (int i = areaIdx; i < areas.size(); i++) {
Area &a = areas[i];
a.setName(name);
a.setDescription(desc);
a.setStyle(ait == polyStyles.end()
? PolygonStyle(QColor(0x55, 0x55, 0x55, 0x99), ? PolygonStyle(QColor(0x55, 0x55, 0x55, 0x99),
QColor(0x55, 0x55, 0x55, 0x99), 2) : *it); QColor(0x55, 0x55, 0x55, 0x99), 2) : *ait);
} }
} }

View File

@ -39,8 +39,7 @@ private:
QVector<Waypoint> &waypoints, PointStyleMap &pointStyles, QVector<Waypoint> &waypoints, PointStyleMap &pointStyles,
PolygonStyleMap &polyStyles, LineStyleMap &lineStyles); PolygonStyleMap &polyStyles, LineStyleMap &lineStyles);
void multiGeometry(QList<TrackData> &tracks, QList<Area> &areas, void multiGeometry(QList<TrackData> &tracks, QList<Area> &areas,
QVector<Waypoint> &waypoints, const QString &name, const QString &desc, QVector<Waypoint> &waypoints);
const QDateTime &timestamp);
void photoOverlay(const Ctx &ctx, QVector<Waypoint> &waypoints, void photoOverlay(const Ctx &ctx, QVector<Waypoint> &waypoints,
PointStyleMap &pointStyles); PointStyleMap &pointStyles);
void track(SegmentData &segment); void track(SegmentData &segment);