Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
86 changes: 39 additions & 47 deletions shared/public/RasterVectorLayerDescription.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#pragma once

#include "VectorLayerDescription.h"
#include "Color.h"
#include "VectorMapSourceDescription.h"
#include "RasterShaderStyle.h"
#include "FeatureValueEvaluator.h"

Expand Down Expand Up @@ -44,7 +44,7 @@ class RasterVectorStyle {

UsedKeysCollection getUsedKeys() const {
UsedKeysCollection usedKeys;
std::shared_ptr<Value> values[] = {
std::shared_ptr<Value> values[] = {
rasterOpacityEvaluator.getValue(),
rasterBrightnessMinEvaluator.getValue(),
rasterBrightnessMaxEvaluator.getValue(),
Expand All @@ -68,7 +68,7 @@ class RasterVectorStyle {
static const BlendMode defaultValue = BlendMode::NORMAL;
return blendModeEvaluator.getResult(context, defaultValue).value;
}

RasterShaderStyle getRasterStyle(const EvaluationContext &context) {
return {
(float) getRasterOpacity(context),
Expand All @@ -85,17 +85,17 @@ class RasterVectorStyle {
double defaultValue = 1.0;
return rasterOpacityEvaluator.getResult(context, defaultValue).value;
}

double getRasterBrightnessMin(const EvaluationContext &context) {
double defaultValue = 0.0;
return rasterBrightnessMinEvaluator.getResult(context, defaultValue).value;
}

double getRasterBrightnessMax(const EvaluationContext &context) {
double defaultValue = 1.0;
return rasterBrightnessMaxEvaluator.getResult(context, defaultValue).value;
}

double getRasterContrast(const EvaluationContext &context) {
double defaultValue = 0.0;
return rasterContrastEvaluator.getResult(context, defaultValue).value;
Expand Down Expand Up @@ -127,68 +127,60 @@ class RasterVectorStyle {
FeatureValueEvaluator<BlendMode> blendModeEvaluator;
};

struct RasterVectorMapSourceDescription : public VectorMapSourceDescription {
bool maskTiles;

RasterVectorMapSourceDescription(std::string identifier,
std::string url,
int minZoom,
int maxZoom,
std::optional<::RectCoord> bounds,
std::optional<float> zoomLevelScaleFactor,
std::optional<bool> adaptScaleToScreen,
std::optional<int> numDrawPreviousLayers,
std::optional<bool> underzoom,
std::optional<bool> overzoom,
std::optional<std::vector<int>> levels,
std::optional<int32_t> coordinateReferenceSystem,
bool maskTiles)
: VectorMapSourceDescription(identifier, url, minZoom, maxZoom, bounds, zoomLevelScaleFactor, adaptScaleToScreen, numDrawPreviousLayers, underzoom, overzoom, levels, coordinateReferenceSystem)
, maskTiles(maskTiles) {}

virtual Tiled2dMapZoomInfo getZoomInfo(bool is3d) const {
auto zoomInfo = VectorMapSourceDescription::getZoomInfo(is3d);
zoomInfo.maskTile = maskTiles;
return zoomInfo;
}
};

class RasterVectorLayerDescription: public VectorLayerDescription {
public:
VectorLayerType getType() override { return VectorLayerType::raster; };

std::string url;
std::shared_ptr<RasterVectorMapSourceDescription> source;
RasterVectorStyle style;
bool adaptScaleToScreen;
int32_t numDrawPreviousLayers;
bool maskTiles;
double zoomLevelScaleFactor;
bool overzoom;
bool underzoom;
std::optional<::RectCoord> bounds;
std::optional<std::string> coordinateReferenceSystem;
std::optional<std::vector<int>> levels;

RasterVectorLayerDescription(std::string identifier,
std::string source,
std::shared_ptr<RasterVectorMapSourceDescription> source,
int minZoom,
int maxZoom,
int sourceMinZoom,
int sourceMaxZoom,
std::string url,
std::shared_ptr<Value> filter,
RasterVectorStyle style,
bool adaptScaleToScreen,
int32_t numDrawPreviousLayers,
bool maskTiles,
double zoomLevelScaleFactor,
std::optional<int32_t> renderPassIndex,
std::shared_ptr<Value> interactable,
bool underzoom,
bool overzoom,
std::optional<::RectCoord> bounds,
std::optional<std::string> coordinateReferenceSystem,
std::optional<std::vector<int>> levels) :
VectorLayerDescription(identifier, source, "", minZoom, maxZoom, sourceMinZoom, sourceMaxZoom, filter, renderPassIndex, interactable, false, false),
style(style), url(url), underzoom(underzoom), overzoom(overzoom), adaptScaleToScreen(adaptScaleToScreen), numDrawPreviousLayers(numDrawPreviousLayers),
maskTiles(maskTiles), zoomLevelScaleFactor(zoomLevelScaleFactor), bounds(bounds), coordinateReferenceSystem(coordinateReferenceSystem), levels(levels) {};

RasterVectorStyle style)
: VectorLayerDescription(identifier, source->identifier, "", minZoom, maxZoom, source->minZoom, source->maxZoom, filter, renderPassIndex, interactable, false, false)
, source(source)
, style(style) {}

std::unique_ptr<VectorLayerDescription> clone() override {
return std::make_unique<RasterVectorLayerDescription>(identifier,
source,
minZoom,
maxZoom,
sourceMinZoom,
sourceMaxZoom,
url,
filter,
style,
adaptScaleToScreen,
numDrawPreviousLayers,
maskTiles,
zoomLevelScaleFactor,
renderPassIndex,
interactable ? interactable->clone() : nullptr,
underzoom,
overzoom,
bounds,
coordinateReferenceSystem,
levels);
style);
}

virtual UsedKeysCollection getUsedKeys() const override {
Expand Down
154 changes: 36 additions & 118 deletions shared/public/Tiled2dMapVectorLayerConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,145 +9,63 @@
*/
#pragma once

#include "RectCoord.h"
#include "Tiled2dMapLayerConfig.h"
#include "Tiled2dMapZoomInfo.h"
#include "Tiled2dMapZoomLevelInfo.h"
#include "VectorMapSourceDescription.h"
#include "VectorLayerDescription.h"
#include "CoordinateSystemIdentifiers.h"
#include "Tiled2dMapVectorSettings.h"
#include "Logger.h"
#include "Tiled2dMapZoomInfo.h"
#include <optional>
#include <vector>
#include <string>

/**
* Abstract base class for different layer configurations.
*/
class Tiled2dMapVectorLayerConfig : public Tiled2dMapLayerConfig {
public:
Tiled2dMapVectorLayerConfig(const std::shared_ptr<VectorMapSourceDescription> &sourceDescription,
const Tiled2dMapZoomInfo &zoomInfo)
: sourceDescription(sourceDescription), zoomInfo(zoomInfo) {}

Tiled2dMapVectorLayerConfig(const std::shared_ptr<VectorMapSourceDescription> &sourceDescription,
const bool is3d)
: sourceDescription(sourceDescription),
zoomInfo(Tiled2dMapZoomInfo(
sourceDescription->zoomLevelScaleFactor ? *sourceDescription->zoomLevelScaleFactor : (is3d ? 0.75 : 1.0),
sourceDescription->numDrawPreviousLayers ? *sourceDescription->numDrawPreviousLayers : 0,
0,
sourceDescription->adaptScaleToScreen ? *sourceDescription->adaptScaleToScreen : false,
true,
sourceDescription->underzoom ? *sourceDescription->underzoom : false,
sourceDescription->overzoom ? *sourceDescription->overzoom : true)) {}

~Tiled2dMapVectorLayerConfig() {}

int32_t getCoordinateSystemIdentifier() override {
return epsg3857Id;
}

std::string getTileUrl(int32_t x, int32_t y, int32_t t, int32_t zoom) override {
std::string url = sourceDescription->vectorUrl;
size_t epsg3857Index = url.find("{bbox-epsg-3857}", 0);
if (epsg3857Index != std::string::npos) {
const auto zoomLevelInfos = getDefaultEpsg3857ZoomLevels(zoom, zoom, std::nullopt);
const Tiled2dMapZoomLevelInfo &zoomLevelInfo = zoomLevelInfos.at(0);
RectCoord layerBounds = zoomLevelInfo.bounds;
const double tileWidth = zoomLevelInfo.tileWidthLayerSystemUnits;
virtual double getZoomIdentifier(double zoom) = 0;
virtual double getZoomFactorAtIdentifier(double zoomIdentifier) = 0;

const bool leftToRight = layerBounds.topLeft.x < layerBounds.bottomRight.x;
const bool topToBottom = layerBounds.topLeft.y < layerBounds.bottomRight.y;
const double tileWidthAdj = leftToRight ? tileWidth : -tileWidth;
const double tileHeightAdj = topToBottom ? tileWidth : -tileWidth;

const double boundsLeft = layerBounds.topLeft.x;
const double boundsTop = layerBounds.topLeft.y;

const Coord topLeft = Coord(epsg3857Id, x * tileWidthAdj + boundsLeft, y * tileHeightAdj + boundsTop, 0);
const Coord bottomRight = Coord(epsg3857Id, topLeft.x + tileWidthAdj, topLeft.y + tileHeightAdj, 0);

std::string boxString = std::to_string(topLeft.x) + "," + std::to_string(bottomRight.y) + "," + std::to_string(bottomRight.x) + "," + std::to_string(topLeft.y);
url = url.replace(epsg3857Index, 16, boxString);
return url;
public:
Tiled2dMapVectorLayerConfig(
std::string layerName,
std::string urlFormat,
const std::optional<RectCoord> &bounds,
const Tiled2dMapZoomInfo &zoomInfo,
const std::vector<int> &levels
);

}
size_t zoomIndex = url.find("{z}", 0);
if (zoomIndex == std::string::npos) throw std::invalid_argument("Layer url \'" + url + "\' has no valid format!");
url = url.replace(zoomIndex, 3, std::to_string(zoom));
size_t xIndex = url.find("{x}", 0);
if (xIndex == std::string::npos) throw std::invalid_argument("Layer url \'" + url + "\' has no valid format!");
url = url.replace(xIndex, 3, std::to_string(x));
size_t yIndex = url.find("{y}", 0);
if (yIndex == std::string::npos) throw std::invalid_argument("Layer url \'" + url + "\' has no valid format!");
return url.replace(yIndex, 3, std::to_string(y));
}
virtual ~Tiled2dMapVectorLayerConfig() = default;

std::vector<Tiled2dMapZoomLevelInfo> getZoomLevelInfos() override {
return getDefaultEpsg3857ZoomLevels(sourceDescription->minZoom, sourceDescription->maxZoom, sourceDescription->levels);
public:
virtual std::string getLayerName() override {
return layerName;
}

std::vector<Tiled2dMapZoomLevelInfo> getVirtualZoomLevelInfos() override {
return getDefaultEpsg3857ZoomLevels(0, sourceDescription->minZoom - 1, sourceDescription->levels);
};
virtual std::string getTileUrl(int32_t x, int32_t y, int32_t t, int32_t zoom) override;

Tiled2dMapZoomInfo getZoomInfo() override {
virtual Tiled2dMapZoomInfo getZoomInfo() override {
return zoomInfo;
}

std::string getLayerName() override {
return sourceDescription->identifier;
std::optional<::RectCoord> getBounds() override {
return bounds;
}

std::optional<Tiled2dMapVectorSettings> getVectorSettings() override {
virtual std::optional<Tiled2dMapVectorSettings> getVectorSettings() override {
return std::nullopt;
}

virtual double getZoomIdentifier(double zoom) {
return std::max(0.0, std::round(log(baseValueZoom * zoomInfo.zoomLevelScaleFactor / zoom) / log(2) * 100) / 100);
}

virtual double getZoomFactorAtIdentifier(double zoomIdentifier) {
double factor = pow(2, zoomIdentifier);
return baseValueZoom * zoomInfo.zoomLevelScaleFactor / factor;
}

std::optional<::RectCoord> getBounds() override {
if (sourceDescription) {
return sourceDescription->bounds;
}
else {
return std::nullopt;
}
}

static std::vector<Tiled2dMapZoomLevelInfo> getDefaultEpsg3857ZoomLevels(int minZoom, int maxZoom, const std::optional<std::vector<int>> &levels) {
std::vector<Tiled2dMapZoomLevelInfo> infos;
if (levels.has_value()) {
for (const auto &level : levels.value()) {
double factor = pow(2, level);
double zoom = baseValueZoom / factor;
double width = baseValueWidth / factor;
infos.push_back(Tiled2dMapZoomLevelInfo(zoom, width, factor, factor, 1, level, epsg3857Bounds));
}
} else {
for (int i = minZoom; i <= maxZoom; i++) {
double factor = pow(2, i);
double zoom = baseValueZoom / factor;
double width = baseValueWidth / factor;
infos.push_back(Tiled2dMapZoomLevelInfo(zoom, width, factor, factor, 1, i, epsg3857Bounds));
}
}
return infos;
}
public:
// Helper to initialize `zoomInfo`
static Tiled2dMapZoomInfo defaultMapZoomInfo();

// Helper to initalize `levels` from min/max zoom levels value
static std::vector<int> generateLevelsFromMinMax(int minZoomLevel, int maxZoomLevel);

protected:
std::shared_ptr<VectorMapSourceDescription> sourceDescription;
std::string layerName;
std::string urlFormat;
Tiled2dMapZoomInfo zoomInfo;

static constexpr double baseValueZoom = 500000000.0;
static constexpr double baseValueWidth = 40075016.0;
static const inline int32_t epsg3857Id = CoordinateSystemIdentifiers::EPSG3857();
static const inline RectCoord epsg3857Bounds = RectCoord(
Coord(epsg3857Id, -20037508.34, 20037508.34, 0.0),
Coord(epsg3857Id, 20037508.34, -20037508.34, 0.0)
);


std::optional<RectCoord> bounds;
std::vector<int> levels; // zoom level indices (kept sorted ascending)
};
3 changes: 2 additions & 1 deletion shared/public/VectorLayerDescription.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
#pragma once

#include "Value.h"
#include <vector>
#include <memory>
#include <optional>

enum VectorLayerType {
background, raster, line, polygon, symbol, custom
Expand Down
31 changes: 27 additions & 4 deletions shared/public/VectorMapSourceDescription.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@

#pragma once

#include "VectorLayerDescription.h"
#include "Color.h"
#include "GeoJsonTypes.h"
#include "RectCoord.h"
#include "Tiled2dMapVectorLayerConfig.h"
#include "Tiled2dMapZoomInfo.h"
#include "VectorLayerDescription.h"

class VectorMapSourceDescription {
public:
Expand All @@ -28,6 +29,7 @@ class VectorMapSourceDescription {
std::optional<bool> underzoom;
std::optional<bool> overzoom;
std::optional<std::vector<int>> levels;
std::optional<int32_t> coordinateReferenceSystem;

VectorMapSourceDescription(std::string identifier,
std::string vectorUrl,
Expand All @@ -39,10 +41,31 @@ class VectorMapSourceDescription {
std::optional<int> numDrawPreviousLayers,
std::optional<bool> underzoom,
std::optional<bool> overzoom,
std::optional<std::vector<int>> levels) :
std::optional<std::vector<int>> levels,
std::optional<int32_t> coordinateReferenceSystem) :
identifier(identifier), vectorUrl(vectorUrl), minZoom(minZoom), maxZoom(maxZoom), bounds(bounds),
adaptScaleToScreen(adaptScaleToScreen), numDrawPreviousLayers(numDrawPreviousLayers),
zoomLevelScaleFactor(zoomLevelScaleFactor), underzoom(underzoom), overzoom(overzoom), levels(levels) {}
zoomLevelScaleFactor(zoomLevelScaleFactor), underzoom(underzoom), overzoom(overzoom), levels(levels),
coordinateReferenceSystem(coordinateReferenceSystem) {}

virtual Tiled2dMapZoomInfo getZoomInfo(bool is3d) const {
return Tiled2dMapZoomInfo(
zoomLevelScaleFactor ? *zoomLevelScaleFactor : (is3d ? 0.75 : 1.0),
numDrawPreviousLayers ? *numDrawPreviousLayers : 0,
0,
adaptScaleToScreen ? *adaptScaleToScreen : false,
true,
underzoom ? *underzoom : false,
overzoom ? *overzoom : true);
};

std::vector<int> getZoomLevels() {
if(levels) {
return *levels;
} else {
return Tiled2dMapVectorLayerConfig::generateLevelsFromMinMax(minZoom, maxZoom);
}
}
};

struct SpriteSourceDescription {
Expand Down
Loading