Probably multiple ways to handle this, but I need to set a definition expression on a polygon FeatureLayer using the intersection of another polygon FeatureLayer. I had been simply using a WHERE clause on an attribute, but the requirement has changed to use the geometry from a different FeatureLayer.
Any help is appreciated.
What I have so far:
createFuncLocLayer: function () {
this.funcLocLayer = new FeatureLayer(this.config.functionalLocationLayer);
this.workplanBoundaryLayer.queryFeatures(this.queryWorkplanLayer(), lang.hitch(this, function (result) {
var wpGeometry = geometryEngine.geodesicBuffer(result.features[0].geometry, -20, "meters")
//How can I apply this.funcLocLayer.setDefinitionExpression to use the wpGeometry variable?
}));
Solved! Go to Solution.
James,
I forgot the comma after the "load".
this.workplanBoundaryLayer.on("load", lang.hitch(this, function(){
I don't know how I missed that.
Thank you
Robert -- I'm marking as correct cause I don't doubt this is what I need to implement. Still working thru a problem of "result" = undefined and causing an issue setting the wpGeometry var. I'll see if what I'm doing wrong there.
def.then(lang.hitch(this, function(result){
debugger
if (result) {
var geom = result;
var wpGeometry = geometryEngine.geodesicBuffer(geom, -20, "meters");
var query = new Query();
query.outFields = ["*"];
query.returnGeometry = true;
query.outSpatialReference = this.map.spatialReference;
query.geometry = wpGeometry;
debugger
this.funcLocLayer.queryIds(query, lang.hitch(this, function (objectIds) {
var qStr = this.funcLocLayer.objectIdField + " IN(" + objectIds.join(',') + ")";
this.funcLocLayer.setDefinitionExpression(qStr);
}));
}
Robert,
Thanks again!
I was struggling with making your solution/suggestion error-free and found the issue (pretty typical struggle for me, not sure how else to pick these out faster, I think I'm getting a bit better tho). It finally makes it to qStr and I believe sets the definitionExpression as desired:
var geom = result;
Should be
var geom = result.geometry;
James,
Sorry about that. The returned value from the deferred was a graphic and you where needing a geometry.
Hi James,
I haven't tried this out but I think you have to use FeatureLayerView or execute a query on the FeatureLayer and create a layer for visualization from the results?
FeatureLayerView | API Reference | ArcGIS API for JavaScript 4.7
var query = new Query({
geometry: wpGeometry,
spatialRelationship = "intersects"
});
// YOU CAN USE LAYERVIEW WHICH YOU CAN USE TO HOOK INTO LAYERS UPDATE EVENT
view.whenLayerView(this.funcLocLayer).then(function(lyrView){
lyrView.watch("updating", function(val){
if(!val){ // wait for the layer view to finish updating
lyrView.queryFeatures(query).then(function(results){
// Do additional stuff
});
}
});
});
// OR USE THE QUERY DIRECLY ON THE LAYER
this.funcLocLayer.queryFeatures(query).then(function(results){
// Create the final layer and add to map or update an existing layer
});
Let me know if this helps.