From 332d1b8e93cac5d89f357487845bf498b22a9fd4 Mon Sep 17 00:00:00 2001 From: Stefan Mitterrutzner Date: Mon, 13 Jan 2025 15:17:30 +0100 Subject: [PATCH] implements icon on line placement and text on line offset calculation --- .../symbol/Tiled2dMapVectorSymbolGroup.cpp | 2 +- .../Tiled2dMapVectorSymbolLabelObject.cpp | 24 +++++++++++++++++-- .../Tiled2dMapVectorSymbolLabelObject.h | 6 ++--- .../symbol/Tiled2dMapVectorSymbolObject.cpp | 15 ++++++++---- .../symbol/Tiled2dMapVectorSymbolObject.h | 2 ++ 5 files changed, 39 insertions(+), 10 deletions(-) diff --git a/shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolGroup.cpp b/shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolGroup.cpp index c3ff738c5..ff20b2eb1 100644 --- a/shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolGroup.cpp +++ b/shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolGroup.cpp @@ -963,7 +963,7 @@ Tiled2dMapVectorSymbolGroup::getPositioning(std::vector<::Coord>::const_iterator } } - double angle = -atan2(next->y - prev->y, next->x - prev->x) * (180.0 / M_PI); + double angle = -atan2(prev->y - next->y, -(prev->x - next->x)) * (180.0 / M_PI); auto midpoint = Vec2D(onePrev->x * (1.0 - interpolationValue) + iterator->x * interpolationValue, onePrev->y * (1.0 - interpolationValue) + iterator->y * interpolationValue); return Tiled2dMapVectorSymbolSubLayerPositioningWrapper(angle, Coord(next->systemIdentifier, midpoint.x, midpoint.y, next->z)); diff --git a/shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolLabelObject.cpp b/shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolLabelObject.cpp index c4379dcdd..b838deefa 100644 --- a/shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolLabelObject.cpp +++ b/shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolLabelObject.cpp @@ -25,7 +25,6 @@ Tiled2dMapVectorSymbolLabelObject::Tiled2dMapVectorSymbolLabelObject(const std:: const ::Coord &coordinate, const std::optional> &lineCoordinates, const Anchor &textAnchor, - const std::optional &angle, const TextJustify &textJustify, const std::shared_ptr fontResult, const Vec2F &offset, @@ -678,7 +677,24 @@ double Tiled2dMapVectorSymbolLabelObject::updatePropertiesLine(VectorModificatio } // updates currentIndex - indexAtDistance(currentIndex, -size * 0.5 * scaleCorrection, std::nullopt, currentIndex); + + switch (textAnchor) { + case Anchor::TOP_LEFT: + case Anchor::LEFT: + case Anchor::BOTTOM_LEFT: + indexAtDistance(currentIndex, fontSize * scaleCorrection, std::nullopt, currentIndex); + break; + case Anchor::TOP_RIGHT: + case Anchor::RIGHT: + case Anchor::BOTTOM_RIGHT: + indexAtDistance(currentIndex, -size * 1.0 * scaleCorrection, std::nullopt, currentIndex); + break; + case Anchor::CENTER: + case Anchor::TOP: + case Anchor::BOTTOM: + indexAtDistance(currentIndex, -size * 0.5 * scaleCorrection, std::nullopt, currentIndex); + break; + } auto yOffset = offset.y * fontSize; @@ -841,6 +857,8 @@ double Tiled2dMapVectorSymbolLabelObject::updatePropertiesLine(VectorModificatio countOffset += 1; } + + isPlaced = true; } else { for (int i = 0; i != characterCount; i++) { positions[(2 * countOffset) + 0] = 0; @@ -855,6 +873,8 @@ double Tiled2dMapVectorSymbolLabelObject::updatePropertiesLine(VectorModificatio countOffset += 1; } boxMin.x = std::numeric_limits::max(); + + isPlaced = false; } assert(countOffset == countBefore + characterCount); diff --git a/shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolLabelObject.h b/shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolLabelObject.h index 1e746ac4a..cccfd3c4f 100644 --- a/shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolLabelObject.h +++ b/shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolLabelObject.h @@ -51,7 +51,6 @@ class Tiled2dMapVectorSymbolLabelObject { const ::Coord &coordinate, const std::optional> &lineCoordinates, const Anchor &textAnchor, - const std::optional &angle, const TextJustify &textJustify, const std::shared_ptr fontResult, const Vec2F &offset, @@ -84,6 +83,9 @@ class Tiled2dMapVectorSymbolLabelObject { std::optional> boundingBoxCircles = std::nullopt; bool isOpaque = true; + bool wasReversed = false; + + bool isPlaced = true; Vec2D dimensions = Vec2D(0.0, 0.0); Vec3D tileOrigin = Vec3D(0,0,0); @@ -234,8 +236,6 @@ class Tiled2dMapVectorSymbolLabelObject { std::shared_ptr animationCoordinator; static constexpr double collisionDistanceBias = 0.75; - bool wasReversed = false; - const std::shared_ptr stateManager; double dpFactor = 1.0; diff --git a/shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolObject.cpp b/shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolObject.cpp index 29102fd5c..608688c05 100644 --- a/shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolObject.cpp +++ b/shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolObject.cpp @@ -63,7 +63,8 @@ Tiled2dMapVectorSymbolObject::Tiled2dMapVectorSymbolObject(const std::weak_ptrgetGraphicsObjectFactory() : nullptr; auto camera = strongMapInterface ? strongMapInterface->getCamera() : nullptr; @@ -140,7 +141,7 @@ Tiled2dMapVectorSymbolObject::Tiled2dMapVectorSymbolObject(const std::weak_ptrstyle.getTextRotationAlignment(evalContext); boundingBoxRotationAlignment = labelRotationAlignment; labelObject = std::make_shared(converter, featureContext, description, text, fullText, - coordinate, lineCoordinates, textAnchor, angle, + coordinate, lineCoordinates, textAnchor, textJustify, fontResult, textOffset, textRadialOffset, description->style.getTextLineHeight(evalContext), letterSpacing, @@ -478,7 +479,13 @@ void Tiled2dMapVectorSymbolObject::updateIconProperties(VectorModificationWrappe rotations[countOffset] = iconRotate; - if (iconRotationAlignment == SymbolAlignment::VIEWPORT || + if ((textSymbolPlacement == TextSymbolPlacement::LINE || textSymbolPlacement == TextSymbolPlacement::LINE_CENTER) && angle) { + if (labelObject && labelObject->wasReversed) { + rotations[countOffset] += std::fmod(*angle + 180.0, 360.0); + } else { + rotations[countOffset] += *angle; + } + } else if (iconRotationAlignment == SymbolAlignment::VIEWPORT || (iconRotationAlignment == SymbolAlignment::AUTO && textSymbolPlacement == TextSymbolPlacement::POINT)) { rotations[countOffset] += rotation; } @@ -566,7 +573,7 @@ void Tiled2dMapVectorSymbolObject::updateIconProperties(VectorModificationWrappe iconBoundingBoxViewportAligned.height = iconHeight + 2.0 * scaledIconPadding; } - if (!isCoordinateOwner) { + if (!isCoordinateOwner || (labelObject && !labelObject->isPlaced)) { alphas[countOffset] = 0.0; } else if (!(description->minZoom <= zoomIdentifier && description->maxZoom >= zoomIdentifier)) { alphas[countOffset] = animationCoordinator->getIconAlpha(0.0, now); diff --git a/shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolObject.h b/shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolObject.h index 23e104275..862ee36d6 100644 --- a/shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolObject.h +++ b/shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolObject.h @@ -205,4 +205,6 @@ class Tiled2dMapVectorSymbolObject { bool is3d; int positionSize; + + const std::optional angle; };