Replies: 6 comments 3 replies
-
You could look into Mapsui.UI.MapView/Objects/Circle.cs at line 154ff. There you could see, how a circle is created as polygon. |
Beta Was this translation helpful? Give feedback.
-
The other possible way (if you want a circle with a zoom independent radius) is to use a SymbolStyle of type SymbolType.Ellipse. |
Beta Was this translation helpful? Give feedback.
-
Perhaps we should have a sample to show both methods you describe. It is indeed a common request. Later we may want to add a CircleFeature. The first version could just draw a SkiaSharp Ellipse. More advanced versions could calculate the circle geographically correct. |
Beta Was this translation helpful? Give feedback.
-
@pauldendulk I made a PR long time ago for a circle, but you didn't accept it. But time change ;-) |
Beta Was this translation helpful? Give feedback.
-
Ok, I understand, that this is a common use case. It is something we have in MapView, but not in the normal MapControl. And it couldn't be added to Mapsui, because there is no polygon to use. So we have to decide where to put this and with which name. Were in MapView called Drawables: circles, lines and polygons. |
Beta Was this translation helpful? Give feedback.
-
I've come up with an example that appears to work. Pass in the radius in meters and you get a circle with that radius. I'm using wpf and satellite images. I got started with PolygonGeometrySample in the mapsui repo. This works for what I need. Figured I'd post this and hopefully it will help someone trying to do something similar. Why there needs to be a radius multiplier, I can't explain, but it is a constant value through the testing I've done. public static ILayer CreatePolygonLayer()
{
return new Layer("Polygons")
{
DataSource = new MemoryProvider(CreatePolygon().ToFeatures()),
Style = new VectorStyle
{
Fill = new Brush(new Color(150, 150, 30, 128)),
Outline = new Pen
{
Color = Color.Orange,
Width = 2,
PenStyle = PenStyle.DashDotDot,
PenStrokeCap = PenStrokeCap.Round
}
}
};
}
private static List<Polygon> CreatePolygon()
{
var polygons = new List<Polygon>();
var lon = 31.134190;
var lat = 29.979147;
var coordinates = CreateCircle(lon, lat, 500);
var circle = new Polygon(new LinearRing(coordinates),
new[]
{
new LinearRing(coordinates)
});
polygons.Add(circle);
// draw a 2nd, smaller circle
var coordinates2 = CreateCircle(lon, lat, 25);
var circle2 = new Polygon(new LinearRing(coordinates2),
new[]
{
new LinearRing(coordinates2)
});
polygons.Add(circle2);
return polygons;
}
private static Coordinate[] CreateCircle(double centerX, double centerY, double radius)
{
const double TORADIANS = Math.PI / 180;
// to get the correct distance the radius has to be multiplied by this
radius *= 1.218027;
var mPointCenter = SphericalMercator.FromLonLat(new MPoint(centerX, centerY));
List<Coordinate> coordinates = new List<Coordinate>();
for (int angle = 0; angle < 360; angle++)
{
// convert angle to radians
double angleRadians = angle * TORADIANS;
double x = mPointCenter.X + (double)(radius*Math.Cos(angleRadians));
double y = mPointCenter.Y + (double)(radius*Math.Sin(angleRadians));
coordinates.Add(new Coordinate(x, y));
}
// have to complete the circle to close the polygon
coordinates.Add(coordinates[0]);
return coordinates.ToArray();
} |
Beta Was this translation helpful? Give feedback.
-
I want to draw a circle on a map. I have the center point and a radius. I've searched around and a seen the same question asked, but no one ever really answers. Is this available in mapsui? Specifically wpf?
Beta Was this translation helpful? Give feedback.
All reactions