Select to view content in your preferred language

Custom WebTiledLayer: how to set Attribution correctly?

98
1
Jump to solution
a week ago
Labels (1)
Jube
by
Emerging Contributor

I have implemented my own version of WebTiledLayer.
Since WebTiledLayer is a sealed class, I had to inherit from ServiceImageTiledLayer.

I have implemented the GetTileUriAsync() function and it works fine.

Now, I would like to set the Attribution property, but it not virtual and readonly property from parent class Layer.
WebTiledLayer seems to have its own redefinition of Attribution property, which magically also set the Layer.Attribution property.

I tried to do the same with my implemention by hiding the parent property with the "new" keyword: new public string Attribution { get; set; }
But as expected the parent property is never set, and when my custom WebTiledLayer is used the empty Layer.Attribution is used instead of my new Attribution property.

How can I set correctly the parent Layer.Attribution property so that it is correctly displayed at the bottom left of the SceneViewer?

Thanks,
Jube

0 Kudos
1 Solution

Accepted Solutions
dotMorten_esri
Esri Notable Contributor

Nice catch. This is actually a bit of an oversight and should have been publicly settable from subclasses. I'll log an internal bug.
For now, here's a totally unsupported way to achieve it using reflection. This may or may not work in the future (tested on 200.8 but should likely work on older versions too):

private void SetAttribution(string attribution)
{
    var field = typeof(Esri.ArcGISRuntime.Mapping.ImageTiledLayer).GetField("_coreReference", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
    var method = field.FieldType.GetMethod("SetAttribution", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
    method.Invoke(field.GetValue(this), new object[] { attribution });
}

View solution in original post

1 Reply
dotMorten_esri
Esri Notable Contributor

Nice catch. This is actually a bit of an oversight and should have been publicly settable from subclasses. I'll log an internal bug.
For now, here's a totally unsupported way to achieve it using reflection. This may or may not work in the future (tested on 200.8 but should likely work on older versions too):

private void SetAttribution(string attribution)
{
    var field = typeof(Esri.ArcGISRuntime.Mapping.ImageTiledLayer).GetField("_coreReference", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
    var method = field.FieldType.GetMethod("SetAttribution", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
    method.Invoke(field.GetValue(this), new object[] { attribution });
}