Select to view content in your preferred language

Generate Renderer issue

2936
10
Jump to solution
11-14-2012 11:34 AM
SamirGambhir
Frequent Contributor
Hi,
I am trying to generate a class breaks renderer using generateRenderer task, but the renderer object is not being returned. I am using ArcGIS Server 10.1 with Javascript API v=2.8. I am using the following esri example (Generate Renderer) to build my code.
function renderIndicator(ind, num, url) {  var classDef = new esri.tasks.ClassBreaksDefinition();  classDef.breakCount = num; //number of breaks  classDef.classificationField = ind; //field name  classDef.classificationMethod = "natural-breaks";  classDef.baseSymbol = symbol;          var colorRamp = new esri.tasks.AlgorithmicColorRamp();  colorRamp.fromColor = new dojo.colorFromHex('#ffff80');  colorRamp.toColor = new dojo.colorFromHex('#6B0000');  colorRamp.algorithm = "cie-lab";  // options are:  "cie-lab", "hsv", "lab-lch"  classDef.colorRamp = colorRamp;          var params = new esri.tasks.GenerateRendererParameters();  params.classificationDefinition = classDef;  var generateRenderer = new esri.tasks.GenerateRendererTask(url); //url of a feature layer  generateRenderer.execute(params);  dojo.connect(generateRenderer, function(renderer) {   return renderer;  }); }

The returned 'renderer' object is needed in another function to display features and generate a legend. It seems that dojo.connect is not working. What am I missing here?

Thanks
Samir
0 Kudos
1 Solution

Accepted Solutions
derekswingley1
Deactivated User
I've attached a simpler version of your page that uses 3.2 and works with a layer from on of our public map service. As long as you're using a 10.1 server, you should be able to replace the URL, change the field name and you should be good to go.

Please let me know if the attached code works with your map service.

View solution in original post

0 Kudos
10 Replies
SamirGambhir
Frequent Contributor
Hi,
I am trying to generate a class breaks renderer using generateRenderer task, but the renderer object is not being returned. I am using ArcGIS Server 10.1 with Javascript API v=2.8. I am using the following esri example (Generate Renderer) to build my code.
function renderIndicator(ind, num, url) {
 var classDef = new esri.tasks.ClassBreaksDefinition();
 classDef.breakCount = num; //number of breaks
 classDef.classificationField = ind; //field name
 classDef.classificationMethod = "natural-breaks";
 classDef.baseSymbol = symbol;

        var colorRamp = new esri.tasks.AlgorithmicColorRamp();
 colorRamp.fromColor = new dojo.colorFromHex('#ffff80');
 colorRamp.toColor = new dojo.colorFromHex('#6B0000');
 colorRamp.algorithm = "cie-lab";
 // options are:  "cie-lab", "hsv", "lab-lch"
 classDef.colorRamp = colorRamp;

        var params = new esri.tasks.GenerateRendererParameters();
 params.classificationDefinition = classDef;
 var generateRenderer = new esri.tasks.GenerateRendererTask(url); //url of a feature layer
 generateRenderer.execute(params);
 dojo.connect(generateRenderer, function(renderer) {
  return renderer;
 });
}

The returned 'renderer' object is needed in another function to display features and generate a legend. It seems that dojo.connect is not working. What am I missing here?

Thanks
Samir


How do I check if the renderer object has been created without applying it in this code? I suspect my code is not generating an object. Any suggestions?

Thanks
Samir
0 Kudos
SamirGambhir
Frequent Contributor
How do I check if the renderer object has been created without applying it in this code? I suspect my code is not generating an object. Any suggestions?

Thanks
Samir


Here is the complete code (and still unresponsive) for generating a renderer using Natural Breaks method:
function inti(){
        ...
        mapM = new esri.Map("mapM", {
  extent : iniExtent
 });
        ...
        stateFeatureLayer = new esri.layers.FeatureLayer("http://localhost:6080/arcgis/rest/services/State_profile/MapServer/1", {
  mode : esri.layers.FeatureLayer.MODE_ONDEMAND,
  outFields : ["*"],
  id : "stateFeatureLayer",
  infoTemplate : infoTemplate
 });
 distFeatureLayer = new esri.layers.FeatureLayer("http://localhost:6080/arcgis/rest/services/District_profile/MapServer/1", {
  mode : esri.layers.FeatureLayer.MODE_ONDEMAND,
  outFields : ["*"],
  id : "distFeatureLayer",
  infoTemplate : infoTemplate
 });
        ...
}

function queryParams(newGeog, indc, indv, myURL){
        if (mapM.infoWindow) {
  mapM.infoWindow.hide();
 }
 if (flag === true) { //flag value returned from another function, and this value has been verified
  myURL = "http://localhost:6080/arcgis/rest/services/State_profile/MapServer/1";
  queryTask = new esri.tasks.QueryTask(myURL);
 } else if (flag === false) {
  myURL = "http://localhost:6080/arcgis/rest/services/District_profile/MapServer/1";
  queryTask = new esri.tasks.QueryTask(myURL);
 }
 query = new esri.tasks.Query();
 query.returnGeometry = true;
 query.outFields = ["*"];
 query.where = "1=1";
 queryTask.execute(query);
 
        var defaultFrom = new dojo.colorFromHex('#ffff80');
 var defaultTo = new dojo.colorFromHex('#6B0000');
 var resultContent = "<tr>" + indc + ": <td>${" + indv + ":formatNumber}</td></tr>"; //'indc' is the name of the indicator and 'indv' is its value
 
        var classDef = new esri.tasks.ClassBreaksDefinition();
 classDef.breakCount = 3;
 classDef.classificationField = indv;
 classDef.classificationMethod = "natural-breaks";
 
 var colorRamp = new esri.tasks.AlgorithmicColorRamp();
 colorRamp.fromColor = defaultFrom;
 colorRamp.toColor = defaultTo;
 colorRamp.algorithm = "cie-lab"; // options are:  "cie-lab", "hsv", "lab-lch"
 classDef.colorRamp = colorRamp;
        
        var params = new esri.tasks.GenerateRendererParameters();
 params.classificationDefinition = classDef;
 var generateRenderer = new esri.tasks.GenerateRendererTask(myURL);
 generateRenderer.execute(params);
 dojo.connect(generateRenderer, "onComplete", function(renderer) {
  if (flag === true) {
   infoTemplate.setTitle("<tr>State: <td>${State_name}</tr></td>");
   stateFeatureLayer.setRenderer(renderer);
   stateFeatureLayer.refresh();
  } else if (flag === false) {
   infoTemplate.setTitle("<tr>DISTRICT: <td>${Dist_name}</tr></td><br /><tr>STATE: <td>${State_name}</tr></td>");
   var strNewGeog = "State_name= '" + newGeog[0] + "'";
   if (newGeog.length > 1) {
       for ( i = 1; i < newGeog.length; i++){
           strNewGeog += " OR State_name= '" + newGeog + "'";
       }
                        }
   distFeatureLayer.setDefinitionExpression(strNewGeog);
   distFeatureLayer.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW);
   distFeatureLayer.setRenderer(renderer);
  }
  infoTemplate.setContent(resultContent);
 }); //another function shows and hides the relevant feature layer
}
dojo.addOnLoad(init);


