EDIT: Updates in the bottom

As a followup to my earlier question, I'm trying to implement custom symbol rendering for my WPF/ArcGIS application.

I'm accessing layers that have been published on the ArcGIS server, with pre-existing symbology already in place. I want to keep this symbol, and add text to it, since FeatureLayers don't automatically display their data labels. I'm running into several problems.

I've defined my renderer thus:

public class EntityLabelRenderer : IRenderer
    public Symbol GetSymbol(Graphic graphic)
        var objectId = graphic.Attributes["OBJECTID"]; // always set.
        var graphicFromServer = //Use a QueryTask to fetch the object;

        return graphicFromServer.Symbol; //add text

When I load my layer, GetSymbol is called for each object, but the Graphic object I get in the call is very barebones - the Symbol property is null, and the only values I can get are the ID. So I use that ID, as I show above, to fetch the full Graphics object with all its properties using a QueryTask. But even the one I get now has its Symbol set to null. Additionally, I don't know what the default data label for this object is, as set on the server. I have all the fields, but have to decide myself which to display.

So my question is: 1) Can I get, for a Graphic object fetched from an ArcGIS server, the default data label as defined in the MXD? 2) Get I get the default symbol for an object, as defined in the MXD on the server? Can I get that, then create a composite symbol comprised of both that symbol and an additional TextSymbol?

3) Is there another, better way? The only one I could think of was to create a custom GraphicsLayer and add TextSymbols to it manually for each object of mine, but this seems insanely complicated.

----- Update -----

I've gone over this and tried some things, and here's where I am in my attempts to get this working:

If I wait until my FeatureLayer's Initialized event is fired, I see that the layer comes populated with an IRenderer for the server-configured symbols. This is great, since I now have the symbol I want to display, as well as the layer's definition of the default text (to display as a label).

So now I can create my own IRenderer which wraps this server-generated IRenderer (usually a UniqueValueRenderer or UniqueMultipleValueRenderer) and adds the label. I can see two approaches: 1) Hacking into the existing renderer, changing its ControlTemplate to add my label, or 2) Somehow returning a composite Symbol that contains both the existing Symbol and my own TextSymbol.

Option #2 is better, but it seems that unlike the Flex and Java SDKs, the WPF SDK doesn't have a CompositeSymbol object. I'd rather not go for option #1 before I'm sure that a CompositeSymbol can't be implemented somehow. Does anyone know how I can go about this?

  • That is weird. The built-in rendereres, e.g. UniqueValueRenderer, access graphic attributes like this: graphic.Attributes[this.Field]. So it clearly expects all the attributes to be present. – Petr Krebs Feb 13 '12 at 12:46
  • Ok, it goes like this: the FeatureLayer class has a private method addRendererFieldsToQuery(), but it is only aware of the built-in renderer types. There is no generic interface-based way for your custom renderer to communicate to the FeatureLayer which fields should be included in the query. You can, however, tweak the FeatureLayer's OutFields property to include fields which are then used by the renderer. – Petr Krebs Feb 13 '12 at 12:50

Your Answer

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

Browse other questions tagged or ask your own question.