1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 05:34:47 +01:00

Only allow one map per file

This commit is contained in:
Martin Tůma 2018-01-29 00:19:57 +01:00
parent aa07b20aa4
commit fbc0fd86cf
14 changed files with 70 additions and 78 deletions

View File

@ -40,7 +40,7 @@ build_script:
copy pkg\pcs.csv installer
copy pkg\maps.xml installer
xcopy pkg\maps installer /s/h/e/k/f/c
copy licence.txt installer

View File

@ -116,7 +116,7 @@ HEADERS += src/config.h \
src/map/primemeridian.h \
src/map/linearunits.h \
src/map/ct.h \
src/map/omd.h
src/map/mapsource.h
SOURCES += src/main.cpp \
src/common/coordinates.cpp \
src/common/rectc.cpp \
@ -202,7 +202,7 @@ SOURCES += src/main.cpp \
src/map/angularunits.cpp \
src/map/primemeridian.cpp \
src/map/linearunits.cpp \
src/map/omd.cpp
src/map/mapsource.cpp
RESOURCES += gpxsee.qrc
TRANSLATIONS = lang/gpxsee_cs.ts \
lang/gpxsee_sv.ts \
@ -218,7 +218,7 @@ macx {
icons/fit.icns \
icons/igc.icns \
icons/nmea.icns \
pkg/maps.xml \
pkg/maps \
pkg/ellipsoids.csv \
pkg/gcs.csv \
pkg/pcs.csv

View File

@ -83,7 +83,7 @@ Section "GPXSee" SEC_APP
; Put the files there
File "gpxsee.exe"
File "maps.xml"
File /r "maps"
File "ellipsoids.csv"
File "gcs.csv"
File "pcs.csv"

View File

@ -90,7 +90,7 @@ Section "GPXSee" SEC_APP
; Put the files there
File "gpxsee.exe"
File "maps.xml"
File /r "maps"
File "ellipsoids.csv"
File "gcs.csv"
File "pcs.csv"

View File

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<omd>
<map>
<name>Open Topo Map</name>
<url>https://a.tile.opentopomap.org/$z/$x/$y.png</url>
<zoom max="17"/>
</map>
<map>
<name>4UMaps</name>
<url>http://4umaps.eu/$z/$x/$y.png</url>
<zoom min="2" max="15"/>
<bounds bottom="-65"/>
</map>
<map>
<name>Open Street Map</name>
<url>http://tile.openstreetmap.org/$z/$x/$y.png</url>
</map>
<map>
<name>USGS Topo</name>
<url>https://navigator.er.usgs.gov/tiles/tcr.cgi/$z/$x/$y.png</url>
<zoom min="2" max="15"/>
</map>
<map>
<name>USGS Imagery</name>
<url>https://navigator.er.usgs.gov/tiles/aerial_Imagery.cgi/$z/$x/$y</url>
<zoom min="2" max="15"/>
</map>
</omd>

7
pkg/maps/4UMaps.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<map>
<name>4UMaps</name>
<url>http://4umaps.eu/$z/$x/$y.png</url>
<zoom min="2" max="15"/>
<bounds bottom="-65"/>
</map>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<map>
<name>Open Street Map</name>
<url>http://tile.openstreetmap.org/$z/$x/$y.png</url>
</map>

6
pkg/maps/OpenTopoMap.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<map>
<name>Open Topo Map</name>
<url>https://a.tile.opentopomap.org/$z/$x/$y.png</url>
<zoom max="17"/>
</map>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<map>
<name>USGS Imagery</name>
<url>https://navigator.er.usgs.gov/tiles/aerial_Imagery.cgi/$z/$x/$y</url>
<zoom min="2" max="15"/>
</map>

6
pkg/maps/USGS-topo.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<map>
<name>USGS Topo</name>
<url>https://navigator.er.usgs.gov/tiles/tcr.cgi/$z/$x/$y.png</url>
<zoom min="2" max="15"/>
</map>

View File

@ -4,25 +4,26 @@
#include "atlas.h"
#include "offlinemap.h"
#include "onlinemap.h"
#include "omd.h"
#include "mapsource.h"
#include "maplist.h"
bool MapList::loadList(const QString &path, bool dir)
bool MapList::loadSource(const QString &path, bool dir)
{
OMD omd;
MapSource ms;
Map *map;
if (!omd.loadFile(path)) {
if (!ms.loadFile(path)) {
if (dir)
_errorString += path + ": " + omd.errorString() + "\n";
_errorString += path + ": " + ms.errorString() + "\n";
else
_errorString = omd.errorString();
_errorString = ms.errorString();
return false;
}
_maps += omd.maps();
for (int i = 0; i < omd.maps().size(); i++)
omd.maps()[i]->setParent(this);
map = ms.map();
map->setParent(this);
_maps.append(map);
return true;
}
@ -71,7 +72,7 @@ bool MapList::loadFile(const QString &path, bool *atlas, bool dir)
return loadAtlas(path, dir);
} else if (suffix == "xml") {
*atlas = false;
return loadList(path, dir);
return loadSource(path, dir);
} else {
*atlas = false;
return loadMap(path, dir);
@ -123,7 +124,7 @@ QString MapList::formats()
+ tr("OziExplorer maps (*.map)") + ";;"
+ tr("TrekBuddy maps/atlases (*.tar *.tba)") + ";;"
+ tr("GeoTIFF images (*.tif *.tiff)") + ";;"
+ tr("Online map definitions (*.xml)");
+ tr("Online map sources (*.xml)");
}
QStringList MapList::filter()

View File

@ -29,7 +29,7 @@ private:
Map *loadListEntry(const QByteArray &line);
bool loadList(const QString &path, bool dir);
bool loadSource(const QString &path, bool dir);
bool loadMap(const QString &path, bool dir);
bool loadAtlas(const QString &path, bool dir);

View File

@ -1,7 +1,7 @@
#include <QFile>
#include <QXmlStreamReader>
#include "onlinemap.h"
#include "omd.h"
#include "mapsource.h"
#define ZOOM_MAX 19
@ -11,7 +11,7 @@
#define BOUNDS_RIGHT 180
#define BOUNDS_BOTTOM -85.0511
Range OMD::zooms(QXmlStreamReader &reader)
Range MapSource::zooms(QXmlStreamReader &reader)
{
const QXmlStreamAttributes &attr = reader.attributes();
int min, max;
@ -51,7 +51,7 @@ Range OMD::zooms(QXmlStreamReader &reader)
return Range(min, max);
}
RectC OMD::bounds(QXmlStreamReader &reader)
RectC MapSource::bounds(QXmlStreamReader &reader)
{
const QXmlStreamAttributes &attr = reader.attributes();
double top, left, bottom, right;
@ -121,7 +121,7 @@ RectC OMD::bounds(QXmlStreamReader &reader)
return RectC(Coordinates(left, top), Coordinates(right, bottom));
}
void OMD::map(QXmlStreamReader &reader)
void MapSource::map(QXmlStreamReader &reader)
{
QString name, url;
Range z(ZOOM_MIN, ZOOM_MAX);
@ -143,20 +143,10 @@ void OMD::map(QXmlStreamReader &reader)
reader.skipCurrentElement();
}
_maps.append(new OnlineMap(name, url, z, b));
_map = new OnlineMap(name, url, z, b);
}
void OMD::omd(QXmlStreamReader &reader)
{
while (reader.readNextStartElement()) {
if (reader.name() == "map")
map(reader);
else
reader.skipCurrentElement();
}
}
bool OMD::loadFile(const QString &path)
bool MapSource::loadFile(const QString &path)
{
QFile file(path);
QXmlStreamReader reader;
@ -169,10 +159,10 @@ bool OMD::loadFile(const QString &path)
reader.setDevice(&file);
if (reader.readNextStartElement()) {
if (reader.name() == "omd")
omd(reader);
if (reader.name() == "map")
map(reader);
else
reader.raiseError("Not an online map definitions file");
reader.raiseError("Not an online map source file");
}
if (reader.error())
@ -182,9 +172,8 @@ bool OMD::loadFile(const QString &path)
return !reader.error();
}
OMD::~OMD()
MapSource::~MapSource()
{
for (int i = 0; i < _maps.size(); i++)
if (!_maps.at(i)->parent())
delete _maps.at(i);
if (_map && !_map->parent())
delete _map;
}

View File

@ -1,5 +1,5 @@
#ifndef OMD_H
#define OMD_H
#ifndef MAPSOURCE_H
#define MAPSOURCE_H
#include <QList>
#include "common/range.h"
@ -8,24 +8,24 @@
class Map;
class QXmlStreamReader;
class OMD
class MapSource
{
public:
~OMD();
MapSource() : _map(0) {}
~MapSource();
bool loadFile(const QString &path);
const QString &errorString() const {return _errorString;}
const QList<Map*> &maps() const {return _maps;}
Map* map() const {return _map;}
private:
RectC bounds(QXmlStreamReader &reader);
Range zooms(QXmlStreamReader &reader);
void map(QXmlStreamReader &reader);
void omd(QXmlStreamReader &reader);
QString _errorString;
QList<Map*> _maps;
Map* _map;
};
#endif // OMD_H
#endif // MAPSOURCE_H