Please help me resolve this.
Thanks
Samir
0 Kudos
derekswingley1
Deactivated User
How do I check if the renderer object has been created without applying it in this code? I suspect my code is not generating an object. Any suggestions?


All the usual web debugging methods apply: 

  • watch the request to generateDataClasses via your browser's dev tools and look at the response

  • console.log the response

  • use a breakpoint to inspect various variable values at runtime


If you could post a complete but simplified version of your page so we can run and debug that would be helpful as well.

I'd also like to encourage you to upgrade to 3.2 even though our generate renderer sample does indeed work with 2.8.
0 Kudos
SamirGambhir
Frequent Contributor
All the usual web debugging methods apply: 

  • watch the request to generateDataClasses via your browser's dev tools and look at the response

  • console.log the response

  • use a breakpoint to inspect various variable values at runtime


If you could post a complete but simplified version of your page so we can run and debug that would be helpful as well.

I'd also like to encourage you to upgrade to 3.2 even though our generate renderer sample does indeed work with 2.8.


Hi Derek,
I have tried all these steps and followed the messages on web console but found no credible leads. I will try to create a simplified version which can be tested.
Thanks
Samir
0 Kudos
SamirGambhir
Frequent Contributor
Hi Derek,
I have tried all these steps and followed the messages on web console but found no credible leads. I will try to create a simplified version which can be tested.
Thanks
Samir


