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 1e1e078
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 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
7 changes: 6 additions & 1 deletion test/data/export/iof-3.0-course.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<CourseData xmlns="http://www.orienteering.org/datastandard/3.0" iofVersion="3.0" creator="OpenOrienteering Mapper Debug 0.9.6" createTime="2021-05-20T09:28:32">
<CourseData xmlns="http://www.orienteering.org/datastandard/3.0" iofVersion="3.0" creator="OpenOrienteering Mapper Debug 0.9.6" createTime="2023-07-06T15:52:35">
<Event>
<Name>Test event</Name>
</Event>
<RaceCourseData>
<Map>
<Scale>10000</Scale>
<MapPositionTopLeft x="0" y="0" unit="mm"/>
<MapPositionBottomRight x="-56.871" y="-7.60623" unit="mm"/>
</Map>
<Control>
<Id>S1</Id>
<Position lng="8" lat="51"/>
Expand Down

0 comments on commit 1e1e078

Please sign in to comment.