imageparameters.layerDefs does not work with 10.5

11125
44
Jump to solution
01-10-2017 10:14 AM
DuarteCarreira
Occasional Contributor II

It seems REST API in 10.5 deprecated simple sintax on layerDefs:

ArcGIS REST API 

Simple syntax is not supported as an expected value for layerDefs parameter starting 10.5.

This is pretty hidden in the documentation by the way...

As a side effect, it seems imageparameter.layerDefinitions no longer works since it still translates requests to the simple sintax:

ImageParameters | API Reference | ArcGIS API for JavaScript 3.19 

In our server we get an error when debugging http requests on the browser's console:

{"error":{"code":400,"message":"Invalid 'layerDefs' is specified","details":[]}}

Our code is pretty simple and worked last week against a 10.3 server.

Can anyone reproduce and confirm this?

EDIT: Just to add that the simplest sample from esri does not work against a 10.5 server:

Layer definitions on a dynamic map service | ArcGIS API for JavaScript 3.19 

It seems a bug to me... I wish I'm proven wrong...

Thanks.

44 Replies
JeremyRead1
New Contributor III

So, I've been working with a really smart developer at Esri, and he's discovered that if you have sublayers within layers, and those sublayers are turned off by default, then that makes this error show up. It's requesting the sublayers and since they are off, it cannot find them to display on the map. He modified the request to exclude these layers, and it worked correctly and returned the .png image. Not sure of the final solution, but it's probably going to either be a code modification for it to avoid sending the sublayers which are off to the request, or just having all the sublayers turned on in the map service. Just wanted to pass this along in case it may help you. I will also update with the final solution for this once it is in place.

Wanted to note that version 10.3.1, which we were on before, did not care about the invalid sublayers and just ignored them. 10.5.1, however, does care about this and will fail on these.

0 Kudos
JeremyRead1
New Contributor III

Ok, here was the solution in my particular case. We had to change the function in the widget that returns the Sublayer Id's to be able to return "undefined". See below where "return '1=1';" was commented out and changed to "return = undefined;"

    filterLayer: function filterLayer(layer, whereClause) {
      var layerDefinitions = layer.layerInfos.map(function (layerInfo) {
        if (layerInfo.subLayerIds == null) {
          return whereClause;
        } else {
          // return '1=1';
            return undefined;
        }
      });
      layer.setLayerDefinitions(layerDefinitions);‍‍‍‍‍‍‍‍‍‍
JeremyBeeler
New Contributor

There was a similar fix in my case.  Our code was passing "1=2" as criteria to one of our layers and that was the problem.  The code is pretty old and I'm guessing the original author was trying to control visibility but removing that did fix the problem.

marko_antoniopachas_tavara
New Contributor

Hi, I'm not good with english but I hope to help you.

I have the same problem, I'm working with API JS 3.12 and AGS 10.5, the problem was the same as the first of the list when I set the layer definition directly on a dynamic layer previously charged. So, in my case I solved it by modyfing the init.js, on the  next method

original method:

setLayerDefinitions:function(b,c){this.layerDefinitions=b;this._params.layerDefs=a._serializeLayerDefinitions(b);this._updateDynamicLayers();c||this.refresh(!0)}, changed to    

new method:

setLayerDefinitions:function(b,c){this.layerDefinitions=b;this._params.layerDefs="{"+a._serializeLayerDefinitions(b)+"}";this._updateDynamicLayers();c||this.refresh(!0)};

Whatever it solved my problem.

0 Kudos
SigamGeo
New Contributor II

I have this problem with version 10.6. I was forced to use Duarte's work around to my popup to work.

In 10.3 the script worked setting layer definitions when loading the map:

    var condicao = null;
    if (parseInt(numeroAia) > 0){
        condicao = "idAuto  = " + numeroAia;
    }
    else if(parseInt(ocorrenciaId) > 0){
        condicao = "idOcorrencia = " + ocorrenciaId;
        if (tabAtiva.id.indexOf("tpAmbiente_tab") > 0) {
            condicao += " and  idMFOA = " + meioFisicoId;
        }
    }

    var layerDef = [];
    layerDef[0] = condicao;
    layerDef[1] = condicao;

Now is not enough to change layerDef format to json in the beggining, I had to change it on the click event to override identifyParams.layerDefinitions:

    var executeIdentifyTask = function (evt) {        

        var layerDef2 = {
            "0": condicao,
            "1": condicao
        };

        identifyParams.layerDefinitions = layerDef2;
        identifyParams.geometry = evt.mapPoint;
        identifyParams.mapExtent = mapa.extent;

        var deferred = identifyTask
            .execute(identifyParams)

Because once set identifyParams.layerDefinitions, it is not in json format anymore.

0 Kudos