Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html>
  <head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="initial-scale=1,maximum-scale=1,user-scalable=no"
    />
    <!--
  ArcGIS API for JavaScript, https://js.arcgis.com
  For more information about the layers-scenelayer-feature-masking sample, read the original sample description at developers.arcgis.com.
  https://developers.arcgis.com/javascript/latest/sample-code/layers-scenelayer-feature-masking/index.html
  -->
<title>Filtrer des entités par une géométrie dans une scène 3D</title>
    <style>
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }

      #infoDiv {
        background-color: white;
        padding: 10px;
        width: 260px;
        margin: 5px;
        position: absolute;
        bottom: 15px;
        right: 10px;
        font-size: 14px;
        display: none;
      }

      .geometry-options {
        display: flex;
        flex-direction: row;
      }

      .geometry-button {
        flex: 1;
        border-style: solid;
        border-width: 1px;
        border-image: none;
      }

      .geometry-button-selected {
        background: #4c4c4c;
        color: #fff;
      }

      .options {
        max-width: 260px;
        width: 100%;
        height: 25px;
      }

      #bufferNum {
        width: 80%;
      }
    </style>

    <link
      rel="stylesheet"
      href="https://js.arcgis.com/4.11/esri/themes/light/main.css"
    />
    <script src="https://js.arcgis.com/4.11/"></script>

    <script>
      require([
        "esri/WebScene",
        "esri/views/SceneView",
        "esri/layers/GraphicsLayer",
        "esri/widgets/Sketch/SketchViewModel",
        "esri/views/layers/support/FeatureFilter",
        "esri/geometry/geometryEngine",
        "esri/Graphic"
      ], function(
        WebScene,
        SceneView,
        GraphicsLayer,
        SketchViewModel,
        FeatureFilter,
        geometryEngine,
        Graphic
      ) {
        // Load webscene and display it in a SceneView
        const webscene = new WebScene({
          portalItem: {
            id: "47241277f5c249d6b1c13840192a7cb0"
          }
        });

        // create the SceneView
        const view = new SceneView({
          container: "viewDiv",
          map: webscene
        });

        // add a GraphicsLayer for the sketches and the buffer
        let sketchLayer = new GraphicsLayer();
        let bufferLayer = new GraphicsLayer();
        view.map.addMany([bufferLayer, sketchLayer]);

        // create the layerView's to add the filter
        let sceneLayerView = null;
        let featureLayerView = null;
        view.map.load().then(function() {
          // loop through webmap's operational layers
          view.map.layers.forEach(function(layer, index) {
            view
              .whenLayerView(layer)
              .then(function(layerView) {
                if (layer.type === "feature") {
                  featureLayerView = layerView;
                }
                if (layer.type === "scene") {
                  sceneLayerView = layerView;
                }
              })
              .catch(console.error);
          });
        });

        // use SketchViewModel to draw polygons that are used as a filter
        let sketchGeometry = null;
        const sketchViewModel = new SketchViewModel({
          layer: sketchLayer,
          view: view,
          pointSymbol: {
            type: "simple-marker",
            style: "circle",
            size: 10,
            color: [255, 255, 255, 0.8],
            outline: {
              color: [211, 132, 80, 0.7],
              size: 10
            }
          },
          polylineSymbol: {
            type: "simple-line",
            color: [211, 132, 80, 0.7],
            width: 6
          },
          polygonSymbol: {
            type: "polygon-3d",
            symbolLayers: [
              {
                type: "fill",
                material: {
                  color: [255, 255, 255, 0.8]
                },
                outline: {
                  color: [211, 132, 80, 0.7],
                  size: "10px"
                }
              }
            ]
          }
        });

        sketchViewModel.on(["create"], function(event) {
          // update the filter every time the user finishes drawing the filtergeometry
          if (event.state == "complete") {
            sketchGeometry = event.graphic.geometry;
            updateFilter();
          }
        });

        sketchViewModel.on(["update"], function(event) {
          const eventInfo = event.toolEventInfo;
          // update the filter every time the user moves the filtergeometry
          if (eventInfo && eventInfo.type.includes("move")) {
            if (eventInfo.type === "move-stop") {
              sketchGeometry = event.graphics[0].geometry;
              updateFilter();
            }
          }
          // update the filter every time the user changes the vertices of the filtergeometry
          if (eventInfo && eventInfo.type.includes("reshape")) {
            if (eventInfo.type === "reshape-stop") {
              sketchGeometry = event.graphics[0].geometry;
              updateFilter();
            }
          }
        });

        // select the layer to filter on
        let featureLayerViewFilterSelected = true;
        document
          .getElementById("featureLayerViewFilter")
          .addEventListener("change", function(ev) {
            featureLayerViewFilterSelected = !!ev.target.checked;
            updateFilter();
          });
        let sceneLayerViewFilterSelected = true;
        document
          .getElementById("sceneLayerViewFilter")
          .addEventListener("change", function(ev) {
            sceneLayerViewFilterSelected = !!ev.target.checked;
            updateFilter();
          });

        // draw geometry buttons - use the selected geometry to sktech
        document.getElementById(
          "point-geometry-button"
        ).onclick = geometryButtonsClickHandler;
        document.getElementById(
          "line-geometry-button"
        ).onclick = geometryButtonsClickHandler;
        document.getElementById(
          "polygon-geometry-button"
        ).onclick = geometryButtonsClickHandler;
        function geometryButtonsClickHandler(event) {
          const geometryType = event.target.value;
          clearFilter();
          sketchViewModel.create(geometryType);
        }

        // get the selected spatialRelationship
        let selectedFilter = "disjoint";
        document
          .getElementById("relationship-select")
          .addEventListener("change", function(event) {
            var select = event.target;
            selectedFilter = select.options[select.selectedIndex].value;
            updateFilter();
          });

        // get user entered values for buffer
        let buffer = 0;
        bufferNum.onchange = bufferVariablesChanged;
        function bufferVariablesChanged() {
          buffer = parseInt(bufferNum.value);
          document.getElementById("bufferValueNum").innerHTML = buffer;
          updateFilter();
        }

        // remove the filter
        document
          .getElementById("clearFilter")
          .addEventListener("click", function() {
            clearFilter();
          });

        function clearFilter() {
          sketchGeometry = null;
          filterGeometry = null;
          sketchLayer.removeAll();
          bufferLayer.removeAll();
          sceneLayerView.filter = null;
          featureLayerView.filter = null;
        }

        // set the geometry filter on the visible FeatureLayerView
        function updateFilter() {
          updateFilterGeometry();
          featureFilter = {
            // autocasts to FeatureFilter
            geometry: filterGeometry,
            spatialRelationship: selectedFilter
          };

          if (featureLayerView) {
            if (featureLayerViewFilterSelected) {
              featureLayerView.filter = featureFilter;
            } else {
              featureLayerView.filter = null;
            }
          }
          if (sceneLayerView) {
            if (sceneLayerViewFilterSelected) {
              sceneLayerView.filter = featureFilter;
            } else {
              sceneLayerView.filter = null;
            }
          }
        }

        // update the filter geometry depending on buffer
        let filterGeometry = null;
        function updateFilterGeometry() {
          // add a polygon graphic for the buffer
          if (sketchGeometry) {
            if (buffer > 0) {
              var newBufferGeometry = geometryEngine.geodesicBuffer(
                sketchGeometry,
                buffer,
                "meters"
              );
              filterGeometry = newBufferGeometry;
              if (bufferLayer.graphics.length === 0) {
                bufferLayer.add(
                  new Graphic({
                    geometry: filterGeometry,
                    symbol: {
                      type: "polygon-3d",
                      symbolLayers: [
                        {
                          type: "fill",
                          material: {
                            color: [255, 255, 255, 0.8]
                          },
                          outline: {
                            color: [255, 153, 0, 0.7],
                            size: "10px"
                          }
                        }
                      ]
                    }
                  })
                );
              }
              bufferLayer.graphics.getItemAt(0).geometry = filterGeometry;
            } else {
              bufferLayer.removeAll();
              filterGeometry = sketchGeometry;
            }
          }
        }

        document.getElementById("infoDiv").style.display = "block";
      });
    </script>
  </head>

  <body>
    <div id="viewDiv"></div>
    <div id="infoDiv" class="esri-widget">
      <b>Filtrer par une géométrie</b><br /><br />
      Sélectionner la couche à filtrer:<br />
      <input id="sceneLayerViewFilter" type="checkbox" checked />
      Bâtiments<br />
      <input id="featureLayerViewFilter" type="checkbox" checked /> Arbres<br />
      <br />Dessiner la géométrie pour le filtrage:
      <div class="geometry-options">
        <button
          class="esri-widget--button esri-icon-map-pin geometry-button"
          id="point-geometry-button"
          value="point"
          title="Filtre par un point"
        ></button>
        <button
          class="esri-widget--button esri-icon-polyline geometry-button"
          id="line-geometry-button"
          value="polyline"
          title="Filtre par une ligne"
        ></button>
        <button
          class="esri-widget--button esri-icon-polygon geometry-button"
          id="polygon-geometry-button"
          value="polygon"
          title="Filtre par polygone"
        ></button>
      </div>
      <br />
      <label for="relationship-select">Relation spatial:</label>
      <select id="relationship-select" class="options">
        <option value="intersects">Intersecte</option>
        <option value="contains">Contient</option>
        <option value="disjoint" selected>Externe à</option> </select
      ><br /><br />
      <div class="tooltip">
        <label for="bufferNum">Zone tampon en mètres:</label>
        <span id="bufferValueNum">0</span> <br />
        0<input
          id="bufferNum"
          type="range"
          min="0"
          max="1000"
          value="0"
          tabindex="1"
        />1000
      </div>
      <br /><br />
      <button class="esri-button" id="clearFilter" type="button">
        Effacer le filtre
      </button>
    </div>
  </body>
</html>

              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console