Watch Pre-recorded Live Shows Here
Why Join
Become a member
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
C# Corner Home
Technologies
Monthly Leaders
ASK A QUESTION
Forum guidelines
Samyrro Samyrrovich
2.1k
26
3.5k
C# GMap: How to draw arc on a map
Dec 9 2019 2:00 PM
Hello, how can I add a polygon to the map as in the picture below? From a certain point of coordinates should open a polygon long, for example, 1 kilometer and a 120-degree opening angle.
My code can only draw a circle. Can it be changed so that it can draw a polygon from a certain point of coordinates with an indication of the direction, distance of drawing and the angle of aperture?
private
void
CreateCircle(Double lat, Double lon,
double
radius,
int
ColorIndex) {
GMapOverlay markers =
new
GMapOverlay(mygmap,
"markers"
);
PointLatLng point =
new
PointLatLng(lat, lon);
int
segments = 1080;
List < PointLatLng > gpollist =
new
List < PointLatLng > ();
for
(
int
i = 0; i < segments; i++) {
gpollist.Add(FindPointAtDistanceFrom(point, i * (Math.PI / 180), radius / 1000));
}
GMapPolygon polygon =
new
GMapPolygon(gpollist,
"Circle"
);
switch
(ColorIndex) {
case
1:
polygon.Fill =
new
SolidBrush(Color.FromArgb(80, Color.Red));
break
;
case
2:
polygon.Fill =
new
SolidBrush(Color.FromArgb(80, Color.Orange));
break
;
case
3:
polygon.Fill =
new
SolidBrush(Color.FromArgb(20, Color.Aqua));
break
;
default
:
MessageBox.Show(
"No search zone found!"
);
break
;
}
polygon.Stroke =
new
Pen(Color.Red, 1);
markers.Polygons.Add(polygon);
mygmap.Overlays.Add(markers);
}
public
static
GMap.NET.PointLatLng FindPointAtDistanceFrom(GMap.NET.PointLatLng startPoint,
double
initialBearingRadians,
double
distanceKilometres) {
const
double
radiusEarthKilometres = 6371.01;
var distRatio = distanceKilometres / radiusEarthKilometres;
var distRatioSine = Math.Sin(distRatio);
var distRatioCosine = Math.Cos(distRatio);
var startLatRad = DegreesToRadians(startPoint.Lat);
var startLonRad = DegreesToRadians(startPoint.Lng);
var startLatCos = Math.Cos(startLatRad);
var startLatSin = Math.Sin(startLatRad);
var endLatRads = Math.Asin((startLatSin * distRatioCosine) + (startLatCos * distRatioSine * Math.Cos(initialBearingRadians)));
var endLonRads = startLonRad + Math.Atan2(Math.Sin(initialBearingRadians) * distRatioSine * startLatCos, distRatioCosine - startLatSin * Math.Sin(endLatRads));
return
new
GMap.NET.PointLatLng(RadiansToDegrees(endLatRads), RadiansToDegrees(endLonRads));
}
public
static
double
DegreesToRadians(
double
degrees) {
const
double
degToRadFactor = Math.PI / 180;
return
degrees * degToRadFactor;
}
public
static
double
RadiansToDegrees(
double
radians) {
const
double
radToDegFactor = 180 / Math.PI;
return
radians * radToDegFactor;
}
Reply
Answers (
1
)
Good codes but its doesnt show datas inserted
Web Api with ajax.