lolochristen / OpenLayers.Blazor

An Map component for Blazor based on OpenLayers with support for swisstopo swiss maps.
MIT License
42 stars 15 forks source link

VectorGeoJSON layers display #70

Closed mcif2 closed 3 months ago

mcif2 commented 3 months ago

Hello. I have an issue when representing VectorGeoJSON layers. All the layers display with the same style I have tried setting a value for the Styles property without any success. This is the syntax I am using for the Styles property upon layer creation in the C# code

Layer vectorLayer1 = new Layer
{
    SourceType = SourceType.VectorGeoJson,
    Url = "https://localhost:8701/layers/1",
    Title = "Layer1",
    Visibility = true,
    Opacity = 1,
    Styles = "style:{'fill-color': 'darkgray'}"
};

I think the Styles string I am using might not be correct. This is because no matter what I type there, it will always display the same: blue border surrounding and white background.

What would be the format for that string?

I have not seen using this property being used for vectorGeoJSON layers in your application, hence the question.

In case this is not the right way to set the layer style, what would be the correct way to customize layer style?

Thanks in advance.

Best regards

lolochristen commented 3 months ago

The Styles property is for tile layers only. To apply a style for vector layers you can set style using Style property and assigning a StyleOptions object: Style="@(new StyleOptions() { Stroke = new StyleOptions.StrokeOptions { Color = "red", Width = 3 }})". A full example is in GeoJsonDemo.razor

or using the FlatStyle property with a Dictionary of styles (documented in openlayers API). You find an example in VectorLayersDemo,.razor.

Another option would be to implement a call back method for dynamic styles but this works only in WASM blazor scenarios.

mcif2 commented 3 months ago

Thank you.