Working on a custom WAB widget (JSAPI 3.x) that generates some buffers around user selected input features. Wanting to highlight features found within buffer on the map.
The following code (amalgamated from various online examples) finds the features but it won't highlight anything in the map:
...
bufferQuery = new Query();
bufferQuery.returnGeometry = true;
bufferQuery.where = "1=1";
bufferQuery.outFields = ["*"];
bufferQuery.SpatialRelationship = "SPATIAL_REL_CONTAINS";
bufferQuery.geometry = inputBuffer;
...
var selectionSymbol = new SimpleMarkerSymbol(
SimpleMarkerSymbol.STYLE_CIRCLE,
12,
new SimpleLineSymbol(
SimpleLineSymbol.STYLE_NULL,
new Color([247, 34, 101, 0.9]),
1
),
new Color([207, 34, 171, 0.5])
);
myFeatureLayer.setSelectionSymbol(selectionSymbol);
myFeatureLayer.selectFeatures(bufferQuery, FeatureLayer.SELECTION_NEW, function(results) {
console.log("found ", results.length, " features in buffer");
});
I've played around with taking each taking and making a new Graphic from it to then add to a graphics layers but my understanding from what I read was that the above or some variation thereof should highlight the selection using the specific symbology. Something missing?
Arne,
The code should work if the feature you are attempting to select is a point layer, depending on the spatial reference of the buffer being the same as the layer you are attempting to select.
That's what I thought but you bring up a good point - I ran into an issue with Linear/Angular spatial reference earlier. So maybe I'm mixing spatial reference. I'll take a look at that -thanks, Robert!
Robert Scheitlin, GISP - So the deeper I git here, the more confused I get. Looking at spatial references, it's clear that the features found in the buffers are WKID 4326 don't have the same WKID as the map, which is 102100, although they come from a map services that has the map's SR. Not sure why.
Anyway, so I add the below line, which fixes the WKID for what's returned...
bufferQuery.outSpatialReference = this.map.spatialReference;
But that doesn't put anything on the map.
The buffer that I'm creating with the following snippet also has WKID 4326 ...
inputBuffer = GeometryEngine.geodesicBuffer(myCtrPnt,[1000],"feet",true);
... my understanding was that geodesicBuffer would handle either of WGS84 and Web Mercator. I don't see a way to put any params into GeometryEngine like some of the GeometryService examples show. Is that what's needed here?
Arne,
Try using WebMercatorUtils geographicToWebMercator method to change the inputBuffer polygon from wkid 4326 to 102100
Cool, thanks, Your one-liners are like fresh batteries in the caverns of ESRI documentation. Haha.
Also. I just found that I may be complicating matters by using the result from a Search (with suggestions) to get my buffer center point and that seems to default to a WKID different from what's in my service. Not sure but I'm going to try to fix that it needed,.
Never did get the selectFeatures() to work so I resorted to a work-around, simply iterating over the features which queryFeatures() would return and making them into Graphics one by one. Then adding them to
map.graphics
Seems these days that half the things i try to do don't work out the way that my interpretation of the documentation says it should. In the end, what matters though are result and work-arounds do the job.