//extend the class dojo.declare("esri.renderer.LabelRenderer", esri.renderer.Renderer, { constructor: function (sym,attr) { // 2nd constructor signature added at v2.0: // esri.renderer.SimpleRenderer(<Object> json); if (sym && !sym.declaredClass) { // REST JSON representation var json = sym; sym = json.symbol; if (sym) { this.symbol = esri.symbol.fromJson(sym); } this.label = json.label; this.description = json.description; } else { this.symbol = sym; } this.attributeField = attr; }, getSymbol: function (graphic) { this.symbol.text = graphic.attributes[this.attributeField] return this.symbol; }, toJson: function () { return esri._sanitize({ type: "label", label: this.label, description: this.description, symbol: this.symbol && this.symbol.toJson() }); } } ); //add the renderer var font = new esri.symbol.Font("16pt", esri.symbol.Font.STYLE_NORMAL, esri.symbol.Font.VARIANT_NORMAL, esri.symbol.Font.WEIGHT_BOLD, "Helvetica"); var textSymbol = new esri.symbol.TextSymbol("", font, new dojo.Color("#666633")); textSymbol.setOffset(0, 8); var renderer = new esri.renderer.LabelRenderer(textSymbol,"OBJECTID"); featureLayer.setRenderer(renderer);
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.