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.

This sample demonstrates how to query attachments from a FeatureLayer through Beverly Hills tree data by using the queryObjectIDs() and queryAttachments() methods. When user clicks somewhere in the map, the attachments located within 800m of the click location will appear in the div on the left hand side.

How it works

A function is called whenever the user clicks on the map, which first calls a query for all object ids within 800m of the point where the map was clicked.

layer.queryObjectIds({
    geometry: point,
    spatialRelationship: "intersects",
    distance: 800,
    units: "meters",
    returnGeometry: false,
    outFields: ["*"]
})

This will return an array of object ids which we highlight to show the user the bounds of their query then pass to the queryAttachments() method to query for attachments on any of the objects returned from our first query.

layer.queryAttachments({
    attachmentTypes: ["image/jpeg"],
    objectIds: objectIds
});

This method will return an array of ids for the attachments returned from the query, which we display by creating an image element and appending it to the queryResults div in the side panel.

Object.keys(attachmentsByFeatureId).forEach(function(objectId) {
    const attachments = attachmentsByFeatureId[objectId];
    attachments.forEach(function (attachment) {
        const image = document.createElement("img");
        image.src = attachment.url;
        image.className = "queryImg";
        document.getElementById("queryResults").appendChild(image);
    });
});

Sample search results

TitleSample
Loading...