How to get DynamicMapServiceLayer's default renderer

2810
3
Jump to solution
06-13-2016 01:58 AM
baohuachu3
New Contributor III

in the rest service ,there is renderer in "Drawing Info" ​but in JS api it is not found.

Tags (2)
1 Solution

Accepted Solutions
FC_Basson
MVP Regular Contributor

You can probably retrieve it by getting the layer information in JSON with a request (esri/request | API Reference | ArcGIS API for JavaScript )

var layersRequest = esri.request({
   url: "http://<server>/arcgis/rest/services/<service>/MapServer/<layer index>",
   content: { f: "json" },
   handleAs: "json",
   callbackParamName: "callback"
});

layersRequest.then(
   function(response) {
      console.log("Success: ", response.drawingInfo);
   },
   function(error) {
      console.log("Error: ", error.message);
 });

This will give you the same result as http://<server>/arcgis/rest/services/<service>/MapServer/<layer index>?f=pjson

View solution in original post

3 Replies
FC_Basson
MVP Regular Contributor

You can probably retrieve it by getting the layer information in JSON with a request (esri/request | API Reference | ArcGIS API for JavaScript )

var layersRequest = esri.request({
   url: "http://<server>/arcgis/rest/services/<service>/MapServer/<layer index>",
   content: { f: "json" },
   handleAs: "json",
   callbackParamName: "callback"
});

layersRequest.then(
   function(response) {
      console.log("Success: ", response.drawingInfo);
   },
   function(error) {
      console.log("Error: ", error.message);
 });

This will give you the same result as http://<server>/arcgis/rest/services/<service>/MapServer/<layer index>?f=pjson

DuarteCarreira
Occasional Contributor II

it seems there are things that should be simpler... and easier...

The 1st option of requesting using the rest api does not work if it was disabled which many people do.

The 2nd option may work. It is such a long winded workaround I'm suprised anyone ever thought of that... I'm going to give it a try.

But it really is strange you cannot just tweak a renderer, eg change 1 color. You have to build an entire new renderer, and disregard completly what the author of the map intended for the symbology of the layers. It's just awkward...

KristianEkenes
Esri Regular Contributor

Yeah, you can request it as done in the previous comment, or you can create a FeatureLayer with the sublayer ID appended to the end of the URL and access the renderer that way.