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; }); }
Solved! Go to Solution.
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
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);
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.
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
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.
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 ;)).
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();