Mapsui
Mapsui copied to clipboard
GeometryFeature does not render StyleCollection in WPF
Mapsui Version 4.0.0
Mapsui Platform WPF. Did not test other platforms
Device Windows device
Describe the bug When adding a StyleCollection to the Styles property of a GeometryFeature, the StyleCollection is not rendered on the map.
To Reproduce Steps to reproduce the behavior: Create map with base map. Create instance of Layer class with a null Style. Create a Point GeometryFeature. Create an instance of SymbolStyle with a Fill color. Create an instance of SymbolStyle with a bitmap. Create an instance of StyleCollection, setting the Styles property such that the two above SymbolStyles are included. Add StyleCollection to GeometryFeature.Styles. Add GeometryFeature to Layer. Add Layer to Map.
e.g.,
Result: No Styles render for GeometryFeature.
This is in contrast to the following that DOES work: Create map with base map. Create instance of Layer class with a null Style. Create a Point GeometryFeature. Create an instance of SymbolStyle with a Fill color. Add SymbolStyle to GeometryFeature.Styles. Create an instance of SymbolStyle with a bitmap. Add SymbolStyle to GeometryFeature.Styles. Add GeometryFeature to Layer. Add Layer to Map.
Expected behavior Both Styles in the StyleCollection are rendered on the map after the GeometryFeature is added to a layer
Screenshots I don't think that screenshots will really help in this instance. It's an all-or-nothing situation.
Additional context Code that does not work: SymbolStyle style1 = new SymbolStyle() { Fill = new Brush(Color.Orange), SymbolScale = 1.5 }; SymbolStyle style2 = new SymbolStyle() { BitmapId = ### }; StyleCollection styleCollection = new StyleCollection() { Styles = { style1, style2 } }; GeometryFeature feature = new GeometryFeature(new Point(0, 0)); feature.Styles.Add(styleCollection);
var dataSource = new MemoryProvider(new List<IFeature>() { feature });
Layer layer = new Layer() { DataSource = dataSource, Name = "Name", IsMapInfoLayer = true, Style = null };
MapControl.Map.Layers.Add(layer);
Code that does work: SymbolStyle style1 = new SymbolStyle() { Fill = new Brush(Color.Orange), SymbolScale = 1.5 }; SymbolStyle style2 = new SymbolStyle() { Fill = new Brush(Color.Black) }; GeometryFeature feature = new GeometryFeature(new Point(0, 0)); feature.Styles.Add(style1); feature.Styles.Add(style2);
var dataSource = new MemoryProvider(new List<IFeature>() { feature });
Layer layer = new Layer() { DataSource = dataSource, Name = "Name", IsMapInfoLayer = true, Style = null };
MapControl.Map.Layers.Add(layer);
The StyleCollection is not supported for the Feature.Styles. There is an explicit log line for that in our code:
https://github.com/Mapsui/Mapsui/blob/443a9bad7ec75a2478f8b91b6ba24a915ea6811d/Mapsui/Rendering/VisibleFeatureIterator.cs#L71
Btw, you should turn on Mapsui logging, it will save you a lot of time. https://mapsui.com/documentation/logging.html
But now you mention it, I don't see a reason why it was not implemented. Instead of writing the log line it could iterate over the styles in the StyleCollection and call the callback. I think it was just not done yet.
If someone would like to add it please provide a unit test and perhaps a sample (could be a geometry inside an existing sample).
Instead of using the StyleCollection on the Feature.Styles you could instead use it on the Layer.Style.
Ah, fair enough. Thanks for the heads up on that! Unfortunately, my current requirement makes setting the Style on the Feature the ideal choice. It isn't horribly inconvenient to simply set multiple Styles on the Feature, I just happened to stumble on the behavior.
Thank you for the note regarding logging. I will definitely turn that on. As far as I am concerned, this issue is resolved. But, since you have solicited work for a fix, I will leave the issue set to "Open".