AnsweredAssumed Answered

Change Map Service Label Color on Event

Question asked by lloydbronn on Nov 14, 2016
Latest reply on Nov 16, 2016 by JKingesriaustralia-com-au-esridist

I have a dynamic map service with labels. I'm wondering how to change the color of labels when certain basemaps are chosen from the basemap gallery. I'm playing around with the label class, trying to set the label text from the default black to white when the dark gray canvas basemap is chosen. I've tried to use labelClass.where and it's not working, probably because the basemap is not a field in the layer (according to LabelClass | API Reference | ArcGIS API for JavaScript 3.18 ).

 

map = new Map("map", {
basemap: "gray",
center: [0, 40],
zoom: 2,
maxZoom: 12,
minZoom: 2,
infoWindow: popup,
showLabels : true
});

 

var labelClass = new LabelClass();
labelClass.symbol = new TextSymbol({
font: new Font("12", Font.STYLE_NORMAL, Font.VARIANT_NORMAL, "Arial"),
color: new Color("#FFFFFF")
});

labelClass.where = basemapGallery.basemaps('basemap_7');

 

I've also tried this:

 

basemapGallery.on("selection-change",function(){
var tp = dijit.byId("TitlePane");
var layer = map.getLayer(refLayerId);
if(basemapGallery.basemaps === 'basemap_7'){
labelClass = true;
}
if(layer && tp != null){
map.removeLayer(layer);
tp.toggle();
}
else{tp.toggle();}
});

Outcomes