ThinkGeo.com    |     Documentation    |     Premium Support

LegendAdornmentLayer not display

Hallo,
I try to add a LegendAdornmentLayer in Code to the AdornmentOverlay. Basicly I use the same code as given in the “HowDoI-Example” (CreateClassBreakStyleSample.xaml.cs)
The layer is added to the Overlay (check in debug-window). The Overlay and the Layer property “IsVisible” are true. but the LegendLayer is not displayed. The ScalebarLayer (in the same Overlay) is displayed.

When I place the example-code in the Loaded-Event from the Usercontrol, the Legend is drawn.
Any suggestions?

Regards Torsten

Thanks Torsten,
I tried with the how do I sample. CreateClassBreakStyleSample.xaml.cs missed one line

mapView.Refresh();

So the full code will like this
private void MapView_Loaded(object sender, RoutedEventArgs e)
{
// Set the map’s unit of measurement to meters(Spherical Mercator)
mapView.MapUnit = GeographyUnit.Meter;

            // Add Cloud Maps as a background overlay
            var thinkGeoCloudVectorMapsOverlay = new ThinkGeoCloudVectorMapsOverlay("itZGOI8oafZwmtxP-XGiMvfWJPPc-dX35DmESmLlQIU~", "bcaCzPpmOG6le2pUz5EAaEKYI-KSMny_WxEAe7gMNQgGeN9sqL12OA~~", ThinkGeoCloudVectorMapsMapType.Light);
            mapView.Overlays.Add(thinkGeoCloudVectorMapsOverlay);

            ShapeFileFeatureLayer housingUnitsLayer = new ShapeFileFeatureLayer(@"../../../Data/Shapefile/Frisco 2010 Census Housing Units.shp");
            LegendAdornmentLayer legend = new LegendAdornmentLayer();

            // Setup the legend adornment
            legend.Title = new LegendItem()
            {
                TextStyle = new TextStyle("Housing Units", new GeoFont("Verdana", 10, DrawingFontStyles.Bold), GeoBrushes.Black)
            };
            legend.Location = AdornmentLocation.LowerRight;
            mapView.AdornmentOverlay.Layers.Add(legend);

            // Project the layer's data to match the projection of the map
            housingUnitsLayer.FeatureSource.ProjectionConverter = new ProjectionConverter(2276, 3857);

            AddClassBreakStyle(housingUnitsLayer, legend);

            // Add housingUnitsLayer to a LayerOverlay
            var layerOverlay = new LayerOverlay();
            layerOverlay.Layers.Add(housingUnitsLayer);

            // Add layerOverlay to the mapView
            mapView.Overlays.Add(layerOverlay);

            // Set the map extent
            housingUnitsLayer.Open();
            mapView.CurrentExtent = housingUnitsLayer.GetBoundingBox();
            housingUnitsLayer.Close();

            mapView.Refresh();
        }

Here is the result

You can see the Legend does show up on the lower right of the map. Or I may misunderstand the issue. If you could provide us a small sample to re-produce the issue that will be very helpful for us to look into more details.

Thanks

Frank

The AdornmentOverlay does not notice when new layers are added; you have to re-open it:

mapView.AdornmentOverlay.Close();
mapView.AdornmentOverlay.Layers.Add(...);
mapView.AdornmentOverlay.Open();

Thanks Clemens,
Could you please try with
mapView.AdornmentOverlay.Refresh();

I may misunderstand your issue. If you could provide us a sample that will be very helpfu.

By the way there is an issue in the V12.3.5 for the AdornmentOverlay. You may need get the latest version which is V12.3.10 and try again.

Thanks

Frank

Hallo Frank, hallo Clemens,

Thanks for your suggenstions. In the meantime I changed my code. I load the Adornmentlayers in the map - Load event, and set the visibility accordingly to my needs. When I change the Visibility of the layers, later in code and refresh the map, the results are correct.
Independently of my changes, I will try your hints.

Regards Torsten

Thanks Torsten,
Good to know it works. Go ahead let us know if you have more question.

Thanks

Frank