Hi Derek,
I tried resolving this issue by trying out different ways but failed. I have created a simplified version of this application and is attached. Can you please look at this? I have struggled quite a bit with this.
Thanks
Samir
0 Kudos
derekswingley1
Deactivated User
I've attached a simpler version of your page that uses 3.2 and works with a layer from on of our public map service. As long as you're using a 10.1 server, you should be able to replace the URL, change the field name and you should be good to go.

Please let me know if the attached code works with your map service.
0 Kudos
SamirGambhir
Frequent Contributor
I've attached a simpler version of your page that uses 3.2 and works with a layer from on of our public map service. As long as you're using a 10.1 server, you should be able to replace the URL, change the field name and you should be good to go.

Please let me know if the attached code works with your map service.


Hi Derek,
This code works really well with 3.2, but fails with 2.8 even if I make the changes necessary to access relevant dojo files. I can consider moving to 3.2 JS but that adds a lot of other complications. I am not sure what is it that makes it work with 3.2 but not with 2.8, even though the sample on ESRI site is designed for 2.8. Can you please make this code work with 2.8?
Thanks
Samir
0 Kudos
derekswingley1
Deactivated User
We don't usually modify or provide patches for older versions of our API. The later 2.x releases are when we started including new ArcGIS Server 10.1 functionality. We built those releases against beta releases of ArcGIS Server and occasionally had to work around issues in the 10.1 betas. Off the top of my head, I'm not certain we had workarounds in the generate renderer task but I suspect we did and that might be the reason this is failing. 3.0 coincided with the release of ArcGIS Server 10.1 final.

I think the more productive route is to move to 3.x, preferably 3.2.

What's stopping you from moving to 3.2? It is a different Dojo version, but I think most common migration issues are documented throughout this forum and we have a migrating to 3.0 doc that outlines a few things to know about. If you post specific issues/errors you're seeing as new threads here we can help (after you search the forum of course ;)).
0 Kudos
SamirGambhir
Frequent Contributor
We don't usually modify or provide patches for older versions of our API. The later 2.x releases are when we started including new ArcGIS Server 10.1 functionality. We built those releases against beta releases of ArcGIS Server and occasionally had to work around issues in the 10.1 betas. Off the top of my head, I'm not certain we had workarounds in the generate renderer task but I suspect we did and that might be the reason this is failing. 3.0 coincided with the release of ArcGIS Server 10.1 final.

I think the more productive route is to move to 3.x, preferably 3.2.

What's stopping you from moving to 3.2? It is a different Dojo version, but I think most common migration issues are documented throughout this forum and we have a migrating to 3.0 doc that outlines a few things to know about. If you post specific issues/errors you're seeing as new threads here we can help (after you search the forum of course ;)).


Hi Derek,
I managed to modify my application to work with 3.2. Thanks for your help fixing the renderer issue. Now I am trying to set up the legend but it is not working. The code below shows the legend only when the "Map it" button is clicked twice. I added a global variable (legendDijit), added CSS code as below and added this small piece of code to your existing code.
CSS:
#legend {width: 150px; color: black;}

JS:
if (legendDijit) {
 legendDijit.destroyRecursive(true);
}
    
legendDijit = new esri.dijit.Legend({
 map : mapM,
 layerInfos : [{
  layer : stateFeatureLayer,
  title : "Title"
  }]
 }, "legend");
legendDijit.startup();
legendDijit.refresh();


I'll appreciate it if you can look into it.
Thanks
Samir
0 Kudos