You are using a browser that is no longer supported. Please use the latest version of Google Chrome, Mozilla Firefox, Apple Safari, or Microsoft Edge. For more information please see the System Requirements.

Unsupported browser

You are using a browser that is not supported. JavaScript API works on the latest versions of Google Chrome, Mozilla Firefox, Apple Safari, or Microsoft Edge. Use one of these browsers and provide your feedback through GeoNet, the Esri Community.

  • {i18n.unsupportedBrowser.chrome}
  • Firefox
  • Safari
  • undefined
Loading...

Note: Support for 3D on mobile devices may vary, view the system requirements for more information.

The FeatureLayerView provides access to a layer's features that are displayed in the view. This sample uses the whenLayerView() method to get the FeatureLayer's layer view once it's created.

view.whenLayerView(featureLayer).then(function(layerView) {
  // do something with the layerView
});

Once the layer view is available, you need to set up a watch on the updating property of the layer view. You must wait for all the features to finish updating in the view before performing a query.

layerView.watch("updating", function(value) {
  if (!value) {
    // wait for the layer view to finish updating

    // get all the features available for drawing.
    layerView
      .queryFeatures({
        geometry: view.extent,
        returnGeometry: true
      })
      .then(function(results) {
        // do something with the resulting graphics
        graphics = results.features;
      });
  }
});

Once you gain access to the graphics available to the layer view, you can use them for a variety of purposes, such as creating drop down menus, or lists, as this sample does. Once a list is created you can listen for click events on each list node and open a popup at the location of the feature when the corresponding node is clicked.

view.popup.open({
  features: [result],
  location: result.geometry.centroid
});

While the popup is typically used with a feature layer, you can also display the popup in response to a query or some other action that does not involve a graphic or a feature. For example, you can display a popup on the view when user clicks on a table row, or a list. The resulting popup in this sample is displayed at the center of a zip code polygon and its content and title will be populated from the features parameter.

Sample search results

TitleSample
Loading...