Skip to content

Commit

Permalink
Fix picking for merged features.
Browse files Browse the repository at this point in the history
  • Loading branch information
josephbirkner committed Aug 29, 2024
1 parent 6f23bdf commit f7381a8
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 20 deletions.
2 changes: 1 addition & 1 deletion erdblick_app/app/map.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {PointMergeService} from "./pointmerge.service";
* Combination of a tile id and a feature id, which may be resolved
* to a feature object.
*/
interface TileFeatureId {
export interface TileFeatureId {
featureId: string,
mapTileKey: string,
}
Expand Down
11 changes: 7 additions & 4 deletions erdblick_app/app/pointmerge.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Injectable} from "@angular/core";
import {PointPrimitiveCollection, LabelCollection, Viewer} from "./cesium";
import {coreLib} from "./wasm";
import {TileFeatureId} from "./map.service";

type MapLayerStyleRule = string;
type PositionHash = string;
Expand All @@ -12,12 +13,12 @@ type Cartographic = {x: number, y: number, z: number};
* To this end, the visualization retains visualization parameters for
* calls to either/both Cesium PointPrimitiveCollection.add() and/or LabelCollection.add().
*/
interface MergedPointVisualization {
export interface MergedPointVisualization {
position: Cartographic,
positionHash: PositionHash,
pointParameters?: Record<string, any>|null, // Point Visualization Parameters for call to PointPrimitiveCollection.add().
labelParameters?: Record<string, any>|null, // Label Visualization Parameters for call to LabelCollection.add().
featureIds: Array<string>
featureIds: Array<TileFeatureId>
}

/**
Expand All @@ -44,8 +45,8 @@ export class MergedPointsTile {
this.features.set(point.positionHash, point);
}
else {
for (let fid in point.featureIds) {
if (existingPoint.featureIds.findIndex(v => v == fid) == -1) {
for (let fid of point.featureIds) {
if (existingPoint.featureIds.findIndex(v => v.featureId == fid.featureId) == -1) {
existingPoint.featureIds.push(fid);
}
}
Expand All @@ -72,10 +73,12 @@ export class MergedPointsTile {

for (let [_, feature] of this.features) {
if (feature.pointParameters) {
feature.pointParameters["id"] = feature.featureIds;
this.pointPrimitives.add(feature.pointParameters);
feature.pointParameters = null;
}
if (feature.labelParameters) {
feature.labelParameters["id"] = feature.featureIds;
this.labelPrimitives.add(feature.labelParameters);
feature.labelParameters = null;
}
Expand Down
54 changes: 41 additions & 13 deletions erdblick_app/app/view.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ import {SearchResultPosition} from "./featurefilter.worker";
// Redeclare window with extended interface
declare let window: DebugWindow;

/**
* Determine if two lists of feature wrappers have the same features.
*/
function featureSetsEqual(rhs: FeatureWrapper[], lhs: FeatureWrapper[]) {
return rhs.length === lhs.length && rhs.every(rf => lhs.some(lf => rf.equals(lf)));
}

@Component({
selector: 'erdblick-view',
template: `
Expand Down Expand Up @@ -216,42 +223,63 @@ export class ErdblickViewComponent implements AfterViewInit {
* Set or re-set the hovered feature.
*/
private setHoveredCesiumFeature(feature: any) {
// Get the actual mapget feature for the picked Cesium feature.
let resolvedFeature = feature ? this.mapService.resolveFeature(feature.id) : null;
if (!resolvedFeature) {
this.mapService.hoverTopic.next([]);
// Get the actual mapget features for the picked Cesium feature.
let resolvedFeatures = this.resolveMapgetFeatures(feature);
if (!resolvedFeatures.length) {
this.mapService.selectionTopic.next([]);
return;
}

if (this.mapService.selectionTopic.getValue().some(f => resolvedFeature!.equals(f))) {
if (featureSetsEqual(this.mapService.selectionTopic.getValue(), resolvedFeatures)) {
return;
}
if (this.mapService.hoverTopic.getValue().some(f => resolvedFeature!.equals(f))) {
if (featureSetsEqual(this.mapService.hoverTopic.getValue(), resolvedFeatures)) {
return;
}

this.mapService.hoverTopic.next([resolvedFeature]);
this.mapService.hoverTopic.next(resolvedFeatures);
}

/**
* Set or re-set the picked feature.
*/
private setPickedCesiumFeature(feature: any) {
// Get the actual mapget feature for the picked Cesium feature.
let resolvedFeature = feature ? this.mapService.resolveFeature(feature.id) : null;
if (!resolvedFeature) {
// Get the actual mapget features for the picked Cesium feature.
let resolvedFeatures = this.resolveMapgetFeatures(feature);
if (!resolvedFeatures.length) {
this.mapService.selectionTopic.next([]);
return;
}

if (this.mapService.selectionTopic.getValue().some(f => resolvedFeature!.equals(f))) {
if (featureSetsEqual(this.mapService.selectionTopic.getValue(), resolvedFeatures)) {
return;
}
if (this.mapService.hoverTopic.getValue().some(f => resolvedFeature!.equals(f))) {
if (featureSetsEqual(this.mapService.hoverTopic.getValue(), resolvedFeatures)) {
this.setHoveredCesiumFeature(null);
}

this.mapService.selectionTopic.next([resolvedFeature]);
this.mapService.selectionTopic.next(resolvedFeatures);
}

/**
* Resolve a Cesium primitive feature ID to a list of mapget FeatureWrappers.
*/
private resolveMapgetFeatures(feature: any) {
let resolvedFeatures: FeatureWrapper[] = [];
if (Array.isArray(feature?.id)) {
for (const fid of feature.id) {
const resolvedFeature = this.mapService.resolveFeature(feature.id);
if (resolvedFeature) {
resolvedFeatures = [resolvedFeature];
}
}
} else if (feature) {
const resolvedFeature = this.mapService.resolveFeature(feature.id);
if (resolvedFeature) {
resolvedFeatures = [resolvedFeature];
}
}
return resolvedFeatures;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion erdblick_app/app/visualization.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
HeightReference
} from "./cesium";
import {FeatureLayerStyle, TileFeatureLayer, HighlightMode} from "../../build/libs/core/erdblick-core";
import {PointMergeService} from "./pointmerge.service";
import {MergedPointVisualization, PointMergeService} from "./pointmerge.service";

export interface LocateResolution {
tileId: string,
Expand Down
2 changes: 1 addition & 1 deletion libs/core/src/visualization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ void FeatureLayerVisualization::addMergedPointGeometry(
{"position", JsValue(pointCartographic)},
{"positionHash", JsValue(gridPositionHash)},
{geomField, JsValue(makeGeomParams(evalFun))},
{"featureIds", JsValue::List({JsValue(std::string(id))})},
{"featureIds", JsValue::List({makeTileFeatureId(id)})},
}));
}

Expand Down

0 comments on commit f7381a8

Please sign in to comment.