How can I create a gradient-style line in Mapsui WPF, based on data?

92 Views Asked by At

Mapsui WPF Can I implement a style for the line so that the color of the line is a gradient depending on the data. At the moment, it turned out to display the route in only one color.

I tried using SkiaSharp to create a custom style and gradienttheme from mapsui, but it didn't work.

1

There are 1 best solutions below

0
pauldendulk On

It is not possible to use a gradient within a single feature. Classes that are derived from IThemeStyle (like GradientTheme and ThemeStyle) are styles that can be used to apply a gradient over a set of features where every individual feature as a single color.

What you could to is draw the route as a set of separate LineStrings which each have their own style specified by an IThemeStyle.

An alternative is to use a CustomThemeRenderer which allows you to do the rendering with SkiaSharp yourself. https://mapsui.com/documentation/custom-style-renders.html (This documentation might not be up to date for the latest release, look at the samples in the master branch instead).