Both client-side and server-side queries can contain a SQL expression and/or a spatial relationship operator. You can perform client-side queries against features that are displayed in the view. From the geometry of the property, I am querying feature layers that are listed in an object and have using this topic to get some inpiration. The graphics layer will be used to draw the features returned from the query. A function calls queryObjectIds () whenever the user clicks on the map, which returns the objectId of the corresponding hexagon in the layer. QueryTask, Query, and FeatureSet are used together to query a layer in a map and display the results.. Clear the graphics layer each time with removeAll. //queryFeatureLayer(view.center, 1500, "intersects"); //queryFeatureLayer(event.mapPoint, 1500, "intersects"); //queryFeatureLayer(view.center, 1500, "intersects"), //queryFeatureLayer(event.mapPoint, 1500, "intersects"), // Only return features for the feature layer, Display point, line, and polygon graphics. In CodePen, click Fork and save the pen as ArcGIS JavaScript Tutorials: Query a feature layer. var query = new esri.tasks.Query(); query.geometry = area.geometry; var counter = 0; var listOfSelectedFeatures; for (var j = 0; j < map.graphicsLayerIds.length; j++) { var currentLayer = map.getLayer(map.graphicsLayerIds); currentLayer.selectFeatures(query, currentLayer.SELECTION_NEW, function { counter++; if (counter == (map.graphicsLayerIds.length - 1)) { for (var k = 0; k < … Build an app to buffer, intersect, and preform distance calculations with the geometry engine. NOTE: This will force POST requests in browsers since auth header is not yet supported by … layer.queryObjectIds ( { geometry: point, spatialRelationship: "intersects" , returnGeometry: false , outFields: [ "*" ] }) We highlight the hexagon, then use the queryRelatedFeatures () method to query for the related features attached to this object id. The main difference between client-side and server-side queries is that client-side querying is only possible after the feature layer is added to a map and the attributes are present. Client-side Query: To access a subset of data on the client, you have to add the feature layer to a map first, and then use the queryFeatures method on a FeatureLayerView object. Copyright © 2021 Esri. Function. To learn how to build this app, visit the Create a starter app tutorial. import { queryFeatures } from '@esri/arcgis-rest-feature-layer' ; // queryFeatures ( { url: "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3" , where: "STATE_NAME = 'Alaska'" }) .then (result) Query a feature service. If anyone has any pointers on what I could be doing wrong here, it'd be a huge help! Run the code and click on the map to query and draw features that are 1500 meters from the point. When the features are returned, pass the results to the addGraphics function. Update the view.when and view.on handlers to call the queryFeatureLayerView function and pass in the same parameters. Another form of querying is to use the hitTest method on the view to find features at a given screen location. Notice that only the features that match the query are displayed. Web feature layers (also known as feature services) are layers that are shared to support displaying, querying, and editing data on the web. The Overflow Blog Open source has a funding problem At the end of the code in the main function, create a FeatureLayer and set the url to access and query the trailheads feature layer, and then create a GraphicsLayer and add it to the map. This will search for and display features in the center of the map. Afterwards we zoom the map to the extent of the graphics. Your app should look something like this. For example, you can use whereto query all counties in the state of Washington from a layer representing U.S. When the features are returned, pass the results to the addGraphics function. As a service editor, ArcGIS Pro supports a wide range of geodatabase datasets and capabilities from supported databases. Update the view.when and view.on handlers to call the queryFeatureLayerView function and pass in the same parameters. The queryFeatures () method allows the user to query the features in a FeatureLayer based on an input query object. My scenario is that is a user scans a QR code on a mobile device, this then launches a webpage with JS map in it, and it then zooms in on the feature relating to the QR code they have scanned. When the view is ready, call the queryFeatureLayer function and pass in the center of the view, 1500 as the distance in meters, and intersects as the spatial relationship operator to use. My feature layer is about 150 points with attributes. … Instead, the token will be passed in POST request body or through X-Esri-Authorization header. I added a function to get some feedback after the selection is complete. Properties:Example:// Once the layer loads, check if the// supportsAdd operations is enabled on the layerfeatureLayer.when(function(){ if (featureLayer.capabilities.operations.supportsAdd) { // if new features can be created in the layer // set … ... ArcGIS Javascript API Feature Layer retrieval. Control editor tracking and feature layer capabilities and settings. The result of this operation is either a feature set or an array of feature IDs (if returnIdsOnly is set to true) and/or a result extent (if returnExtentOnly is set to true). All rights reserved. var layer = MyMapView.Map.Layers["MyLayer"] as FeatureLayer; var table = layer.FeatureTable; ((ServiceFeatureTable)table).Where = null; var task = new QueryTask(new Uri(((ServiceFeatureTable)table).ServiceUri)); var result = await task.ExecuteObjectIDsQueryAsync(new Query("closeddate > date '2012-12-01'")); if (result != null) When the features are returned, pass the results to the addGraphics function. // query all features from the oil and gas wells layer view.when(function { return wellsLayer.when(function { var query = wellsLayer.createQuery(); return wellsLayer.queryFeatures(query); }); }); The source data for a feature layer can be hosted onArcGIS OnlineorArcGIS Enterpriseor it can be created from an array on the client. Working with Feature Layers in the ArcGIS API for JavaScript ... Query the layer Attribute queries select only features passing a WHERE SQL clause Spatial queries select only features passing a spatial filter Statistic queries returns statistics about the selected features You can query features from clusters to get access to the underlying features represented by a cluster. Use the queryFeatures method to execute the query. Query expressions in ArcGIS adhere to standard SQL expressions. Both client-side and server-side queries can contain a SQL expression and/or a spatial relationship operator. After the view and FeatureLayerView are ready, use hitTest to find features and show a pop-up when the cursor is over a feature. With hosted feature layers, you can do the following: Both the SQL filter selected and the spatial query will be applied so you should only see trailheads that have "Canyon" in their name. Define an addGraphics function that will be used later to accept the return values from a query and add the results to the graphics layer. Learn more about the parameters you can use in the documentation. Define another function that accepts a point, distance to search, spatial relationship operator, and an optional SQL expression and builds a query that will return all of the fields and the geometry from the feature layer. The input into the process is Query. Learn more about the parameters you can use in the documentation. The following sections include common tasks for working with feature layers from the web in ArcGIS Pro. The ArcGIS API for JavaScript uses AMD modules. Click on the map below to execute a query to find features. If the user selects 'Query By Distance', two parameters, distance and units, are added to the query object that is the input for layer.queryFeatures(), returning any item in the feature that is within 0.5 miles from where the user clicked on the map. Define a sql variable and update the calls to queryFeatureLayer and queryFeatureLayerView to accept a SQL where clause and run the code again. When I set a breakpoint before the last line(rl.addMany(features)), I see that features contains the expected feature, and the symbol is set properly. 5. What is the best approach to do this via ArcGIS Javascript API? The source data for a feature layer can be hosted on ArcGIS Online or ArcGIS Enterprise or it can be created from an array on the client. The require function is used to load modules so they can be used in the main function. Also, I know that the feature exists, but is not appearing on the map. var query = new esri.tasks.Query(); query.geometry = area.geometry; var counter = 0; var listOfSelectedFeatures; for (var j = 0; j < map.graphicsLayerIds.length; j++) { var currentLayer = map.getLayer(map.graphicsLayerIds); currentLayer.selectFeatures(query, currentLayer.SELECTION_NEW, function { counter++; if (counter == (map.graphicsLayerIds.length - 1)) { for (var k = 0; k < map.graphicsLayerIds.length; k++) { var layer … It returns a query object that already respect the layer's definitionExpression if one is present. In this tutorial, you will execute server-side and client-side queries to find trailheads that are within a distance of 1500 meters from the center of the map and where you click. Display the visible extent of a cluster’s features. 1. Afterwards we zoom the map to the extent of the graphics. I'm working with the API for JavaScript to create a map of tornadoes in the US. 5. // query all features from the oil and gas wells layerview.then(function() { returnwellsLayer.then(function() { varquery = … To learn how to build this app, visit the Create a starter app tutorial. Also, add logic to only show a pop-up when a new feature is found. To do so, the feature layer must be added to the map and the FeatureLayerView must be ready, in other words, the features and attributes have been loaded and can be queried. Learn more about the query parameters you can use in the documentation. Beyond spatial queries, you can also perform an attribute or a combination of attribute and spatial search queries with the queryFeatures function. A user provides input to the query. In this tutorial, you will execute server-side and client-side queries to find trailheads that are within a distance of 1500 meters from the center of the map and where you click. Currently I have used a Query Task by specifying the layer, the "where" statement, graphic symbol, InfoTemplate etc.