Select to view content in your preferred language

imageparameters.layerDefs does not work with 10.5

12826
44
Jump to solution
01-10-2017 10:14 AM
DuarteCarreira
Frequent Contributor

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.

1 Solution

Accepted Solutions
DonKang
Regular Contributor

Bug it is!

And this from ESRI Tech Support.

I tested on this issue, since the setLayerDefinitions requires an array of string, so even you provided a json object, it will still convert it to array object, which is a conflict with 10.5 service, so just like being discussed in the geonet thread, it is a bug, and currently the workaround might be keep using 10.3 service until we fixed this issue, so I submitted a bug regarding this issue: [BUG-000102051:setLayerDefinitions() function against dynamicmapservicelayer doesn't work for 10.5 services since the simple syntax is not valid for 10.5 anymore.

thanks

Don

View solution in original post

44 Replies
DonKang
Regular Contributor

I am having similar issues. It has taken me all day with 4 different ESRI Tech support to figure out.

As mentioned in the attached, layerDefs using simple syntax is no longer supported starting 10.5.
Meaning, it only works with Json Syntax. Currently, I am working to migrate 10.3 Server to 10.5. Using 10.5 service my application do not work and turns out to be due to this reason.

I am trying to figure out how to convert following to JSON syntax.

var layerDefinitions = [];
layerDefinitions[0] = "POPULATION > 5000000";
layerDefinitions[5] = "AREA > 100000";
dynamicMapServiceLayer.setLayerDefinitions(layerDefinitions);
DuarteCarreira
Frequent Contributor

Hi Don, good to know I'm not alone, though being a bug is alarming...

It seems to me every js app that needs to turn on/off change querydefs of layers will not work with a 10.5 server. That's a huge oversight if you ask me...

You can convert your example to json but it will only work using a direct request to the rest api, not using the js api.

Your example would be:

{0:"POPULATION > 5000000", 5:"AREA > 100000"}

You can see what's going on by copying the request in the browser's console. The request will end with a parameter like f=image. If you change this last parameter to f=html you will see a page where you can change all parameters including the querydefs.

This however it does not solve the problem: js api 3.9 does not comply with 10.5 server requiring a json string in querydefs. It's the js api responsibility to turn your programming into correct rest requests.

The only way out I see is to roll back 10.5 to 10.4, and wait for a compliant release of js api.

Rolling back has to be done manually: you have to write down every service configuration, every server configuration, and then recreate everything by hand. Unless you made a backup of your last configuration before upgrading to 10.5.

Anyway, a huge oversight from esri, and a huge loss of time and amount of problems for us.

If you hear anything positive from esri please let me know.

EDIT: it just now occurred to me it could be a bug with 10.5 server, accepting the wrong syntax in the layerdefs parameter, and not with the js api... also, I seem to remember an old solution where there was a way in the js api to edit the request before it was sent, correcting whatever was needed to make it work.

0 Kudos
DonKang
Regular Contributor

Thanks for your info.
Luckily my production environment is still in 10.3. I was in the process setting up a new production server with 10.5.
And yes this is a major issue. My app simply would not function if layer Definition issue is not fixed. 

I've contacted ESRI support with your posting.
I will let you know if I hear anything from ESRI.

thanks

Don

0 Kudos
DonKang
Regular Contributor

Bug it is!

And this from ESRI Tech Support.

I tested on this issue, since the setLayerDefinitions requires an array of string, so even you provided a json object, it will still convert it to array object, which is a conflict with 10.5 service, so just like being discussed in the geonet thread, it is a bug, and currently the workaround might be keep using 10.3 service until we fixed this issue, so I submitted a bug regarding this issue: [BUG-000102051:setLayerDefinitions() function against dynamicmapservicelayer doesn't work for 10.5 services since the simple syntax is not valid for 10.5 anymore.

thanks

Don

DuarteCarreira
Frequent Contributor

Don, thanks very much for posting this.

though the "workaround" is really more a "do not use".

i am  always amazed thinking how this kind of bugs keep getting through QC to releases. Exportmap is just the most used and fundamental request to the server... And the time it takes to solve... usually more than 12 months. If anything like this would happen, say with iis, I would expect a patch within days... but I think this time it´s really a huge bug that will really kill 10.5... so maybe a new js API release/patch might just appear quickly.

anyway, back to the past release...

JordanPorter
Deactivated User

I am also having the issue.  Anyone know of a resource guide for reverting back to 10.3 without a "backup" made?

0 Kudos
DuarteCarreira
Frequent Contributor

Jordan, you'll have to write down all your configurations and recreate everything in 10.3. This includes server configs like datasources and security, and services.

I think there are scripts that export services configs to help out a bit. Search online...

I have found another workaround that is not very elegant but works, by adding a few lines to your web app:

dynamicMapServiceLayer.on('update-start',function(evt) {
  console.log("Original layerDefs:" + evt.target._params.layerDefs);
 
  if(evt.target._params.layerDefs.charAt(0) !='{') {
    //if not json syntax, convert
    evt.target._params.layerDefs = evt.target._params.layerDefs.split(':').join(':"').split(';').join('",') + '"';
    evt.target._params.layerDefs = '{' + evt.target._params.layerDefs + '}';
  }
 
  console.log("Corrected layerDefs:" + evt.target._params.layerDefs);
 });

Just replace dynamicMapServiceLayer with your variable name. Place this code right after creating your layer.

Esri could/should come up with something better, like an override for the little piece of code that's building the wrong layerDefs syntax.

JordanPorter
Deactivated User

This just saved me.  After realizing the implications of downgraded ArcGIS server, that became a no-go.  

Considering that we have dozen of apps, with several dynamic layers in each, manually defining the listener on each layer would be cumbersome.  So I am utilizing this logic in a modular js file to include to loop through each dynamic service and apply the listener.  Thanks for your help!

0 Kudos
DuarteCarreira
Frequent Contributor

Jordan, I haven't tested the code properly and some scenarios I don't know what happens to layerDefs, like when it changes many times as the user operates the web app.

But if you get to create your module would you consider sharing?

Thanks.

0 Kudos