Skip to content

Commit

Permalink
Fix #1092 markers: hide/show layer markers
Browse files Browse the repository at this point in the history
  • Loading branch information
mistic100 committed Sep 28, 2023
1 parent edcdc79 commit f3a8399
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
10 changes: 5 additions & 5 deletions packages/markers-plugin/src/Marker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export class Marker {
* The final description of the marker. Either text content, image, url, SVG attributes, etc.
*/
definition: any;
visible = true;

/** @internal */
tooltip?: Tooltip;
Expand Down Expand Up @@ -389,8 +388,9 @@ export class Marker {
...this.config.hoverScale,
};
}

this.visible = this.config.visible !== false;
if (utils.isNil(this.config.visible)) {
this.config.visible = true;
}

this.state.anchor = utils.parsePoint(this.config.anchor);

Expand Down Expand Up @@ -844,10 +844,10 @@ export class Marker {
Object.defineProperty(element, 'visible', {
enumerable: true,
get: function (this: Object3D) {
return (this.children[0].userData[MARKER_DATA] as Marker).visible;
return (this.children[0].userData[MARKER_DATA] as Marker).state.visible;
},
set: function (this: Object3D, visible: boolean) {
(this.children[0].userData[MARKER_DATA] as Marker).visible = visible;
(this.children[0].userData[MARKER_DATA] as Marker).state.visible = visible;
},
});

Expand Down
27 changes: 19 additions & 8 deletions packages/markers-plugin/src/MarkersPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ export class MarkersPlugin extends AbstractConfigurablePlugin<
showAllTooltips: false,
currentMarker: null as Marker,
hoveringMarker: null as Marker,
// require a 2nd render (only the scene) when 3d markers visibility changes
needsReRender: false,
};

private readonly container: HTMLElement;
Expand Down Expand Up @@ -222,9 +224,7 @@ export class MarkersPlugin extends AbstractConfigurablePlugin<
*/
showAllMarkers() {
this.state.visible = true;

this.renderMarkers();

this.dispatchEvent(new ShowMarkersEvent());
}

Expand All @@ -233,9 +233,7 @@ export class MarkersPlugin extends AbstractConfigurablePlugin<
*/
hideAllMarkers() {
this.state.visible = false;

this.renderMarkers();

this.dispatchEvent(new HideMarkersEvent());
}

Expand Down Expand Up @@ -488,8 +486,8 @@ export class MarkersPlugin extends AbstractConfigurablePlugin<
*/
toggleMarker(markerId: string | MarkerConfig, visible?: boolean) {
const marker = this.getMarker(markerId);
marker.visible = visible === null ? !marker.visible : visible;
this.viewer.needsUpdate();
marker.config.visible = utils.isNil(visible) ? !marker.config.visible : visible;
this.renderMarkers();
}

/**
Expand Down Expand Up @@ -532,7 +530,7 @@ export class MarkersPlugin extends AbstractConfigurablePlugin<
showMarkersList() {
let markers: Marker[] = [];
Object.values(this.markers).forEach((marker) => {
if (marker.visible && !marker.config.hideList) {
if (marker.state.visible && !marker.config.hideList) {
markers.push(marker);
}
});
Expand Down Expand Up @@ -572,11 +570,16 @@ export class MarkersPlugin extends AbstractConfigurablePlugin<
* Updates the visibility and the position of all markers
*/
renderMarkers() {
if (this.state.needsReRender) {
this.state.needsReRender = false;
return;
}

const zoomLevel = this.viewer.getZoomLevel();
const viewerPosition = this.viewer.getPosition();

Object.values(this.markers).forEach((marker) => {
let isVisible = this.state.visible && marker.visible;
let isVisible = this.state.visible && marker.config.visible;
let visibilityChanged = false;
let position: Point = null;

Expand Down Expand Up @@ -640,8 +643,16 @@ export class MarkersPlugin extends AbstractConfigurablePlugin<

if (visibilityChanged) {
this.dispatchEvent(new MarkerVisibilityEvent(marker, isVisible));

if (marker.is3d()) {
this.state.needsReRender = true;
}
}
});

if (this.state.needsReRender) {
this.viewer.needsUpdate();
}
}

/**
Expand Down

0 comments on commit f3a8399

Please sign in to comment.