I am using the Bootleaf IAG framework.
I can not figure out how to get the bounding coordinates of a filtered layer.
I am modifying the bootleaf code to query points with a polygon layer. The Query Widget already allows users to draw a polygon, but I want to select a polygon from a layer hosted on my arcgis server. I modified the filter widget by removing the text field and allowing my users to select polygon layers and values from a dropdown menu. This works fine.
Now I need to take the result of the layer.setWhere(where, handleError);
code and merry it with the query below. I need selectedPolygon
to equal the result of layer.setWhere(where, handleError);
and use the bounding coordinates in the .within
section of the query.
I have tried a number of things, L.latLngBounds
, getBounds()
, and toGeoJSON().features[0].geometry.coordinates
to name a few, but but I can not figure out how to pull out the bounds. What is the correct code?
const query = L.esri.query({ url: pointInPolygonUrl })
.token(pointInPolygonData.token)
.within(selectedPolygon)
query.run(function (error, data, response) {
if (error) {
console.log(error);
return;
}
6/8/2021 Edit (based on Seth Lutske's comment:
I did not provide a code sandbox for two reasons: 1 - bootleaf has a lot of files, 2 - all of my layers require secure sign in to arcgis. Hopefully I can provide enough information to get assistance without it.
Is
selectedPolygon
changing the way I am expecting? Currently there is no variable calledselectedPolygon
because I can not figure out the correct way to format it.selectedPolygon
is what I want to call the filter resultlayer.setWhere(where, handleError);
. I set the polygon layer up to filter on the map as the value changes. I can verify it is filtering as expected.selectedPolygon
format - This is where my problem lies. I can not seem to find the correct format based on how bootleaf layers are configured. I started withvar selectedPolygon =
layer.features.geometry.coordinates;
and got a geometry undefined error. I proceeded to try every other code I could think of to get the bounds.Bounding coordinates may not be the proper terminology. I want to run a query to find all of the points within the filtered polygon. To achieve this, it is my understanding that I need to use the bounds of the filtered polygon in the
within
section of the query.
6/8/2021 Edit #2
This link may be most beneficial to show how the layer is constructed. I modified this code to remove the text input and add a dropdown, but the basic definition should be the same.
Line 1605 is function addFilter()
Line 1804 is function applyFilter()
Line 1927 is layer.setWhere(where, handleFilterError);
Photo 1: console.log("polygon layer", layer)
Photo 2: Expanded _layers
Photo 3: Expanded _rings
(I did not find ToGetJSON
, but I found ToGeoJSON
in this section.
It looks like if I can get to _rings
then I should be fine, but that is where my knowledge is lacking.
within
can accept quite a few different kinds of geometry type arguments. 1 are you sure theselectedPolygon
is changing according to your UI in the way you expect? 2 IsselectedPolygon
in any of the accepted formats as described in the docs I linked? What format is it in? 3 You want to use the bounding coordinates ofselectedPolygon
, or the polygon itself, in thewithin
query? !important: As always, providing a codesandbox demonstrating the issue will make helping you much easier.layer
gets defined. Is there atoGetJSON
anywhere up the prototype chain on that (under the __proto__ property)?layer
you're printing isbootleaf.layers
...what is that? I don't see any documentation about bootleaf's api. Therings
you see are arcgis js api rings, which each represent a single polygon, usually in a multipolygon layer. Have you checked the __proto__ oflayer
? Does it not contain.toGeoJSON
?