I use mapsui control in WPF to show on the map 4 lines between 5 points. I implemented a method that shows the selected line by clicking on the map. Now I need to be able to select all 4 lines at the same time. It would be preferable that when the cursor is dragged, a polygon is formed and all the lines in them are selected. How could I implement such a method with Mapsui Control? Unfortunately I can't find this information in the mapsui documentation on the site.
public Task<Map> CreateMapAsync(Map map)
{
map.Layers.Add(Mapsui.Tiling.OpenStreetMap.CreateTileLayer());
var polylineLayer = CreatePolylineLayer();
map.Layers.Add(polylineLayer);
map.Navigator.CenterOnAndZoomTo(polylineLayer.Extent!.Centroid, map.Navigator.Resolutions[6]);
map.Info += (s, a) => ToggleSelected(a.MapInfo?.Feature);
map.Widgets.Add(new MapInfoWidget(map));
return Task.FromResult(map);
}
public static ILayer CreatePolylineLayer()
{
return new Layer("Polyline")
{
DataSource = new MemoryProvider(CreatePolylines(CreatePoinst()).Select(p => new GeometryFeature { Geometry = p })),
Style = CreateLineStringStyle(),
IsMapInfoLayer = true
};
}
private static List<Point> CreatePoinst()
{
var berlin = new Point(13.4050, 52.52);
var dresden = new Point(13.7373, 51.0504);
var leipzig = new Point(12.3712900, 51.33962);
var stuttgard = new Point(9.1829321, 48.7758459);
var hannover = new Point(9.7332, 52.3705);
List<Point> points = new List<Point>() { berlin, dresden, leipzig, stuttgard, hannover };
return points;
}
private static List<LineString> CreatePolylines(List<Point> points)
{
List<LineString> ListPolylines = new List<LineString>();
for (int i = 0; i < points.Count-1; i++)
{
var netTopSu = NetTopologySuite.NtsGeometryServices.Instance.CreateGeometryFactory(4326);
var lnsAURtoLER = netTopSu.CreateLineString(new[] {
new NetTopologySuite.Geometries.Coordinate(points[i].Y, points[i].X),
new NetTopologySuite.Geometries.Coordinate(points[i+1].Y, points[i+1].X)});
var stringOfGeometry = lnsAURtoLER.ToString();
var lineString = (LineString)new WKTReader().Read(stringOfGeometry);
lineString = new LineString(lineString.Coordinates.Select(v => SphericalMercator.FromLonLat(v.Y, v.X).ToCoordinate()).ToArray());
ListPolylines.Add(lineString);
}
return ListPolylines;
}
public static IStyle CreateLineStringStyle()
{
return new ThemeStyle(f =>
{
if (f["selected"]?.ToString().Length > 0 ) //f["selected"]?.ToString() == "true"
return new VectorStyle
{
Fill = null,
Outline = null,
Line = { Color = Mapsui.Styles.Color.Blue, Width = 4 }
};
return new VectorStyle { Fill = null, Outline = null, Line = { Color = Mapsui.Styles.Color.Red, Width = 5 } };
});
}```
I don't know exactly what you are trying to do, but if you want to threat the collection of lines as one geometry you could use an NTS MultiLineString. So the method now called CreatePolylines should return a MultiLineString.
If you need to select one line in one scenario and all lines in another scenario then you need to solve this in your own code, Mapsui has no off the shelf solution for that.