TransWikia.com

How to apply a layer definition with a spatial query to a Dynamic layer?

Geographic Information Systems Asked on December 9, 2020

Using the ArcGIS Server JavaScript API, it’s possible to specify an attribute query in the form of a layerDefinition against a Dynamic layer.

For example, the following query will restrict the layer to show only features where the population is greater than 5,000,000:

var layerDefinitions = [];
layerDefinitions[0] = "POPULATION > 5000000";
dynamicMapServiceLayer.setLayerDefinitions(layerDefinitions);

Is it possible to specify a bounding box in the layer definition?

That is, apply a spatial query in addition to any attribute query. The query should be based directly on the layer’s geometry field (not an attribute derived from the geometry). Assume the data is stored in WGS84 and is "geometryType": "esriGeometryPoint".

2 Answers

If that Geometry Point is stored, then, it must have an OBJECTID. You can just select it with a query like : OBJECTID = 1

Edit:

You could do a spatial intersect, using a polygon drawn with the coordinates you want as described here https://developers.arcgis.com/javascript/3/jsapi/polygon-amd.html#polygon3 and pass it to the query

var polygon = new Polygon([[50, 0], [150, 20], [150, -20], [50,0]]);
query.geometry = polygon;
query.spatialRelationship = Query.SPATIAL_REL_INTERSECTS;

there are other spatial operations, maybe you'd prefer SPATIAL_REL_WITHIN https://developers.arcgis.com/javascript/3/jsapi/query-amd.html#constants

Answered by LMokrane on December 9, 2020

Unfortunately, layerdefinitions do not support geometry operations. Some workarounds are:

  • Add X/Y attributes and filter on those
  • Add the service as separate FeatureLayer and code a custom renderer that excludes certain features
  • Use a QueryTask to get the ObjectID's of features within the bounding box, the set the layerdefinition to objectid in (1,2,...n)

Answered by Berend on December 9, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP