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.

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.