<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>Focus Area | 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>
camera-position="11.57879, 48.1346375, 865"
<arcgis-zoom slot="top-left"></arcgis-zoom>
<arcgis-navigation-toggle slot="top-left"></arcgis-navigation-toggle>
<arcgis-compass slot="top-left"></arcgis-compass>
<calcite-block expanded id="styleControl" label="Focus area style">
<calcite-segmented-control>
<calcite-segmented-control-item value="dark">Dark</calcite-segmented-control-item>
<calcite-segmented-control-item value="bright" checked
>Bright</calcite-segmented-control-item
<calcite-segmented-control-item value="none">None</calcite-segmented-control-item>
</calcite-segmented-control>
] = await $arcgis.import([
"@arcgis/core/widgets/Sketch/SketchViewModel.js",
"@arcgis/core/symbols/SimpleFillSymbol.js",
"@arcgis/core/Graphic.js",
"@arcgis/core/geometry/Polygon.js",
"@arcgis/core/core/Collection.js",
"@arcgis/core/layers/GraphicsLayer.js",
"@arcgis/core/layers/IntegratedMeshLayer.js",
"@arcgis/core/effects/FocusArea.js",
const viewElement = document.querySelector("arcgis-scene");
const meshLayer = new IntegratedMeshLayer({
url: "https://tiles-eu1.arcgis.com/7cCya5lpv5CmFJHv/arcgis/rest/services/Munich_3D_Mesh_City_Mapper_2_SURE_43/SceneServer",
await viewElement.viewOnReady();
viewElement.map.add(meshLayer);
// Creating the initial focus area
const initialFocusAreaGeometry = new Polygon({
const focusArea = new FocusArea({
outline: { color: [255, 128, 128, 0.55] },
geometries: new Collection([initialFocusAreaGeometry]),
// Adding the focus area to the map with the "bright" style
viewElement.focusAreas.areas.add(focusArea);
viewElement.focusAreas.style = "bright";
// UI control to change the global focus area style and enable/disable focus area
const styleControl = document.getElementsByTagName("calcite-segmented-control")[0];
styleControl.addEventListener("calciteSegmentedControlChange", (e) => {
const selectedValue = e.target.selectedItem.value;
if (selectedValue === "none") {
// Disable the focus area
viewElement.focusAreas.areas.at(0).enabled = false;
// Apply selected style "dark" or "bright"
viewElement.focusAreas.style = e.target.selectedItem.value;
viewElement.focusAreas.areas.at(0).enabled = true;
// Setting up GraphicsLayer, Graphic and SketchViewModel for basic modification of the focus area
const sketchLayer = new GraphicsLayer({
elevationInfo: { mode: "on-the-ground" },
const sketchGraphic = new Graphic({
geometry: viewElement.focusAreas.areas.at(0).geometries.at(0),
symbol: new SimpleFillSymbol({
color: [255, 255, 255, 1 / 255],
sketchLayer.graphics.add(sketchGraphic);
viewElement.map.add(sketchLayer);
function updateFocusArea(event) {
// Using the resulting sketch graphic as input for focus area geometry
focusArea.geometries = new Collection([event.graphics.at(0).geometry]);
// Using sketch view model to allow modifying the graphic and update the focus area accordingly
const sketchViewModel = new SketchViewModel({
sketchViewModel.on("update", (event) => {