Select to view content in your preferred language

How to use a Renderer to override the symbology coming from the map service

1034
2
Jump to solution
10-14-2020 10:33 AM
MichelTurmel
Occasional Contributor

I am in the process of creating my first custom 2 D widget and I can dynamically add a layer on the map , but as soon as I try to add a renderer to override the symbology coming from the map service then the layer does not show on the Layer List anymore and I get no error message

 

Here is my environment:

   - Portal for ArcGIS version 10.6

   - Web AppBuilder Developer Edition 2.6

   - ArcGIS JavaScript API 3.33

 

Here is part of my code: as soon as I had the lines in bold then the layer does not show anymore:

 

I have defined:

define(['dojo/_base/declare',

  'jimu/BaseWidget',

  'dojo/on',

  'esri/layers/FeatureLayer',

  'esri/renderers/SimpleRenderer',

  'esri/symbols/PictureFillSymbol',

  'esri/Color',

  'esri/map',

  'esri/dijit/Legend'

],

function(declare,

        BaseWidget,

        on,

        FeatureLayer,

        SimpleRenderer,

        SimpleFillSymbol,

        Color,

        Map)

{

  //To create a widget, you need to derive from BaseWidget.

  return declare([BaseWidget],

  {          

  

    baseClass: "test",

..........

_onBtnTestClicked: function()

    {

var comp1 = test1.value;

 

      var template = new esri.InfoTemplate();

 

      var comp1OperatorLayerURL = "https://........";

      var comp1OperatorfeatureLayer = new esri.layers.FeatureLayer(comp1OperatorLayerURL, {

        id: comp1Operator,

        outFields: ["*"],

        opacity: 0.5,

        infoTemplate: template,

        mode: esri.layers.FeatureLayer.MODE_SNAPSHOT,

        definitionExpression: comp1OperatorSearch

      });

      comp1OperatorfeatureLayer._titleForLegend=comp1OperatorfeatureLayer.title=comp1OperatorfeatureLayer.name=comp1Operator;

      // set the symbology

      var symbol = new esri.symbol.SimpleFillSymbol().setColor(new esri.Color([255,0,0,0.5]));

      var renderer = new SimpleRenderer(symbol);

      comp1OperatorfeatureLayer.setRenderer(renderer);

      ......

 

      map.addLayers([comp12NonOperatedOVOperatedfeatureLayer,...]);

 

      ......

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Michel,

   You have:

define([
  'dojo/_base/declare',
  'jimu/BaseWidget',
  'dojo/on',
  'esri/layers/FeatureLayer',
  'esri/renderers/SimpleRenderer',
  'esri/symbols/PictureFillSymbol',
  'esri/Color',
  'esri/map',
  'esri/dijit/Legend'
],

function(declare,
  BaseWidget,
  on,
  FeatureLayer,
  SimpleRenderer,
  SimpleFillSymbol,
  Color,
  Map)
{‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

0 Kudos
2 Replies
RobertScheitlin__GISP
MVP Emeritus

Michel,

   You have:

define([
  'dojo/_base/declare',
  'jimu/BaseWidget',
  'dojo/on',
  'esri/layers/FeatureLayer',
  'esri/renderers/SimpleRenderer',
  'esri/symbols/PictureFillSymbol',
  'esri/Color',
  'esri/map',
  'esri/dijit/Legend'
],

function(declare,
  BaseWidget,
  on,
  FeatureLayer,
  SimpleRenderer,
  SimpleFillSymbol,
  Color,
  Map)
{‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

0 Kudos
MichelTurmel
Occasional Contributor

Thank you Robert,

So I understood the documentation right, I just entered the wrong widget.

Sorry about that!

0 Kudos