<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>Create area of interest for VoxelLayer | Sample | ArcGIS Maps SDK for JavaScript</title>
<!-- Load the ArcGIS Maps SDK for JavaScript from CDN -->
<script type="module" src="https://js.arcgis.com/5.0/"></script>
<arcgis-scene item-id="3a922ed0c7a8489ea4fbe8747ac560ba">
<arcgis-zoom slot="top-left"> </arcgis-zoom>
<arcgis-navigation-toggle slot="top-left"></arcgis-navigation-toggle>
<arcgis-compass slot="top-left"> </arcgis-compass>
<calcite-panel id="panelVoxelControl" style="visibility: hidden" slot="top-right">
<calcite-block label="Voxel slice" expanded>
Vertical Slice (West-East):
label-handles></calcite-slider>
<calcite-button label="Slice" id="addSlice" width="full">Add Slice</calcite-button>
<div class="customSlice" style="display: none">
<calcite-label layout="inline-space-between"
<calcite-label layout="inline-space-between"
<calcite-label layout="inline-space-between"
<calcite-label layout="inline-space-between"
placeholder="Orientation"
<calcite-label layout="inline-space-between"
<arcgis-expand slot="bottom-left">
<arcgis-legend id="expandLegend"></arcgis-legend>
const VoxelSlice = await $arcgis.import("@arcgis/core/layers/voxel/VoxelSlice.js");
// Get references to DOM elements
const viewElement = document.querySelector("arcgis-scene");
const newSliceContainer = document.querySelector(".customSlice");
const panelVoxelControl = document.getElementById("panelVoxelControl");
const sliderXAxisSlice = document.getElementById("sliderXAxisSlice");
const addSlice = document.getElementById("addSlice");
const newSliceXAxisInput = document.getElementById("newSliceXAxisInput");
const newSliceYAxisInput = document.getElementById("newSliceYAxisInput");
const newSliceZAxisInput = document.getElementById("newSliceZAxisInput");
const newOrientationInput = document.getElementById("newOrientationInput");
const newTiltInput = document.getElementById("newTiltInput");
// Wait for the view to fully initialize
await viewElement.viewOnReady();
const voxelLayer = viewElement.map.layers.find((layer) => layer.type === "voxel");
// Wait for the voxel layer to be in the component's view
await viewElement.whenLayerView(voxelLayer);
const voxelVolume = voxelLayer.getVolume(null);
const voxelVolumeSize = voxelVolume.sizeInVoxels;
let countSlice = voxelLayer.getVolumeStyle(null).slices.length;
panelVoxelControl.style.visibility = "visible";
voxelLayer.popupEnabled = true;
// A voxel layer can have multiple slices. Each slice is represented by orientation, tilt and point.
// A vertical slice from West to East
const voxelXSlice = new VoxelSlice({
point: [voxelVolumeSize[0] / 2, 0, 0],
voxelLayer.getVolumeStyle(null).slices = [voxelXSlice];
sliderXAxisSlice.max = voxelVolumeSize[0];
sliderXAxisSlice.value = voxelVolumeSize[0] / 2;
// Listen to changes in the slider's value
// update the point value of the slice
sliderXAxisSlice.addEventListener("calciteSliderInput", function () {
const newPoint = [sliderXAxisSlice.value, 0, 0];
const xSlice = voxelLayer.getVolumeStyle(null).slices.getItemAt(0);
newSliceXAxisInput.max = voxelVolumeSize[0];
newSliceYAxisInput.max = voxelVolumeSize[1];
newSliceZAxisInput.max = voxelVolumeSize[2];
// Modifies the point, orientation and tilt of a slice
function updateNewSlice() {
newSliceXAxisInput.value,
newSliceYAxisInput.value,
newSliceZAxisInput.value,
const nSlice = voxelLayer.getVolumeStyle(null).slices.getItemAt(countSlice - 1);
nSlice.orientation = newOrientationInput.value;
nSlice.tilt = newTiltInput.value;
// Listen to the click event
addSlice.addEventListener("click", function () {
const newSliceContent = document.getElementById("newSliceContent");
newSliceXAxisInput.value = Math.floor(voxelVolumeSize[0] / 2).toString();
newSliceYAxisInput.value = Math.floor(voxelVolumeSize[1] / 2).toString();
newSliceZAxisInput.value = Math.floor(voxelVolumeSize[2] / 2).toString();
newOrientationInput.value = "210";
newTiltInput.value = "45";
addSlice.textContent = "Delete Slice";
newSlice = new VoxelSlice({
orientation: newOrientationInput.value,
tilt: newTiltInput.value,
point: [newSliceXAxisInput.value, newSliceYAxisInput.value, newSliceZAxisInput.value],
//Adding a new slice to the VoxelVolumeStyle
voxelLayer.getVolumeStyle(null).slices.add(newSlice);
newSliceContainer.style = "display:block;";
addSlice.textContent = "Add Slice";
//A slice can be deleted from the collection by using the removeAt method and passing it's index.
voxelLayer.getVolumeStyle(null).slices.removeAt(countSlice - 1);
newSliceContainer.style = "display:none;";
countSlice = voxelLayer.getVolumeStyle(null).slices.length;
// Listen to any changes on the points (X,Y and Z), orientation and tilt
// update the voxel's slice properties
newSliceXAxisInput.addEventListener("calciteInputChange", function () {
newSliceYAxisInput.addEventListener("calciteInputChange", function () {
newSliceZAxisInput.addEventListener("calciteInputChange", function () {
newOrientationInput.addEventListener("calciteInputChange", function () {
newTiltInput.addEventListener("calciteInputChange", function () {