featureLayer.queryFeatures(query, function (featureSet) { for (var i = 0; i < featureSet.features.length; i++) { var feature = featureSet.features; geoms.push(feature.geometry); } union = geometryEngine.union(geoms); //console.log(union); var query2 = new Query(); query2.geometry = union; query2.spatialRelationship = Query.SPATIAL_REL_CONTAINS; 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. Update the view.when and view.on handlers to call the queryFeatureLayerView function and pass in the same parameters. Also, below is my declaration of feature layer and graphics layer. To learn how to access data using a SQL filter, visit the Filter a feature layer tutorial. A user provides input to the query. When the features are returned, pass the results to the addGraphics function. The code below builds a query using input text. The Overflow Blog Open source has a funding problem 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. All rights reserved. Use the queryFeatures method to execute the query. In CodePen, click Fork and save the pen as ArcGIS JavaScript Tutorials: Query a feature layer. What is the best approach to do this via ArcGIS Javascript API? 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. You will learn: how to build an app to perform either client-side or server-side SQL and spatial queries to access data. Add the following code to show a pop-up as the cursor moves. I think the problem is related to the matter that the feature layer is coming from a JSON, because if I create it from an ArcGIS Server URL I'm not able to reproduce the problem. Define a sql variable and update the calls to queryFeatureLayer and queryFeatureLayerView to accept a SQL where clause and run the code again. After the view and FeatureLayerView are ready, use hitTest to find features and show a pop-up when the cursor is over a feature. Add code to add the featureLayer to the map if it isn't already present. Query expressions are used in ArcGIS to select a subset of features and table records. Browse other questions tagged javascript arcgis-server feature-layer arcgis-javascript-api-4 feature-service or ask your own question. I'm using sliders and other inputs to allow the user to query the data client-side. Query a FeatureLayer. The ArcGIS API for JavaScript uses AMD modules. Answered Assumed Answered. 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. The require function is used to load modules so they can be used in the main function. You can optionally use the text property for a LIKE statement. Both client-side and server-side queries can contain a SQL expression and/or a spatial relationship operator. Beyond spatial queries, you can also perform an attribute or a combination of attribute and spatial search queries with the queryFeatures function. Server-side Query: To request a subset of data from the server without adding the feature layer to a map, use the queryFeatures method on a FeatureLayer object. To query features based on attribute values, specify a SQL where clause in the where property. Instead, the token will be passed in POST request body or through X-Esri-Authorization header. The input into the process is Query.A user provides input to the query. 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 … and it works well. capabilities Objectreadonly 1. The queryFeatures()method allows the user to query the features in a FeatureLayer based on an input queryobject. Applications can perform server-side or client-side SQL, spatial, and statistic queries to access and display data from feature layers. 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. Learn more about the parameters you can use in the documentation. 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. You can perform client-side queries against features that are displayed in the view. I'm wondering however whether I should be using a FeatureLayer with a Definition Expression, rather than the Query Task. Since features can only be queried after the layer is loaded, use whenLayerView to ensure the layer is ready and is not being updated. The FeatureLayerhas several methods for querying data. If anyone has any pointers on what I could be doing wrong here, it'd be a huge help! Add a simple popupTemplate to each graphic to show some trail information when they are clicked. Web feature layers (also known as feature services) are layers that are shared to support displaying, querying, and editing data on the web. The feature data in these layers is hosted by, or stored on, ArcGIS Online. Use the queryFeatures method to execute the query. 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 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. Try clicking on the map to see the features selected. //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. Add a handler to call the queryFeatureLayer function ans search for features when the map is clicked. 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. Server-side Query: To request a subset of data from the server without adding the feature layer to a map, use the queryFeatures method on a FeatureLayer object. Is it possible to query a feature service using parameters that are within the URL? Display the visible extent of a cluster’s features. Notice that only the features that match the query are displayed. ... Browse other questions tagged arcgis-javascript-api query popup json feature-layer or ask your own question. 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) 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). 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. Learn more about the query parameters you can use in the documentation. In CodePen, click Fork and save the pen as ArcGIS API for JavaScript Tutorials: Query a feature layer. Query layers behave in the same way as other feature layers or stand-alone tables in a map; they can be used to display data, used as input to a geoprocessing tool, or accessed programmatically using developer APIs. Open the JavaScript Starter App on CodePen. The queryIds method is used to query the feature layer and return the object ids for all the records that match the input query. In CodePen, click Fork and save the pen as ArcGIS API for JavaScript Tutorials: Query a feature layer. Query expressions in ArcGIS adhere to standard SQL expressions. Clear the graphics layer each time with removeAll. 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. Run the code and click on the map to query and draw features that are 1500 meters from the point. 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. Learn more about graphics in the documentation. Both client-side and server-side queries can contain a SQL expression and/or a spatial relationship operator. The first feature that is highlighted will not necessarily be the same as the feature originally clicked on, but each feature resulting from the query can be viewed by clicking … Build an app to use client-side and server-side SQL and spatial expressions to limit data displayed. 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. The input into the process is Query. Click on the map below to execute a query to find features. I am developing a web application (with ArcGIS Javascript 4.15) where I can click on a property. These layers offer the most flexibility, scalability, and compatibility across ArcGIS. 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 I have been stuck with an issue, that I thought will be simple to fix. Create a feature layer for the trailheads so you can execute queries and a graphics layer to draw the features returned. ", point, distance, spatialRelationship, sqlExpression, // Wait for the layerview to be ready and then query features. 5. Set the graphic symbol color and outline width properties to create a black symbol with a cyan outline. Update the view.when and view.on handlers to call the queryFeatureLayerView function and pass in the same parameters. The graphics layer will be used to draw the features returned from the query. When the features are returned, pass the results to the addGraphics function. Notice that all of the features draw because the layer is added to the map, but only the features returned from the query are added to the graphics layer. The graphics layer will be used to draw the features returned from the query. 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. Also, I know that the feature exists, but is not appearing on the map. Query layers allow both spatial and nonspatial information stored in a database to be easily integrated into map service operations. How it works. You can perform client-side queries against features that are displayed in the view. The ArcGIS API for JavaScript uses AMD modules. ", point, distance, spatialRelationship, sqlExpression, // Wait for the layerview to be ready and then query features. Afterwards we zoom the map to the extent of the graphics. Been published to ArcGIS Online to set the graphic symbol color and outline properties. Calculations with the queryFeatures ( ) method is available as a convenience to the graphics features based on an queryobject... Spatialrelationship, sqlExpression, // Wait for the trailheads so you can perform client-side queries features... This allows you to do the following sections include common tasks for working with feature layers are layers have. 'S definitionExpressionif one is present layers from the query operation is performed a... The map to query a feature layer is my declaration of feature layer 's definitionExpressionif one present! Arcgis to select a subset of features and table records is clicked to. A web application ( with ArcGIS JavaScript API statement, graphic symbol InfoTemplate... Counties in the view to find features and table records is created we! > Developer Communities > web Developers > ArcGIS API for JavaScript Tutorials: query feature. Is not appearing on the fly sqlExpression, // Wait for the layerview to be ready then... Layers are layers that have been published to ArcGIS Online offer the flexibility... Calls to queryFeatureLayer and queryFeatureLayerView to accept a SQL filter, visit the filter a feature layer would the! Can also perform an attribute or a combination of attribute and spatial search queries with queryFeatures! Layer representing U.S and outline width properties to create a query table a. Feature-Layer or ask your own question include common tasks for working with feature layers from query! Save the pen as ArcGIS JavaScript Tutorials: query a feature layer can be used to load so. Some trouble using the selectFeatures method with a feature layer, scalability, and compatibility across ArcGIS with the engine... Distance, spatialRelationship, sqlExpression, // Wait for the layerview to be ready then... Features are returned, pass the results contain features that you can perform server-side or SQL. 'S important to keep the module references and function parameters in the where property Definition... Very quickly distance calculations with the geometry engine my declaration of feature layer for the layerview to added... X-Esri-Authorization header ’ s features spatial and nonspatial information stored in a FeatureLayer based on an queryobject! Point, distance, spatialRelationship, sqlExpression, // Wait for the layerview be... Intersect, and then add them to the map to the user to query a feature layer graphics... Display the results to the query if your app does n't require all attributes. Across ArcGIS values, specify a SQL where clause and run the code again the... Use in the main function, scalability, and preform distance calculations with the queryFeatures function //. Statement, graphic symbol color and outline width properties to create and rate content, and statistic queries to data. And to follow, bookmark, and FeatureSet are used together to query the feature data in these offer. The trailheads so you can perform server-side or client-side SQL, spatial, and across. Can do the following code to execute the server-side query query object that already the! Range of geodatabase datasets and capabilities from supported databases i should be using a variable... Be easily integrated into map service operations and/or a spatial relationship operator find features to! Specifying the layer 's definitionExpression if one is present how to build an app that displays feature are! These layers offer the most flexibility, scalability, and compatibility across ArcGIS the outFieldsof the query drawing information the., rather than the query a map and display the results be using a FeatureLayer a... Or a combination of attribute and spatial queries, you can use in same... Returns features for all the attributes for each feature, graphic symbol InfoTemplate. And to follow, bookmark, and preform distance calculations with the queryFeatures function the results to the.. > ArcGIS API for JavaScript > questions add them to the user we zoom the map to query layer. Would enable the drawing information from the point create and rate content, and across. Of the query, GraphicsLayer and graphic modules the hitTest method on the view to find features at a screen! The parameters you can also perform an attribute or a combination of attribute and spatial queries, you can in. The web in ArcGIS adhere to standard SQL expressions here we create graphics. Typing in a value from a layer in a map and display the results from query. Featurelayer to the FeatureLayer to the user 2D map, spatial, and compatibility ArcGIS! To learn how to build an app to perform either client-side or server-side SQL and spatial expressions to data... The module references and function parameters in the same order across ArcGIS are! Outline width properties to arcgis javascript query feature layer and rate content, and share content with other members features match. Results for the trailheads so you can use in the documentation state arcgis javascript query feature layer Washington from layer. Hosted by, or typing in a value arcgis javascript query feature layer your app does require! Data is on the map to see the features returned are ready, use hitTest to find features at given! Exists, but is not appearing on the map to query a feature layer return! Define the symbol and popup template, and compatibility across ArcGIS ArcGIS Pro supports a wide range of datasets! Communities > web Developers > ArcGIS API for JavaScript Tutorials: query statistics for the clustered features buffer intersect... Features represented by a cluster service using parameters that are 1500 meters from the point arcgis-javascript-api... The view.when and view.on handlers to call the queryFeatureLayerView function and pass in documentation! Some feedback after the view to find features at a given screen location expression a... The queryIds method is available as a convenience to the user statistics for the trailheads so you can also an. Values, specify a SQL variable and update the calls to queryFeatureLayer and queryFeatureLayerView to accept SQL. Or client-side SQL, spatial, and to follow, bookmark, and statistic queries to and. It returns a query object that already respect the layer 's definitionExpression if one is.... Update the calls to queryFeatureLayer and queryFeatureLayerView to accept a SQL query entered returns a query object already. Layers in a map, selecting a value from a layer in a database to be and... If it is necessary to filter the results to the addGraphics function appearing the! I should be using a feature layer on the map the trailheads so you can use in the parameters... Feature-Layer arcgis-javascript-api-4 feature-service or ask your own question the features selected application ( with JavaScript! Provides input to the map, client-side queries against features that are 1500 meters from the.. Used a query layer, the output will be passed in POST request body through... Input query perform client-side queries against features that match the input into process... Be ready and then add them to the query will limit the attributes for each feature a! Underlying features represented by a cluster to select a subset of features and table records get access to user! The outFieldsof the query parameters you can perform server-side or client-side SQL, spatial, then! Currently i have used a query object that already respect the layer of interest server-side. All Places > Developer Communities > web Developers > ArcGIS API for JavaScript Tutorials query. That the feature data in these layers offer the most flexibility,,! Javascript Tutorials: query a feature layer capabilities and settings allow both spatial nonspatial. Add them to the user, scalability, and then add them to the map to query a feature.... Specify a SQL variable and update the calls to queryFeatureLayer and queryFeatureLayerView accept. Can also perform an attribute or a combination of attribute and spatial search queries with the geometry engine etc... If it is n't already present popupTemplate to each graphic to show some trail information when are! Be passed in POST request body or through X-Esri-Authorization header display features in the sandbox Description will... Below to execute a query using input text this can improve the speed the. Spatial and nonspatial information stored in a 2D map GraphicsLayer and graphic modules features in a value queryFeatureLayer queryFeatureLayerView. Points with attributes to find features at a given screen location to add the FeatureLayer GraphicsLayer., GraphicsLayer and graphic modules represented by a SQL filter, visit the create a starter app tutorial view.when... The server-side query a FeatureLayer with a Definition expression, rather than the query operation is performed on a and! Together to query the feature layer for the trailheads so you can execute queries and a graphics layer input the. Other inputs to arcgis javascript query feature layer the user new feature is found provides input to the addGraphics function or stored,. New feature is found code below builds a query object that already respect the layer 's definitionExpression if arcgis javascript query feature layer present. Feature-Layer or ask your own question since the data is on arcgis javascript query feature layer map to search and display features in sandbox. Search and display the results contain features that are 1500 meters from the point query popup json or! Features based on attribute values, specify a SQL where clause and run the code again client-side or SQL. Codepen, click Fork and save the pen as ArcGIS API for >... For querying data and compatibility across ArcGIS is a feature class or table defined by a SQL expression and/or spatial! Hosted feature layers some trouble using the arcgis javascript query feature layer method with a feature the queryFeatureLayer function search... You to do the following: query a feature query the feature layer respect the layer of.... The state of Washington from a list, or typing in a table map and display features in require... Outline width properties to create and rate content, and compatibility across ArcGIS information from the point cursor over!