mirror of
https://github.com/tumic0/QtPBFImagePlugin.git
synced 2025-06-30 21:19:16 +02:00
Compare commits
13 Commits
2.5
...
d8a521623a
Author | SHA1 | Date | |
---|---|---|---|
d8a521623a | |||
f5f006dc7b | |||
c86eb7bac2 | |||
3ef6c55d20 | |||
98933deb0e | |||
6e1bc09d62 | |||
ea98da4a74 | |||
8261ee2e79 | |||
d5c315efbe | |||
39ffdaf616 | |||
38b6e2320b | |||
b36fb5fa92 | |||
a7b7d16f4f |
@ -1,4 +1,4 @@
|
||||
version: 2.5.{build}
|
||||
version: 3.0.{build}
|
||||
|
||||
configuration:
|
||||
- Release
|
||||
@ -26,7 +26,7 @@ build_script:
|
||||
nmake release
|
||||
|
||||
artifacts:
|
||||
- path: release\pbf2.dll
|
||||
- path: release\pbf3.dll
|
||||
|
||||
cache:
|
||||
- C:\tools\vcpkg\installed\
|
||||
|
33
README.md
33
README.md
@ -18,24 +18,39 @@ to fit the styles and available data (OpenMapTiles, Mapbox tiles).
|
||||
Due to a major design flaw in the Mapbox vector tiles specification - the zoom
|
||||
is not part of the PBF data - the plugin can not be used "as is", but passing
|
||||
the zoom level is necessary. This is done by exploiting the optional *format*
|
||||
parameter of the QImage constructor or the QImage::fromData() or
|
||||
QPixmap::loadFromData() functions. The zoom number is passed as ASCII string
|
||||
parameter of the QImage constructor or the *QImage::loadFromData()* or
|
||||
*QPixmap::loadFromData()* functions. The zoom number is passed as ASCII string
|
||||
to the functions:
|
||||
```cpp
|
||||
QPixmap pm;
|
||||
pm.loadFromData(tileData, QString::number(zoom).toLatin1());
|
||||
QImage img;
|
||||
img.loadFromData(data, QByteArray::number(zoom));
|
||||
```
|
||||
The plugin supports vector scaling using QImageReader's setScaledSize() method,
|
||||
|
||||
For a complete code sample see the [pbf2png](https://github.com/tumic0/pbf2png)
|
||||
conversion utility.
|
||||
|
||||
### HiDPI
|
||||
The plugin supports vector scaling using QImageReader's *setScaledSize()* method,
|
||||
so when used like in the following example:
|
||||
```cpp
|
||||
QImageReader reader(file, QString::number(zoom).toLatin1());
|
||||
QImage img;
|
||||
QImageReader reader(file, QByteArray::number(zoom));
|
||||
reader.setScaledSize(QSize(1024, 1024));
|
||||
reader.read(&image);
|
||||
reader.read(&img);
|
||||
```
|
||||
you will get 1024x1024px tiles with a pixel ratio of 2 (= HiDPI tiles).
|
||||
|
||||
For a sample code see the [pbf2png](https://github.com/tumic0/pbf2png)
|
||||
conversion utility.
|
||||
### Overzoom
|
||||
Since version 3 of the plugin tile overzoom is supported. If you set *format*
|
||||
to `$zoom;$overzoom`:
|
||||
```cpp
|
||||
QImage img;
|
||||
QByteArray fmt(QByteArray::number(zoom) + ';' + QByteArray::number(overzoom));
|
||||
img.loadFromData(data, fmt);
|
||||
```
|
||||
you will get (512<<overzoom)x(512<<overzoom)px tiles with a pixel ratio of 1.
|
||||
When overzoom is combined with setScaledSize(), the base size is the overzoomed
|
||||
tile size.
|
||||
|
||||
## Styles
|
||||
The map style is loaded from the
|
||||
|
@ -2,7 +2,7 @@ TARGET = pbf
|
||||
TEMPLATE = lib
|
||||
CONFIG += plugin
|
||||
QT += gui
|
||||
VERSION = 2.5
|
||||
VERSION = 3.0
|
||||
|
||||
PROTOS = protobuf/vector_tile.proto
|
||||
include(protobuf/vector_tile.pri)
|
||||
|
@ -79,16 +79,19 @@ bool PBFHandler::read(QImage *image)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ok;
|
||||
int zoom = format().toInt(&ok);
|
||||
QList<QByteArray> list(format().split(';'));
|
||||
int zoom = list.size() ? list.first().toInt() : 0;
|
||||
int overzoom = (list.size() > 1) ? list.at(1).toInt() : 0;
|
||||
|
||||
QSize scaledSize(_scaledSize.isValid()
|
||||
? _scaledSize : QSize(TILE_SIZE, TILE_SIZE));
|
||||
QSize size(scaledSize.width()<<overzoom,
|
||||
scaledSize.height()<<overzoom);
|
||||
QPointF scale((qreal)scaledSize.width() / TILE_SIZE,
|
||||
(qreal)scaledSize.height() / TILE_SIZE);
|
||||
|
||||
QSize size = _scaledSize.isValid()
|
||||
? _scaledSize : QSize(TILE_SIZE, TILE_SIZE);
|
||||
QPointF scale = _scaledSize.isValid()
|
||||
? QPointF((qreal)_scaledSize.width() / TILE_SIZE,
|
||||
(qreal)_scaledSize.height() / TILE_SIZE) : QPointF(1.0, 1.0);
|
||||
*image = QImage(size, QImage::Format_ARGB32_Premultiplied);
|
||||
Tile tile(image, ok ? zoom : -1, scale);
|
||||
Tile tile(image, zoom, scale);
|
||||
|
||||
_style->render(data, tile);
|
||||
|
||||
|
@ -171,6 +171,12 @@ static QList<QPolygonF> polyLines(const QPainterPath &path, const QRectF &rect)
|
||||
return lines;
|
||||
}
|
||||
|
||||
static qreal diff(qreal a1, qreal a2)
|
||||
{
|
||||
qreal d = qAbs(a1 - a2);
|
||||
return (d > 180) ? 360 - d : d;
|
||||
}
|
||||
|
||||
static QPainterPath textPath(const QPainterPath &path, qreal textWidth,
|
||||
qreal maxAngle, qreal charWidth, const QRectF &tileRect)
|
||||
{
|
||||
@ -189,11 +195,16 @@ static QPainterPath textPath(const QPainterPath &path, qreal textWidth,
|
||||
qreal sl = l.length();
|
||||
qreal a = l.angle();
|
||||
|
||||
if ((sl < charWidth) || (j > 1 && qAbs(angle - a) > maxAngle)) {
|
||||
if (sl < charWidth) {
|
||||
if (length > textWidth)
|
||||
return subpath(pl, last, j - 1, length - textWidth);
|
||||
last = j;
|
||||
length = 0;
|
||||
} else if (j > 1 && diff(angle, a) > maxAngle) {
|
||||
if (length > textWidth)
|
||||
return subpath(pl, last, j - 1, length - textWidth);
|
||||
last = j - 1;
|
||||
length = sl;
|
||||
} else
|
||||
length += sl;
|
||||
|
||||
|
@ -2265,7 +2265,6 @@
|
||||
"source": "openmaptiles",
|
||||
"source-layer": "building",
|
||||
"minzoom": 13,
|
||||
"maxzoom": 14,
|
||||
"layout": {
|
||||
"visibility": "visible"
|
||||
},
|
||||
@ -4059,4 +4058,4 @@
|
||||
}
|
||||
],
|
||||
"id": "osm-liberty"
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user