Select to view content in your preferred language

Identifyparameters not working with layerids even with proposed fix

296
0
03-11-2022 09:45 AM
succip
by
Occasional Contributor

Hello,

I know there's a bug with 4.22's implementation of layerIds in IdentifyParameters but even with the proposed fix here , I'm still not seeing the results I'd expect. 

Please see my code below. mapServiceUrlList is an array of objects with { url, layerIds[] }. On map click I want to get all results from the identify. If I hard code layerIds outside of the forEach block with the array it works as intended, but if it's within the forEach dynamically generated it doesn't work. Any help is appreciated!

 

 

 

 

  let params = new IdentifyParameters({
    tolerance: 5,
    layerOption: "all",
    returnGeometry: true,
    spatialReference: view.spatialReference,
    geometry: mapPoint,
    width: view.width,
    height: view.height,
    mapExtent: view.extent,
  });

const mapServiceUrlList = getMapServiceUrls();
  mapServiceUrlList.forEach(({ url, layerIds }) => {
    params.layerIds = layerIds;
    params.sublayers = [{ id: params.layerIds }];
    identify.identify(url, params).then(({ results }) => {
      if (results.length > 0) console.log(results);
    });
  });

 

 

Edit: I found if I declare a new IdentifyParameters object with every iteration of the forEach it works as intended, otherwise it just runs properly on the first object iterated. See my fix here:

const mapServiceUrlList = getMapServiceUrls();
  mapServiceUrlList.forEach(({ url, layerIds }) => {
    let params = new IdentifyParameters({
      tolerance: 5,
      layerOption: "visible",
      returnGeometry: true,
      spatialReference: view.spatialReference,
      geometry: mapPoint,
      width: view.width,
      height: view.height,
      mapExtent: view.extent,
      layerIds,
    });
    params.sublayers = [{ id: params.layerIds[0] }];
    identify.identify(url, params).then(({ results }) => {
      if (results.length > 0) console.log(results);
    });
  });

 

 

0 Kudos
0 Replies