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.
Skip To ContentArcGIS for DevelopersSign In Dashboard
Loading...

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

This sample displays information based on the PopupTemplate using the Feature widget. You can use this widget to display information normally found in the Popup without having to use the Popup itself. You can also use this information in a custom widget or other parts of your application.

// Provide graphic to a new instance of a Feature widget
const feature = new Feature({
  graphic: graphic,
  map: view.map,
  spatialReference: view.spatialReference
});

view.ui.add(feature, "bottom-left");

view.whenLayerView(fLayer).then(function (layerView) {
  let highlight;
  let objectId;

  const debouncedUpdate = promiseUtils.debounce(function (event) {
  // Perform a hitTest on the View
    view.hitTest(event)
      .then(function (event) {
        // Make sure graphic has a popupTemplate
          let results = event.results.filter(function (result) {
            return result.graphic.layer.popupTemplate;
          });

          let result = results[0];
          let newObjectId = result && result.graphic.attributes[fLayer.objectIdField];

          if (!newObjectId) {
            highlight && highlight.remove();
            objectId = feature.graphic = null;
          } else if (objectId !== newObjectId) {
            highlight && highlight.remove();
            objectId = newObjectId;
            feature.graphic = result.graphic;
            highlight = layerView.highlight(result.graphic);
          }
        })
    });

    // Listen for the pointer-move event on the View
    // and make sure that function is not invoked more
    // than one at a time
    view.on("pointer-move", function (event) {
      debouncedUpdate(event).catch(function (err) {
        if (!promiseUtils.isAbortError(err)) {
          throw err;
        }
      });
    });
});

Sample search results

TitleSample
Loading...