Skip to content

Commit

Permalink
IofCourseExport: Add 'Map' element
Browse files Browse the repository at this point in the history
The 'Map' element is added to the IOF 3.0 compliant xml export of
course data.
  • Loading branch information
dl3sdo committed Jul 6, 2023
1 parent 0359901 commit 966eecd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
28 changes: 27 additions & 1 deletion src/fileformats/iof_course_export.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Kai Pastor
* Copyright 2021-2023 Kai Pastor
*
* This file is part of OpenOrienteering.
*
Expand All @@ -22,6 +22,7 @@
#include <Qt>
#include <QDateTime>
#include <QLatin1String>
#include <QRectF>
#include <QString>
#include <QXmlStreamWriter>

Expand Down Expand Up @@ -97,11 +98,36 @@ void IofCourseExport::writeXml(const PathObject& object)
}
{
XmlElementWriter event(*xml, QLatin1String("RaceCourseData"));
writeMap();
writeControls(object.getRawCoordinateVector());
writeCourse(object.getRawCoordinateVector());
}
}

void IofCourseExport::writeMap()
{
XmlElementWriter map_data(*xml, QLatin1String("Map"));
xml->writeTextElement(QLatin1String("Scale"), QString::number(map->getScaleDenominator()));

// IOF.xsd proposes for 'MapPositionTopLeft': "The position of the map's top left corner given in the map's coordinate system, usually (0, 0)."
// With this the bottom right position is determined by the (negative) size of the map extent.
// Alternatively use real coordinates from the map_extent structure below.
// NOTE: templates are not considered when determining the map extent.
auto map_extent = map->calculateExtent(true, false, nullptr);
{
XmlElementWriter map_position_topleft(*xml, QLatin1String("MapPositionTopLeft"));
map_position_topleft.writeAttribute(QLatin1String("x"), QString::number(0.0f));
map_position_topleft.writeAttribute(QLatin1String("y"), QString::number(0.0f));
map_position_topleft.writeAttribute(QLatin1String("unit"), QLatin1String("mm")); // optional attribute, default is 'mm'
}
{
XmlElementWriter map_position_bottomright(*xml, QLatin1String("MapPositionBottomRight"));
map_position_bottomright.writeAttribute(QLatin1String("x"), QString::number(-map_extent.width()));
map_position_bottomright.writeAttribute(QLatin1String("y"), QString::number(-map_extent.height()));
map_position_bottomright.writeAttribute(QLatin1String("unit"), QLatin1String("mm")); // optional attribute, default is 'mm'
}
}

void IofCourseExport::writeControls(const std::vector<MapCoord>& coords)
{
auto next = [](auto current) {
Expand Down
6 changes: 4 additions & 2 deletions src/fileformats/iof_course_export.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Kai Pastor
* Copyright 2021-2023 Kai Pastor
*
* This file is part of OpenOrienteering.
*
Expand Down Expand Up @@ -31,8 +31,8 @@ namespace OpenOrienteering {

class LatLon;
class Map;
class MapView;
class MapCoord;
class MapView;
class PathObject;
class SimpleCourseExport;

Expand Down Expand Up @@ -60,6 +60,8 @@ class IofCourseExport : public Exporter

void writeXml(const PathObject& object);

void writeMap();

void writeControls(const std::vector<MapCoord>& coords);

void writeCourse(const std::vector<MapCoord>& coords);
Expand Down

0 comments on commit 966eecd

Please sign in to comment.