What is the layerDefinitions equivalent for identifyParameters in ArcGIS API for JavaScript version 4?

712
4
Jump to solution
09-07-2022 01:06 PM
LoriMcCormack1
New Contributor III

Even though I have a defiintion query on my layers, the identify includes features I don't want.  In version 3.x, I was able to use layerDefinitions in the identifyParameters.  

What is the equivalent in version 4.x?

0 Kudos
1 Solution

Accepted Solutions
ReneRubalcava
Frequent Contributor

Ah, sorry. That won't work in 4.13. That was introduced at 4.23 I think. Before that, we didn't have that option in the IdentifyParameters like in 3x. In recent 4x version, the sublayers need to come from a MapImageLayer as they need a layer source.

https://codepen.io/odoe/pen/qBYbOyG?editors=1000

View solution in original post

4 Replies
ReneRubalcava
Frequent Contributor

You can define the defintionExpression in a sublayer in the IdentifyParameters

https://developers.arcgis.com/javascript/latest/api-reference/esri-rest-support-IdentifyParameters.h...

You can create a MapImageLayer with your sublayers, load it, then add those sublayers to the parameters.

https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-support-Sublayer.html#sour...

 

0 Kudos
LoriMcCormack1
New Contributor III

Hi ReneRubalcava,

That was very helpful.

This is what my parameters look like.  However, it still identifies features that are hidden because of the definition expression on the MapImageLayer.  At quick glance, can you tell why the definition expression doesn't appear to be working for identify?  I'm using version 4.13.

// Create identify task for the specified map service
identifyTask = new IdentifyTask(urlTravelImpacts);

// Set the geometry to the location of the view click
identifyParams = new IdentifyParameters();
identifyParams.tolerance = 5;
identifyParams.layerIds = [indexBridgeRestriction, indexRoadImpact, indexRestrictionCurrent, indexRestrictionFuture, indexReferencePoints, indexIntersectionNode, indexMilepostsEstablished, indexMaintDistrict];
identifyParams.layerOption = "visible";
identifyParams.width = view.width;
identifyParams.height = view.height;
identifyParams.returnGeometry = true;
identifyParams.sublayers = [
{
id: indexBridgeRestriction
},
{
id: indexRoadImpact,
definitionExpression: "TravelImpactStartDate <= '2022/09/07' AND TravelImpactEndDate >= '2022/09/07'"
},
{
id: indexRestrictionCurrent,
definitionExpression: "TravelImpactStartDate <= '2022/09/07' AND TravelImpactEndDate >= '2022/09/07'"
},
{
id: indexRestrictionFuture,
definitionExpression: "TravelImpactStartDate <= '2022/09/07' AND TravelImpactEndDate >= '2022/09/07'"
},
{
id: indexReferencePoints
},
{
id: indexIntersectionNode
},
{
id: indexMilepostsEstablished
},
{
id: indexMaintDistrict
}
];

0 Kudos
ReneRubalcava
Frequent Contributor

Ah, sorry. That won't work in 4.13. That was introduced at 4.23 I think. Before that, we didn't have that option in the IdentifyParameters like in 3x. In recent 4x version, the sublayers need to come from a MapImageLayer as they need a layer source.

https://codepen.io/odoe/pen/qBYbOyG?editors=1000

LoriMcCormack1
New Contributor III

I will upgrade my code to 4.24 so my map works correctly.  It's odd because 4.13 was working, and now even the identify pararameter layer option = 'visible' doesn't work anymore.  Even layers turned off are being identified.

Thanks again for your help!  You helped me with another issue and I am so grateful to have such a wonderful Esri user community.

0 Kudos