Skip to content

Commit

Permalink
Merge pull request #622 from openmobilemaps/feature/epsg-url-template
Browse files Browse the repository at this point in the history
Feature/epsg url template
  • Loading branch information
maerki authored Apr 12, 2024
2 parents adf8dba + add089d commit 12e1eba
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog for Open Mobile Maps

## Version 2.2.0
- Adds support for `{bbox-epsg-3857}` placeholder in URL template

## Version 2.1.0 (08.04.2024)
- Adds dotted line style (line-dotted boolean and an optional skewFactor, defaulting to 1.0 and denoting the stretch factor)
- Fixes style for short dashes
Expand Down
23 changes: 23 additions & 0 deletions shared/public/Tiled2dMapVectorLayerConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,29 @@ class Tiled2dMapVectorLayerConfig : public Tiled2dMapLayerConfig {

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);
const Tiled2dMapZoomLevelInfo &zoomLevelInfo = zoomLevelInfos.at(0);
RectCoord layerBounds = zoomLevelInfo.bounds;
const double tileWidth = zoomLevelInfo.tileWidthLayerSystemUnits;

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;

}
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));
Expand Down

0 comments on commit 12e1eba

Please sign in to comment.