Skip to content

Commit

Permalink
Merge pull request #1678 from xeokit/XCD-158-example-zone-hide-show
Browse files Browse the repository at this point in the history
XCD-158 Demonstrate Zone hiding and showing with an example
  • Loading branch information
xeolabs authored Sep 20, 2024
2 parents 0ab414d + 81a73c3 commit eebb4fd
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions examples/zone/ZonesPlugin_createZones.html
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,33 @@ <h3>Resources</h3>
return annotations.annotations["myAnnotation_" + zone.id];
};

const setZoneVisible = function(zone, visible) {
zone.visible = visible;
const zoneAnnotation = getZoneAnnotation(zone);
if (zoneAnnotation)
{
zoneAnnotation.setMarkerShown(visible);
zoneAnnotation.setLabelShown(visible);
}
};

const sceneContextMenu = new ContextMenu({
items: [
[
{
title: "Hide visible Zones ",
getEnabled: context => (zonesPlugin.zones.filter(z => z.visible).length > 0),
doAction: context => zonesPlugin.zones.filter(z => z.visible).forEach(z => setZoneVisible(z, false))
},
{
title: "Show hidden Zones ",
getEnabled: context => (zonesPlugin.zones.filter(z => !z.visible).length > 0),
doAction: context => zonesPlugin.zones.filter(z => !z.visible).forEach(z => setZoneVisible(z, true))
}
]
]
});

let curZoneEdit = null;

const zoneEditContextMenu = new ContextMenu({
Expand Down Expand Up @@ -379,6 +406,10 @@ <h3>Resources</h3>
startZoneTranslate(newZone);
}
},
{
title: "Hide Zone",
doAction: contextZone => setZoneVisible(contextZone, false)
},
{
title: "Delete Zone",
doAction: function(contextZone) {
Expand Down Expand Up @@ -420,6 +451,11 @@ <h3>Resources</h3>
curZoneContextMenu.context = pickZone;
curZoneContextMenu.show(canvasPos[0], canvasPos[1] + 50);
}
else
{
sceneContextMenu.context = { };
sceneContextMenu.show(canvasPos[0], canvasPos[1] + 50);
}
});

const zonesPlugin = new ZonesPlugin(viewer);
Expand Down

0 comments on commit eebb4fd

Please sign in to comment.