Hello all,
I'm looking for some strategic advice and sample code if possible.
I'm working with a few very large feature services. We are serving these out to a web-based app. Layer1 is a polygon layer and Layer2 is a line layer, with those lines falling within the polygons in Layer1.
Right now our application passes an ID to Layer1 that we then use Layer1.setDefinitionExpression() to segment the data. Now we need to take that boundary and use it to query and display the data from Layer2 where it is within the subset of Layer1.
Any advice on how to proceed? Feature services are necessary for both because of the need for editing.
Enjoy the day,
Mike
Solved! Go to Solution.
Why isn't the union and second selection section within the queryFeatures function? Wouldn't those happen before the queryFeatures function completes?
var geoms = []; pondLayer.queryFeatures(query, function(featureset){ for (var i = 0; i < featureset.features.length; i++) { var feature = featurset.features; geoms.push(feature); }) var union = geometryEngine.uniongeoms(geoms); //Notice I am using geometryEngine and not geometryEngineAsync var query2 = new Query(); query2.geometry = union; query2.spatialRelationship = Query.SPATIAL_REL_CONTAINS; pondLayer.selectFeatures(query2, FeatureLayer.SELECTION_NEW); });
Ken,
You are correct.
Thanks Robert and Ken. I'm seeing light at the end of the tunnel. Now I'm getting a TypeError that refers back to the geometryEngine saying "c.getCacheValue is not a function". I'm assuming I may have the wrong references (currently referencing 3.13)?
var geoms = [];
pondLayer.queryFeatures(query, function(featureSet){
for (var i = 0; i < featureSet.features.length; i++) {
var feature = featureSet.features;
geoms.push(feature);
};
var union = geometryEngine.union(geoms); //Notice I am using geometryEngine and not geometryEngineAsync
var query2 = new Query();
query2.geometry = union;
query2.spatialRelationship = Query.SPATIAL_REL_CONTAINS;
pondLayer.selectFeatures(query2, FeatureLayer.SELECTION_NEW);
});
Michael,
Correct the geometryEngine did not come out of Beta until 3.15, so just use 3.15.
c.getCacheValue is not a function still persists after switching to 3.15 and points to the geometryEngine. I'm going to keep digging, but I'm not finding an obvious solution. Any other ideas?
Thanks for all your help. Very appreciated.
Michael,
Is it possible to zip-up all your code and attach it to a reply (use the advance editor to get the attach option).
Michael,
Try this:
You need to add the features geometry and not just the feature to the geoms array.
function queryGo() { var query = new Query(); query.where = "EntityID = 11828"; query.outfields = ["*"]; query.returnGeometry = true; query.spatialReference = sr; query.outSpatialReference = sr; var geoms = []; var union; //geoms.SpatialReference = sr; 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; pondLayer.selectFeatures(query2, FeatureLayer.SELECTION_NEW); }); }
Hi Robert,
This is working great for me right now. I see the array of the unioned features, but I can't get the selected features to show now. Any ideas on why that may be? Thank you so much for your help.
Enjoy the day,
Mike
Hi Robert,
A little more digging on this. When I get the count of features selected by Query2 run against the pondLayer it returns all features in the database. Not sure if I'm missing a query parameter?
Enjoy the day,
Mike