Select to view content in your preferred language

Javascript API 4.3 unique rendering problem

1064
3
05-15-2017 03:57 PM
Yunpiao_WhitneyBai1
Deactivated User

Hi,

I'm trying to implement a function that allows to click a polygon to change its rendering. Here is my code.

this.view.on("click", function(evt){
   var point = {
      x:evt.x,
      y:evt.y
   };
   this.view.hitTest(point).then(function(response){
      var graphic = response.results[0].graphic; 
      var id= graphic.attributes.SITE_ID; // get the unique id for special rendering
      var lyr = graphic.layer;
      var render = new Renderer({
         field: "SITE_ID",
         defaultSymbol: lyr.renderer.symbol || lyr.renderer.defaultSymbol,
         uniquevalueInfos:[{
            value: id,
            symbol: new SimpleFillSymbol({
               color: [ 51,51, 204, 0.9 ],
               style: "solid",
               outline: {
                  color: "white",
                  width: 1
               }
            })
         }]
      });
      lyr.renderer=render;
});

}.bind(this));

The code runs fine without any error happen, and I also get the legend changed, but the rendering of that polygon does not change at all.  Does anyone have the same issue? 

0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Emeritus

Yunpaio,

   So I assume you have seen this sample, since your code looks like it was based on this:

Access features with click events | ArcGIS API for JavaScript 4.3 

I have not had your issue. Can you share you complete code for inspection?

0 Kudos
KristianEkenes
Esri Regular Contributor

It also looks like you're calling `new Renderer()` when it should be `new UniqueValueRenderer()` 

0 Kudos
Yunpiao_WhitneyBai1
Deactivated User

Robert and Kristian, 

Thank you both for the reply. I've found the problem, which is pretty dumb. It is because I did not capitalize 'V' for 'uniquevalueInfo' .

Again, thanks for the answer.

0 Kudos