Skip to content

Commit

Permalink
FeatureLayerVisualization now creates new compound feature IDs.
Browse files Browse the repository at this point in the history
  • Loading branch information
josephbirkner committed Aug 19, 2024
1 parent 6924b27 commit 582af50
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 78 deletions.
8 changes: 4 additions & 4 deletions erdblick_app/app/features.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {TileLayerParser, TileFeatureLayer} from '../../build/libs/core/erdblick-
* WASM TileFeatureLayer, use the peek()-function.
*/
export class FeatureTile {
id: string;
mapTileKey: string;
nodeId: string;
mapName: string;
layerName: string;
Expand All @@ -31,7 +31,7 @@ export class FeatureTile {
let mapTileMetadata = uint8ArrayToWasm((wasmBlob: any) => {
return parser.readTileLayerMetadata(wasmBlob);
}, tileFeatureLayerBlob);
this.id = mapTileMetadata.id;
this.mapTileKey = mapTileMetadata.id;
this.nodeId = mapTileMetadata.nodeId;
this.mapName = mapTileMetadata.mapName;
this.layerName = mapTileMetadata.layerName;
Expand Down Expand Up @@ -162,7 +162,7 @@ export class FeatureWrapper {
*/
peek(callback: any) {
if (this.featureTile.disposed) {
throw new Error(`Unable to access feature of deleted layer ${this.featureTile.id}!`);
throw new Error(`Unable to access feature of deleted layer ${this.featureTile.mapTileKey}!`);
}
return this.featureTile.peek((tileFeatureLayer: TileFeatureLayer) => {
let feature = tileFeatureLayer.find(this.featureId);
Expand All @@ -182,6 +182,6 @@ export class FeatureWrapper {
if (!other) {
return false;
}
return this.featureTile.id == other.featureTile.id && this.featureId == other.featureId;
return this.featureTile.mapTileKey == other.featureTile.mapTileKey && this.featureId == other.featureId;
}
}
14 changes: 7 additions & 7 deletions erdblick_app/app/map.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ export class MapService {
if (evictTileLayer(tileLayer)) {
tileLayer.destroy();
} else {
newTileLayers.set(tileLayer.id, tileLayer);
newTileLayers.set(tileLayer.mapTileKey, tileLayer);
}
}
this.loadedTileLayers = newTileLayers;
Expand Down Expand Up @@ -527,7 +527,7 @@ export class MapService {
let tileLayer = new FeatureTile(this.tileParser!, tileLayerBlob, preventCulling);

// Consider, if this tile is a selection tile request.
if (this.selectionTileRequest && tileLayer.id == this.selectionTileRequest.tileKey) {
if (this.selectionTileRequest && tileLayer.mapTileKey == this.selectionTileRequest.tileKey) {
this.selectionTileRequest.resolve!(tileLayer);
this.selectionTileRequest = null;
}
Expand All @@ -540,10 +540,10 @@ export class MapService {

// If this one replaces an older tile with the same key,
// then first remove the older existing one.
if (this.loadedTileLayers.has(tileLayer.id)) {
this.removeTileLayer(this.loadedTileLayers.get(tileLayer.id));
if (this.loadedTileLayers.has(tileLayer.mapTileKey)) {
this.removeTileLayer(this.loadedTileLayers.get(tileLayer.mapTileKey));
}
this.loadedTileLayers.set(tileLayer.id, tileLayer);
this.loadedTileLayers.set(tileLayer.mapTileKey, tileLayer);

// Schedule the visualization of the newly added tile layer,
// but don't do it synchronously to avoid stalling the main thread.
Expand All @@ -562,7 +562,7 @@ export class MapService {
tileLayer.destroy()
for (const styleId of this.visualizedTileLayers.keys()) {
const tileVisus = this.visualizedTileLayers.get(styleId)?.filter(tileVisu => {
if (tileVisu.tile.id === tileLayer.id) {
if (tileVisu.tile.mapTileKey === tileLayer.id) {
this.tileVisualizationDestructionTopic.next(tileVisu);
return false;
}
Expand All @@ -575,7 +575,7 @@ export class MapService {
}
}
this.tileVisualizationQueue = this.tileVisualizationQueue.filter(([_, tileVisu]) => {
return tileVisu.tile.id !== tileLayer.id;
return tileVisu.tile.mapTileKey !== tileLayer.id;
});
this.loadedTileLayers.delete(tileLayer.id);
}
Expand Down
2 changes: 1 addition & 1 deletion erdblick_app/app/view.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export class ErdblickViewComponent implements AfterViewInit {

/** Check if the given feature is known and can be selected. */
isKnownCesiumFeature(f: any) {
return f && f.id !== undefined && f.id.hasOwnProperty("type")
return f && f.id !== undefined && f.id.hasOwnProperty("mapTileKey")
}

/**
Expand Down
16 changes: 3 additions & 13 deletions erdblick_app/app/visualization.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class TileVisualization {

/**
* Actually create the visualization.
* @param viewer {Cesium.Viewer} The viewer to add the rendered entity to.
* @param viewer {Viewer} The viewer to add the rendered entity to.
* @return True if anything was rendered, false otherwise.
*/
async render(viewer: Viewer) {
Expand All @@ -168,6 +168,7 @@ export class TileVisualization {
if (this.isHighDetailAndNotEmpty()) {
returnValue = await this.tile.peekAsync(async (tileFeatureLayer: TileFeatureLayer) => {
let visualization = new coreLib.FeatureLayerVisualization(
this.tile.mapTileKey,
this.style,
this.options,
this.pointMergeService,
Expand Down Expand Up @@ -256,7 +257,7 @@ export class TileVisualization {

/**
* Destroy any current visualization.
* @param viewer {Cesium.Viewer} The viewer to remove the rendered entity from.
* @param viewer {Viewer} The viewer to remove the rendered entity from.
*/
destroy(viewer: Viewer) {
this.deleted = true;
Expand All @@ -278,17 +279,6 @@ export class TileVisualization {
this.hasTileBorder = false;
}

/**
* Iterate over all Cesium primitives of this visualization.
*/
forEachPrimitive(callback: any) {
if (this.primitiveCollection) {
for (let i = 0; i < this.primitiveCollection.length; ++i) {
callback(this.primitiveCollection.get(i));
}
}
}

/**
* Check if the visualization is high-detail, and the
* underlying data is not empty.
Expand Down
8 changes: 4 additions & 4 deletions libs/core/include/erdblick/cesium-interface/labels.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

namespace erdblick {

struct CesiumPrimitiveLabelsCollection {

CesiumPrimitiveLabelsCollection();
struct CesiumLabelCollection
{
CesiumLabelCollection();

/**
* Add an individual label to the collection
Expand All @@ -18,7 +18,7 @@ struct CesiumPrimitiveLabelsCollection {
JsValue const &position,
const std::string& labelText,
FeatureStyleRule const &style,
std::string_view const& id,
JsValue const& id,
BoundEvalFun const& evalFun);

/**
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 @@ -18,7 +18,7 @@ struct CesiumPointPrimitiveCollection
void addPoint(
const JsValue& position,
FeatureStyleRule const& style,
std::string_view const& id,
JsValue const& id,
BoundEvalFun const& evalFun);

/**
Expand Down
8 changes: 4 additions & 4 deletions libs/core/include/erdblick/cesium-interface/primitive.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct CesiumPrimitive
void addPolyLine(
JsValue const& vertices,
FeatureStyleRule const& style,
std::string_view const& id,
JsValue const& id,
BoundEvalFun const& evalFun);

/**
Expand All @@ -77,7 +77,7 @@ struct CesiumPrimitive
void addPolygon(
JsValue const& vertices,
FeatureStyleRule const& style,
std::string_view const& id,
JsValue const& id,
BoundEvalFun const& evalFun);

/**
Expand All @@ -91,7 +91,7 @@ struct CesiumPrimitive
void addTriangles(
JsValue const& float64Array,
FeatureStyleRule const& style,
std::string_view const& id,
JsValue const& id,
BoundEvalFun const& evalFun);

/**
Expand All @@ -111,7 +111,7 @@ struct CesiumPrimitive
*/
void addGeometryInstance(
const FeatureStyleRule& style,
std::string_view const& id,
JsValue const& id,
const JsValue& geom,
BoundEvalFun const& evalFun);

Expand Down
11 changes: 9 additions & 2 deletions libs/core/include/erdblick/visualization.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class FeatureLayerVisualization
* Convert a TileFeatureLayer into Cesium primitives based on the provided style.
*/
FeatureLayerVisualization(
std::string const& mapTileKey,
const FeatureLayerStyle& style,
NativeJsValue const& rawOptionValues,
NativeJsValue const& rawFeatureMergeService,
Expand Down Expand Up @@ -177,7 +178,7 @@ class FeatureLayerVisualization
void addPolyLine(
std::vector<mapget::Point> const& vertsCartesian,
const FeatureStyleRule& rule,
std::string_view const& id,
JsValue const& id,
BoundEvalFun const& evalFun);

/**
Expand Down Expand Up @@ -218,8 +219,14 @@ class FeatureLayerVisualization
*/
void addOptionsToSimfilContext(simfil::OverlayNode& context);

/**
* Create a feature primitive ID struct from the mapTileKey_ and the given feature ID.
*/
JsValue makeTileFeatureId(std::string_view const& featureId) const;

/// =========== Generic Members ===========

JsValue mapTileKey_;
bool featuresAdded_ = false;
CesiumPrimitive coloredLines_;
std::map<std::tuple<uint32_t, uint32_t, uint32_t, uint32_t>, CesiumPrimitive> dashLines_;
Expand All @@ -231,7 +238,7 @@ class FeatureLayerVisualization
std::map<uint32_t, CesiumPrimitive> arrowGroundLines_;
CesiumPrimitive coloredGroundMeshes_;
CesiumPointPrimitiveCollection coloredPoints_;
CesiumPrimitiveLabelsCollection labelCollection_;
CesiumLabelCollection labelCollection_;
JsValue featureMergeService_;

FeatureLayerStyle const& style_;
Expand Down
2 changes: 1 addition & 1 deletion libs/core/src/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ EMSCRIPTEN_BINDINGS(erdblick)

////////// FeatureLayerVisualization
em::class_<FeatureLayerVisualization>("FeatureLayerVisualization")
.constructor<FeatureLayerStyle const&, em::val, em::val, FeatureStyleRule::HighlightMode, em::val>()
.constructor<std::string, FeatureLayerStyle const&, em::val, em::val, FeatureStyleRule::HighlightMode, em::val>()
.function("addTileFeatureLayer", &FeatureLayerVisualization::addTileFeatureLayer)
.function("run", &FeatureLayerVisualization::run)
.function("primitiveCollection", &FeatureLayerVisualization::primitiveCollection)
Expand Down
12 changes: 6 additions & 6 deletions libs/core/src/cesium-interface/labels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@

namespace erdblick {

CesiumPrimitiveLabelsCollection::CesiumPrimitiveLabelsCollection() :
CesiumLabelCollection::CesiumLabelCollection() :
labelCollection_(Cesium().LabelCollection.New()) {}

void CesiumPrimitiveLabelsCollection::addLabel(
void CesiumLabelCollection::addLabel(
JsValue const &position,
const std::string &labelText,
FeatureStyleRule const &style,
std::string_view const& id,
JsValue const& id,
BoundEvalFun const& evalFun) {
auto const &color = style.labelColor();
auto const &outlineColor = style.labelOutlineColor();
auto const &bgColor = style.labelBackgroundColor();
auto const &padding = style.labelBackgroundPadding();

auto labelProperties = JsValue::Dict({
{"id", JsValue(id)},
{"id", id},
{"position", position},
{"show", JsValue(true)},
{"text", JsValue(labelText)},
Expand Down Expand Up @@ -66,11 +66,11 @@ void CesiumPrimitiveLabelsCollection::addLabel(
numLabelInstances_++;
}

NativeJsValue CesiumPrimitiveLabelsCollection::toJsObject() const {
NativeJsValue CesiumLabelCollection::toJsObject() const {
return *labelCollection_;
}

bool CesiumPrimitiveLabelsCollection::empty() const {
bool CesiumLabelCollection::empty() const {
return numLabelInstances_ == 0;
}

Expand Down
4 changes: 2 additions & 2 deletions libs/core/src/cesium-interface/points.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ CesiumPointPrimitiveCollection::CesiumPointPrimitiveCollection() :
void CesiumPointPrimitiveCollection::addPoint(
const JsValue& position,
FeatureStyleRule const& style,
std::string_view const& id,
JsValue const& id,
BoundEvalFun const& evalFun)
{
auto const color = style.color(evalFun);
Expand All @@ -25,7 +25,7 @@ void CesiumPointPrimitiveCollection::addPoint(
{"position", position},
{"color", Cesium().Color.New(color.r, color.g, color.b, color.a)},
{"pixelSize", JsValue(style.width())},
{"id", JsValue(id)},
{"id", id},
{"outlineColor", Cesium().Color.New(oColor.r, oColor.g, oColor.b, oColor.a)},
{"outlineWidth", JsValue(style.outlineWidth())},
});
Expand Down
10 changes: 5 additions & 5 deletions libs/core/src/cesium-interface/primitive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ CesiumPrimitive CesiumPrimitive::withPerInstanceColorAppearance(bool flatAndSync
void CesiumPrimitive::addPolyLine(
JsValue const &vertices,
FeatureStyleRule const &style,
std::string_view const& id,
JsValue const& id,
BoundEvalFun const &evalFun) {
JsValue polyline;
if (clampToGround_) {
Expand All @@ -85,7 +85,7 @@ void CesiumPrimitive::addPolyLine(
void CesiumPrimitive::addPolygon(
const JsValue &vertices,
const FeatureStyleRule &style,
std::string_view const& id,
JsValue const& id,
BoundEvalFun const &evalFun) {
auto polygon = Cesium().PolygonGeometry.New({
{"polygonHierarchy", Cesium().PolygonHierarchy.New(*vertices)},
Expand All @@ -98,7 +98,7 @@ void CesiumPrimitive::addPolygon(
void CesiumPrimitive::addTriangles(
const JsValue &float64Array,
const FeatureStyleRule &style,
std::string_view const& id,
JsValue const& id,
BoundEvalFun const &evalFun) {
auto geometry = Cesium().Geometry.New({
{"attributes", JsValue::Dict({
Expand All @@ -115,7 +115,7 @@ void CesiumPrimitive::addTriangles(

void CesiumPrimitive::addGeometryInstance(
const FeatureStyleRule &style,
std::string_view const& id,
JsValue const& id,
const JsValue &geom,
BoundEvalFun const &evalFun) {
auto attributes = JsValue::Dict();
Expand All @@ -125,7 +125,7 @@ void CesiumPrimitive::addGeometryInstance(
}
auto geometryInstance = Cesium().GeometryInstance.New({
{"geometry", geom},
{"id", JsValue(id)},
{"id", id},
{"attributes", attributes}
});
++numGeometryInstances_;
Expand Down
Loading

0 comments on commit 582af50

Please sign in to comment.