2

I'm having trouble setting the color of a feature layer in ArcGIS api for javascript. I have a feature layer, which, on the load event I set its renderer's colorInfo and opacityInfo. Both work individually, but when I try to set a specific color, and set the opacity of the color together, the color reverts to a default color from the feature layer. I've searched the documentation and tried everything--not a lot of examples pertinent to simple stuff like this. It's like colorInfo and opacityInfo conflict with each other.

<script>
require(["stuff"],function(stuff){
map = new Map("div",center, zoom, etc);
var featureLayer = new FeatureLayer("url",{
 id: "id",
 infoTemplate: esri.InfoTemplate({title: "${title}",content: "${content}"}),
 outFields:["*"],
 visible: true
));
featureLayer.on("load", function(){
featureLayer.renderer.setColorInfo({field: 'my_field', colors: ['#mycolor']});
featureLayer.renderer.setOpacityInfo({opacityValues: [0.25]}); //removes mycolor and sets it to some weird default color
});
});

All I'm really trying to do is define a specific color and set its opacity. I've also tried using a SimpleRenderer, but this seems to conflict with a toggle menu I'm using, so trying to stick with the feature layers own renderer methods.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jan 28, 2016 at 23:53

1 Answer 1

3

Your code seems to be working as it should.

https://jsfiddle.net/kmqqxfuq/

Please make sure there are no other events being fired which set the feature color/opacity. (feature layer on opacity-change etc)

answered Jan 29, 2016 at 3:53

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.