Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: icon line placement #676

Merged
merged 1 commit into from
Jan 13, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ Tiled2dMapVectorSymbolLabelObject::Tiled2dMapVectorSymbolLabelObject(const std::
const ::Coord &coordinate,
const std::optional<std::vector<Coord>> &lineCoordinates,
const Anchor &textAnchor,
const std::optional<double> &angle,
const TextJustify &textJustify,
const std::shared_ptr<FontLoaderResult> fontResult,
const Vec2F &offset,
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -855,6 +873,8 @@ double Tiled2dMapVectorSymbolLabelObject::updatePropertiesLine(VectorModificatio
countOffset += 1;
}
boxMin.x = std::numeric_limits<float>::max();

isPlaced = false;
}

assert(countOffset == countBefore + characterCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class Tiled2dMapVectorSymbolLabelObject {
const ::Coord &coordinate,
const std::optional<std::vector<Coord>> &lineCoordinates,
const Anchor &textAnchor,
const std::optional<double> &angle,
const TextJustify &textJustify,
const std::shared_ptr<FontLoaderResult> fontResult,
const Vec2F &offset,
Expand Down Expand Up @@ -84,6 +83,9 @@ class Tiled2dMapVectorSymbolLabelObject {
std::optional<std::vector<CircleD>> 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);
Expand Down Expand Up @@ -234,8 +236,6 @@ class Tiled2dMapVectorSymbolLabelObject {
std::shared_ptr<SymbolAnimationCoordinator> animationCoordinator;
static constexpr double collisionDistanceBias = 0.75;

bool wasReversed = false;

const std::shared_ptr<Tiled2dMapVectorStateManager> stateManager;

double dpFactor = 1.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ Tiled2dMapVectorSymbolObject::Tiled2dMapVectorSymbolObject(const std::weak_ptr<M
is3d(is3d),
positionSize(is3d ? 3 : 2),
tileOrigin(tileOrigin),
persistingSymbolPlacement(persistingSymbolPlacement) {
persistingSymbolPlacement(persistingSymbolPlacement),
angle(angle) {
auto strongMapInterface = mapInterface.lock();
auto objectFactory = strongMapInterface ? strongMapInterface->getGraphicsObjectFactory() : nullptr;
auto camera = strongMapInterface ? strongMapInterface->getCamera() : nullptr;
Expand Down Expand Up @@ -140,7 +141,7 @@ Tiled2dMapVectorSymbolObject::Tiled2dMapVectorSymbolObject(const std::weak_ptr<M
SymbolAlignment labelRotationAlignment = description->style.getTextRotationAlignment(evalContext);
boundingBoxRotationAlignment = labelRotationAlignment;
labelObject = std::make_shared<Tiled2dMapVectorSymbolLabelObject>(converter, featureContext, description, text, fullText,
coordinate, lineCoordinates, textAnchor, angle,
coordinate, lineCoordinates, textAnchor,
textJustify, fontResult, textOffset, textRadialOffset,
description->style.getTextLineHeight(evalContext),
letterSpacing,
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,6 @@ class Tiled2dMapVectorSymbolObject {

bool is3d;
int positionSize;

const std::optional<double> angle;
};
Loading