I am trying to query, by geometry, a FeatureLayer. The Feature layer is a "client-side" Feature layer-- its created from a bunch of graphics added to its `source` property. When I call the `queryFeatures` or `queryObjectIds` method to get features within an overlapping extent or shape I never get any results back.
Here is a codepen demonstrating the problem. The below code snippet shows my approach:
let graphics = [
new Graphic({
attributes: {
ogc_fid: 1,
val: "one"
},
geometry: new Point({
latitude: 44.99,
longitude: -68.99,
spatialReference: {latestWkid: 4326, wkid: 4326}
})
}),
new Graphic({
attributes: {
ogc_fid: 2,
val: "two"
},
geometry: new Point({
latitude: 44.98,
longitude: -68.98,
spatialReference: {latestWkid: 4326, wkid: 4326}
})
}),
]
let myLayer = new FeatureLayer({
source: graphics,
objectIdField: "ogc_fid",
fields: [{
name: "ogc_fid",
type: "oid"
}, {
name: "val",
type: "string"
}],
renderer: {
symbol: {
color: "red",
size: 6,
type: "simple-marker",
},
// overrides the layer's default renderer
type: "simple",
}
});
// .....
// try to query client-side featureLayer by an extent:
let extent = new Extent({
spatialReference: { wkid: 4326},
xmax: 45.5,
xmin: 44.7,
ymax: -68.5,
ymin: -69.5
})
myLayer.queryObjectIds({
geometry: extent,
spatialRelationship: "intersects",
//there are no features returned
}).then(result => console.log(result))
The above will return no results. I can get results via an attribute query but geometry-ones all return nothing. Can anyone spot what I am doing wrong?
What I've tried:
I've looked at other posts like this one where Robert's approach looks about the same as mine, besides him creating a special Query object. I've been able to get similar to above to work on a FeatureLayer based on a featureService (aka: url property).
As shown in the CodePen, I've also tried running the queries on the FeatureLayerView. Interestingly, no results return there under any circumstance which is also unexpected.. bonus points if you can explain that.