Select to view content in your preferred language

Feature Layer QueryIds -- What id is returned?

6534
8
Jump to solution
04-20-2015 01:20 PM
DanRicketts
Deactivated User

I have a feature Layer and am running queryids.  I get the array of ids fine.  However, I can't figure out where the id is coming from.  The documentation says it is the "ObjectId."  When I look at the feature service list of fields ObjectID is one of the fields listed but it doesn't seem to be a field that is returned to the browser, I am doing "*" as my fields so I should be getting all. 

I thought maybe the objectid was the array object number but I can't find any correlation between the ID from the feature service to the array object # in the browser. 

How can I access this Object ID in the feature layer in browser? 

I want to loop through my graphics in the feature layer and show the graphics that are in my ID array.  Don't know what Id that query returned. 

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
KellyHutchins
Esri Frequent Contributor

The returned id is the value for the object id field for the feature layer. You can find out the name of the field using the Feature Layer's objectIdField property.

If you want to show the selected features it might be simpler just to use the Feature Layer's selectFeatures method. Using this method you define a query and the features that meet the input query requirements will be displayed on the map using the selection symbol defined using the setSelectionSymbol method.

View solution in original post

8 Replies
KellyHutchins
Esri Frequent Contributor

The returned id is the value for the object id field for the feature layer. You can find out the name of the field using the Feature Layer's objectIdField property.

If you want to show the selected features it might be simpler just to use the Feature Layer's selectFeatures method. Using this method you define a query and the features that meet the input query requirements will be displayed on the map using the selection symbol defined using the setSelectionSymbol method.

DanRicketts
Deactivated User

Kelly thanks for pointing out the objectIdField property.  This answered the question.  It returned ESRI_OID.  This apparently is a field desktop adds when you import the layer which complicates the matter because it is not in my original SQL dataset so I can't query the database to verify results and my query is returning incorrect results both when run in javascript and when I run directly on the service within arcgis server.  I am trying to find out where this ESRI_OID is stored but not having any luck. 

I am in fact using the ids to determine the visible points per layer.  I am doing a variety of query's to provide an array of ids that meet the requirements.  It looks like the selectFeatures method only highlights the features, since I already have a class breaks renderer defined with a symbol for the layer.  It doesn't hide the points in the layer that don't meet criteria, at least that I can see. 

0 Kudos
KellyHutchins
Esri Frequent Contributor

Dan Ricketts

A layer definition will filter the layer to only display the features that match the definition expression.  Here's a JSBin that shows how to generate a definition expression based on the results of  queryIds.

Create a Map

DanRicketts
Deactivated User

Thanks again.  Yes the definition expression should work perfectly. 

0 Kudos
DanRicketts
Deactivated User

Kelly,

Is there a good way to force a query on the entire layer instead of only what was in the definition?  I set the definition based on the selection.  However, if the user changes their selection it only queries the existing definition.  I understand that is by design.  If I clear it by setting definition to empty then it doesn't finish in time.  I can set a promise I supposed and wait but wanted to see if there was some way to force a query on the layer instead of just the current definition.

I thought of going back to hiding the non-selected graphics but it seems to leave them in the selection area.  So if a point is around a hidden graphic when you select the visible graphic the hidden is also available.  Apparently hiding the graphic doesn't prevent the popups from using it when selecting in the area. 

0 Kudos
KellyHutchins
Esri Frequent Contributor

You can wait until the current expression is cleared before applying the new one. Here's an example:

<!DOCTYPE html>
<html>
<head>
  <title>QueryMap</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
  <link rel="stylesheet" href="http://js.arcgis.com/3.13/dijit/themes/claro/claro.css">
  <link rel="stylesheet" href="http://js.arcgis.com/3.13/esri/css/esri.css">
  <style>
    html, body, #mapDiv{
      padding: 0;
      margin: 0;
      height: 100%;
    }
    #clearButton{
      z-index: 40;
      position: absolute;
      top:5px;
      right:10px;
    }
  </style>
  
  <script src="http://js.arcgis.com/3.13/"></script>
  <script>


    require(["esri/map", "esri/layers/FeatureLayer", "esri/tasks/query", "esri/InfoTemplate", "dojo/on","dojo/dom", "dojo/domReady!"], function(Map, FeatureLayer, Query, InfoTemplate, on, dom) {
      var map = new Map("mapDiv", {
        center: [-118.29, 34.07],
        zoom: 13,
        basemap: "gray"
      });
      //Clear the existing expression and once the layer is updated apply
      //the new expression
      on(dom.byId("clearButton"),"click",function(){
        on.once(flayer, "update-start", function(){
          updateQuery(flayer, "Ligustrum lucidum"); 
        });
        flayer.setDefinitionExpression(null);


      });
      var flayer = new FeatureLayer("http://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/ParkTrees/FeatureServer/0",{
        outFields: ["*"],
        infoTemplate: new InfoTemplate("${COMMON}","${BOTANICAL}")
      });
      map.addLayer(flayer);
      flayer.on("load",function(){
        updateQuery(flayer, "Fraxinus uhdei");
      });


      function updateQuery(layer, expression){
        var query = new Query();
        query.where = "BOTANICAL = '" + expression +  "'";
        layer.queryIds(query, function(objectIds) {
          var exp = layer.objectIdField + " IN(" + objectIds.join(",") + ")";
          layer.setDefinitionExpression(exp);
        });
      }


    });
  </script>


</head>
<body class="claro">
  <div id="mapDiv"></div>
  <input id="clearButton" type="button" value="Clear"/>
</body>
</html>
0 Kudos
DanRicketts
Deactivated User

Kelly,

Thanks.  Howerver, instead of update-start wouldn't you want update-end?  We would want the definitionexpression(null) to complete prior to trying to set a new defexpres correct?  Wouldn't this try to update the expression at pretty much the same time as it was being cleared? 

0 Kudos
KellyHutchins
Esri Frequent Contributor

Either way should work because update shouldn't fire until after the layer definition is cleared.

0 Kudos