Skip to content

Commit

Permalink
Added support for icon URLs.
Browse files Browse the repository at this point in the history
  • Loading branch information
josephbirkner committed Nov 6, 2024
1 parent cc31551 commit b206919
Show file tree
Hide file tree
Showing 13 changed files with 229 additions and 61 deletions.
106 changes: 54 additions & 52 deletions README.md

Large diffs are not rendered by default.

20 changes: 17 additions & 3 deletions erdblick_app/app/pointmerge.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
PointPrimitiveCollection,
LabelCollection,
Viewer,
Entity
Entity,
BillboardCollection
} from "./cesium";
import {coreLib} from "./wasm";
import {TileFeatureId} from "./parameters.service";
Expand Down Expand Up @@ -38,6 +39,7 @@ export class MergedPointsTile {

referencingTiles: Array<bigint> = [];

billboardPrimitives: BillboardCollection|null = null;
pointPrimitives: PointPrimitiveCollection|null = null;
labelPrimitives: LabelCollection|null = null;
debugEntity: Entity|null = null;
Expand Down Expand Up @@ -73,17 +75,23 @@ export class MergedPointsTile {
}

render(viewer: Viewer) {
if (this.pointPrimitives || this.labelPrimitives) {
if (this.pointPrimitives || this.labelPrimitives || this.billboardPrimitives) {
this.remove(viewer);
}

this.billboardPrimitives = new BillboardCollection();
this.pointPrimitives = new PointPrimitiveCollection();
this.labelPrimitives = new LabelCollection();

for (let [_, feature] of this.features) {
if (feature.pointParameters) {
feature.pointParameters["id"] = feature.featureIds;
this.pointPrimitives.add(feature.pointParameters);
if (feature.pointParameters.hasOwnProperty("image")) {
this.billboardPrimitives.add(feature.pointParameters);
}
else {
this.pointPrimitives.add(feature.pointParameters);
}
}
if (feature.labelParameters) {
feature.labelParameters["id"] = feature.featureIds;
Expand All @@ -94,6 +102,9 @@ export class MergedPointsTile {
if (this.pointPrimitives.length) {
viewer.scene.primitives.add(this.pointPrimitives)
}
if (this.billboardPrimitives.length) {
viewer.scene.primitives.add(this.billboardPrimitives)
}
if (this.labelPrimitives.length) {
viewer.scene.primitives.add(this.labelPrimitives)
}
Expand Down Expand Up @@ -130,6 +141,9 @@ export class MergedPointsTile {
if (this.pointPrimitives && this.pointPrimitives.length) {
viewer.scene.primitives.remove(this.pointPrimitives)
}
if (this.billboardPrimitives && this.billboardPrimitives.length) {
viewer.scene.primitives.remove(this.billboardPrimitives)
}
if (this.labelPrimitives && this.labelPrimitives.length) {
viewer.scene.primitives.remove(this.labelPrimitives)
}
Expand Down
2 changes: 2 additions & 0 deletions libs/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ set(ERDBLICK_SOURCE_FILES
include/erdblick/cesium-interface/point-conversion.h
include/erdblick/cesium-interface/points.h
include/erdblick/cesium-interface/labels.h
include/erdblick/cesium-interface/billboards.h

src/visualization.cpp
src/style.cpp
Expand All @@ -39,6 +40,7 @@ set(ERDBLICK_SOURCE_FILES
src/cesium-interface/cesium.cpp
src/cesium-interface/points.cpp
src/cesium-interface/labels.cpp
src/cesium-interface/billboards.cpp
)

if(${CMAKE_SYSTEM_NAME} STREQUAL "Emscripten")
Expand Down
52 changes: 52 additions & 0 deletions libs/core/include/erdblick/cesium-interface/billboards.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#pragma once

#include "cesium.h"
#include "simfil/model/model.h"
#include "mapget/model/featurelayer.h"
#include "../rule.h"
#include "points.h"

namespace erdblick
{

struct CesiumBillboardCollection
{
CesiumBillboardCollection();

/**
* Add an individual billboard to the collection.
*/
void addBillboard(
const JsValue& position,
FeatureStyleRule const& style,
JsValue const& id,
BoundEvalFun const& evalFun);

/**
* Get the parameters for a BillboardCollection::add() call.
*/
static JsValue billboardParams(
const JsValue& position,
FeatureStyleRule const& style,
JsValue const& id,
BoundEvalFun const& evalFun);

/**
* Construct a JS Primitive from the provided Geometry instances.
*/
[[nodiscard]] NativeJsValue toJsObject() const;

/**
* Check if any geometry has been added to the primitive.
*/
bool empty() const;

private:
/** Number of billboards in this collection. */
size_t numGeometryInstances_ = 0;

/** Wrapped billboard primitive object from Cesium */
JsValue billboardCollection_;
};

}
1 change: 1 addition & 0 deletions libs/core/include/erdblick/cesium-interface/cesium.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct CesiumLib
CesiumClass PrimitiveType;
CesiumClass Label;
CesiumClass LabelCollection;
CesiumClass BillboardCollection;
CesiumClass HorizontalOrigin;
CesiumClass VerticalOrigin;
CesiumClass LabelStyle;
Expand Down
2 changes: 1 addition & 1 deletion libs/core/include/erdblick/cesium-interface/labels.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct CesiumLabelCollection
/**
* Get the parameter object for a call to LabelCollection.add().
*/
JsValue labelParams(
static JsValue labelParams(
JsValue const &position,
const std::string& labelText,
FeatureStyleRule const &style,
Expand Down
2 changes: 1 addition & 1 deletion libs/core/include/erdblick/cesium-interface/points.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct CesiumPointPrimitiveCollection
/**
* Get the parameters for a PointPrimitiveCollection::add() call.
*/
JsValue pointParams(
static JsValue pointParams(
const JsValue& position,
FeatureStyleRule const& style,
JsValue const& id,
Expand Down
6 changes: 6 additions & 0 deletions libs/core/include/erdblick/rule.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ class FeatureStyleRule
[[nodiscard]] glm::dvec3 const& offset() const;
[[nodiscard]] std::optional<glm::dvec3> const& pointMergeGridCellSize() const;

[[nodiscard]] bool hasIconUrl() const;
[[nodiscard]] std::string iconUrl(BoundEvalFun const& evalFun) const;

[[nodiscard]] std::optional<std::regex> const& relationType() const;
[[nodiscard]] float relationLineHeightOffset() const;
[[nodiscard]] std::shared_ptr<FeatureStyleRule> relationLineEndMarkerStyle() const;
Expand Down Expand Up @@ -151,6 +154,9 @@ class FeatureStyleRule
std::optional<std::array<float, 4>> scaleByDistance_;
std::optional<std::array<float, 4>> offsetScaleByDistance_;

std::string iconUrl_;
std::string iconUrlExpression_;

std::optional<std::regex> relationType_;
float relationLineHeightOffset_ = 1.0; // Offset of the relation line over the center in m.
std::shared_ptr<FeatureStyleRule> relationLineEndMarkerStyle_;
Expand Down
2 changes: 2 additions & 0 deletions libs/core/include/erdblick/visualization.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "cesium-interface/points.h"
#include "cesium-interface/primitive.h"
#include "cesium-interface/labels.h"
#include "cesium-interface/billboards.h"
#include "style.h"
#include "simfil/overlay.h"
#include "layer.h"
Expand Down Expand Up @@ -274,6 +275,7 @@ class FeatureLayerVisualization
CesiumPrimitive coloredGroundMeshes_;
CesiumPointPrimitiveCollection coloredPoints_;
CesiumLabelCollection labelCollection_;
CesiumBillboardCollection billboardCollection_;

// Map from map-layer-style-rule-id to map from grid-position-hash
// to pair of feature-id-set and MergedPointVisualization.
Expand Down
48 changes: 48 additions & 0 deletions libs/core/src/cesium-interface/billboards.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "cesium-interface/billboards.h"
#include "cesium-interface/cesium.h"
#include "simfil/model/model.h"

#include <iostream>

namespace erdblick
{

CesiumBillboardCollection::CesiumBillboardCollection() :
billboardCollection_(Cesium().PointPrimitiveCollection.New())
{}

JsValue CesiumBillboardCollection::billboardParams(
const JsValue& position,
const FeatureStyleRule& style,
const JsValue& id,
const BoundEvalFun& evalFun)
{
auto result = CesiumPointPrimitiveCollection::pointParams(position, style, id, evalFun);
if (style.hasIconUrl()) {
result.set("image", JsValue(style.iconUrl(evalFun)));
}
return result;
}

void CesiumBillboardCollection::addBillboard(
const JsValue& position,
FeatureStyleRule const& style,
JsValue const& id,
BoundEvalFun const& evalFun)
{
auto params = billboardParams(position, style, id, evalFun);
billboardCollection_.call<void>("add", *params);
++numGeometryInstances_;
}

[[nodiscard]] NativeJsValue CesiumBillboardCollection::toJsObject() const
{
return *billboardCollection_;
}

bool CesiumBillboardCollection::empty() const
{
return numGeometryInstances_ == 0;
}

}
1 change: 1 addition & 0 deletions libs/core/src/cesium-interface/cesium.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ CesiumLib::CesiumLib() :
PrimitiveType("PrimitiveType"),
Label("Label"),
LabelCollection("LabelCollection"),
BillboardCollection("BillboardCollection"),
HorizontalOrigin("HorizontalOrigin"),
VerticalOrigin("VerticalOrigin"),
LabelStyle("LabelStyle"),
Expand Down
24 changes: 24 additions & 0 deletions libs/core/src/rule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ void FeatureStyleRule::parse(const YAML::Node& yaml)
pointMergeGridCellSize_->y = yaml["point-merge-grid-cell"][1].as<double>();
pointMergeGridCellSize_->z = yaml["point-merge-grid-cell"][2].as<double>();
}
if (yaml["icon-url"].IsDefined()) {
iconUrl_ = yaml["icon-url"].as<std::string>();
}
if (yaml["icon-url-expression"].IsDefined()) {
iconUrlExpression_ = yaml["icon-url-expression"].as<std::string>();
}

/////////////////////////////////////
/// Line Style Fields
Expand Down Expand Up @@ -662,6 +668,24 @@ std::optional<glm::dvec3> const& FeatureStyleRule::pointMergeGridCellSize() cons
return pointMergeGridCellSize_;
}

bool FeatureStyleRule::hasIconUrl() const
{
return !iconUrl_.empty() || !iconUrlExpression_.empty();
}

std::string FeatureStyleRule::iconUrl(BoundEvalFun const& evalFun) const
{
if (!iconUrlExpression_.empty()) {
auto iconUrlVal = evalFun.eval_(iconUrlExpression_);
if (iconUrlVal.isa(simfil::ValueType::String)) {
return iconUrlVal.as<simfil::ValueType::String>();
}
std::cout << "Invalid result for iconUrl expression: " << iconUrlExpression_
<< ": " << iconUrlVal.toString() << std::endl;
}
return iconUrl_;
}

std::optional<std::regex> const& FeatureStyleRule::attributeType() const
{
return attributeType_;
Expand Down
24 changes: 20 additions & 4 deletions libs/core/src/visualization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include <iostream>

#include "cesium-interface/billboards.h"

using namespace mapget;

namespace erdblick
Expand Down Expand Up @@ -158,6 +160,8 @@ NativeJsValue FeatureLayerVisualization::primitiveCollection() const
collection.call<void>("add", coloredPoints_.toJsObject());
if (!labelCollection_.empty())
collection.call<void>("add", labelCollection_.toJsObject());
if (!billboardCollection_.empty())
collection.call<void>("add", billboardCollection_.toJsObject());
return *collection;
}

Expand Down Expand Up @@ -351,7 +355,6 @@ void FeatureLayerVisualization::addGeometry(
case GeomType::Points:
auto pointIndex = 0;
for (auto const& pt : vertsCartesian) {

// If a merge-grid cell size is set, then a merged feature representation was requested.
if (auto const& gridCellSize = rule.pointMergeGridCellSize()) {
addMergedPointGeometry(
Expand All @@ -363,12 +366,25 @@ void FeatureLayerVisualization::addGeometry(
evalFun,
[&](auto& augmentedEvalFun)
{
return coloredPoints_
.pointParams(JsValue(pt), rule, tileFeatureId, augmentedEvalFun);
if (rule.hasIconUrl())
return CesiumBillboardCollection::billboardParams(
JsValue(pt),
rule,
tileFeatureId,
augmentedEvalFun);
return CesiumPointPrimitiveCollection::pointParams(
JsValue(pt),
rule,
tileFeatureId,
augmentedEvalFun);
});
}
else
else if (rule.hasIconUrl()) {
billboardCollection_.addBillboard(JsValue(pt), rule, tileFeatureId, evalFun);
}
else {
coloredPoints_.addPoint(JsValue(pt), rule, tileFeatureId, evalFun);
}

++pointIndex;
}
Expand Down

0 comments on commit b206919

Please sign in to comment.