i need do query by more than one layer the same time

736
1
04-29-2019 06:09 AM
EduardoMazzucchelli
New Contributor II

is it posible ?

I use javascript 4.11

'https://js.arcgis.com/4.11/esri/themes/light/main.css',
'https://js.arcgis.com/4.11/',
"https://unpkg.com/angular-esri-map@2.0.5/dist/angular-esri-map.js"

const view = new MapView({
container: "viewDiv",
map: new WebMap({
basemap: "satellite",
layers: [
new FeatureLayer({
url: https://portalgis.sinopecarg.com.ar/arcgis/rest/services/SERVICIOS_GIS/InstalacionesPozos_GSJ/MapServer/1,
new FeatureLayer({
url: https://portalgis.sinopecarg.com.ar/arcgis/rest/services/SERVICIOS_GIS/InstalacionesPozos_GSJ/MapServer/2
]
}),

I need do a query by: 

const pozosA = view.map.layers.getItemAt(1);
const pozosI = view.map.layers.getItemAt(2);

How have I to do ???

Regards


Eduardo

0 Kudos
1 Reply
ReneRubalcava
Frequent Contributor

You can wrap multiple requests in a Promise.all

Promise.all([
  layer1.queryFeatures(query1),
  layer2.queryFeatures(query2)
]).then(([result1, result2]) => {
  // use your results
});

Only issue in this case, is if one request errors, they are both rejected. We have a utility in the API to handle this called esri/core/promiseUtils#eachAlways

There is a native Promise.allSettled that has the same behavior and will resolve when all promises are fulfilled, or rejected.

0 Kudos