Hey everyone, I am attempting to create a renderer where the user is able to select the field on which to render based off of. I need to use UniqueValueDefinition as my render which means that I cannot use RendererChooser class—Web AppBuilder for ArcGIS (Developer Edition) | ArcGIS for Developers. After selecting the field the chrome console shoots back the following error
Uncaught TypeError: a.getFieldsUsedInExpressions is not a function
My feature layer is created like so:
var landusePolygonLayer = new FeatureLayer("https://services7.arcgis.com"),
id: "canada_Risk",//confirm works
mode: FeatureLayer.MODE_ONDEMAND,
outFields: ["*"]
});
I then call getData() after the user chooses the field ( which sets currField to that field which is used in the code below.
function getData(){
classBreaks("#ffffcc", "#006837");
}
function classBreaks(c1, c2) {
var classDef = new UniqueValueDefinition();
//define ColorRamp
var colorRamp = new AlgorithmicColorRamp();
colorRamp.fromColor = new Color.fromHex(c1);
colorRamp.toColor = new Color.fromHex(c2);
colorRamp.algorithm = "hsv"; // options are: "cie-lab", "hsv", "lab-lch"
//var classField = this.get("value")
console.log("This.get(value)", currField);//confirm the field is correct in console
classDef.attributeField= currField;//set def field to the user selected field
classDef.type = "classBreaksDef";
classDef.baseSymbol = new SimpleFillSymbol("solid", null, null);
classDef.ColorRamp = colorRamp;
//var params = new GenerateRendererParameters();
//params.classificationDefinition = classDef;
console.log("here")
this.map.getLayer("canada_Risk").setRenderer(classDef);
console.log("here2")
var currField
define(
['dojo/_base/declare',
"dijit/_WidgetsInTemplateMixin",
'jimu/BaseWidget',
"esri/toolbars/draw",
"esri/toolbars/edit",
"esri/graphic",
"esri/request",
"esri/config",
"esri/Color",
"esri/renderers/Renderer",
"esri/tasks/ClassBreaksDefinition",
"esri/tasks/UniqueValueDefinition",
"esri/tasks/ColorRamp",
"esri/tasks/AlgorithmicColorRamp",
"esri/tasks/GenerateRendererParameters",
"esri/tasks/GenerateRendererTask",
"esri/layers/LayerDrawingOptions",
"esri/layers/FeatureLayer",
"esri/layers/Field",
"esri/symbols/SimpleMarkerSymbol",
"esri/symbols/SimpleLineSymbol",
"esri/symbols/SimpleFillSymbol",
"esri/dijit/editing/TemplatePicker",
"esri/dijit/editing/Editor",
"dojo/_base/array",
"dojo/_base/event",
"dojo/_base/lang",
"dojo/parser",
"dijit/registry",
"dojo/data/ItemFileReadStore",
"dojox/grid/DataGrid",
"dijit/form/FilteringSelect",
"dijit/form/Select",
"dojo/on",
"dojo/data/ObjectStore",
"dojo/store/Memory",
"dojo/domReady!"],
function(declare,_WidgetsInTemplateMixin, BaseWidget, Draw, Edit, Graphic, esriRequest, esriConfig, Color,Renderer,
ClassBreaksDefinition, UniqueValueDefinition, ColorRamp, AlgorithmicColorRamp,
GenerateRendererParameters, GenerateRendererTask, LayerDrawingOptions,
FeatureLayer,Field,
SimpleMarkerSymbol, SimpleLineSymbol, SimpleFillSymbol,
TemplatePicker,Editor,
arrayUtils, event, lang, parser, registry, ItemFileReadStore, DataGrid, FilteringSelect,Select, On,ObjectStore, Memory) {
Solved! Go to Solution.
Abhinav,
So like I said I tested this and it worked fine for me using my service url. So the next question is are you using the right symbol type? The code is setup to symbolize a Polygon feature.
This is great! Maybe a new thread, but the layer is not refreshing with the new symbology until I navigate or zoom.
I'm attempting to put a legend in too, but that is off topic.
David,
It that version I forgot to add a layer refresh (line 4):
generateRenderer.execute(params, lang.hitch(this, function(renderer){
console.info(renderer);
this.map.getLayer("canada_Risk").setRenderer(renderer);
this.map.getLayer("canada_Risk").refresh();
}), lang.hitch(this, function(err){
console.info(err);
}));
Yeah i have a regular feature layer (not a dynamic layer or anything) that is a polygon feature. with full control over the polygon.
Is your layer publicly accessible? If so can you share the url for me to test?
Im sorry Robert, it isn't publiv and I am unable to make it public. only thing I can think of that could be different is the fact that it has been optimized for layer drawing in the layer settings. But I do not believe that could cause an issue.
The layer does have a lot of polygons as well. I do not know if the screenshot below will help.
Not sure what to tell you then. I have provided code that I have tested on my end to work with data I use.
Yea, you have done everything you can and ill mark the zip file comment as correct. If I am able to fix my issue I will post an update in this thread.
Thanks for all the help Robert!
I think what is happening that the renderer is not attaching the symbols to the values (hopefully I worded that correctly)
here is an example of the legend after setting the renderer.
those are the correct values for the field i have chosen but they are given a null symbol. I don't see why it would do that for my feature layer but not for your feature layer.
I too downloaded @RobertScheitlin__GISP 's attached widget code and my results are similar to yours. The values for the field are shown but the symbols are not.