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?
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();
}
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 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.