Akku,
I made a Desktop Edition version with the following code. Try to click on the map to see the effects.
private void DisplayMap_Load(object sender, EventArgs e)
{
winformsMap1.MapUnit = GeographyUnit.Meter;
winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);
GoogleMapsLayer googlemapLayer = new GoogleMapsLayer();
LayerOverlay staticOverlay = new LayerOverlay();
staticOverlay.Layers.Add("googlemapLayer", googlemapLayer);
InMemoryFeatureLayer GreatCircle = new InMemoryFeatureLayer();
GreatCircle.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.SimpleColors.Red, 3, true);
GreatCircle.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
staticOverlay.Layers.Add("GreatCircleLayer", GreatCircle);
winformsMap1.Overlays.Add("WorldOverlay", staticOverlay);
winformsMap1.CurrentExtent = new RectangleShape(-2000000, 2000000, 2000000, -2000000);
winformsMap1.Refresh();
winformsMap1.MapClick += new EventHandler<MapClickWinformsMapEventArgs>(winformsMap1_MapClick);
}
void winformsMap1_MapClick(object sender, MapClickWinformsMapEventArgs e)
{
InMemoryFeatureLayer greatCircleLayer = (InMemoryFeatureLayer)winformsMap1.FindFeatureLayer("GreatCircleLayer");
greatCircleLayer.InternalFeatures.Clear();
//double Longitude1 = -118.55;
//double Latitude1 = 34.08;
double Longitude1 = 0;
double Latitude1 = 0;
double Longitude2 = e.WorldX;
double Latitude2 =e.WorldY;
Proj4Projection proj4 = new Proj4Projection();
proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();
proj4.Open();
Vertex vertex = proj4.ConvertToInternalProjection(Longitude2, Latitude2);
proj4.Close();
MultilineShape greatCircleMultiLineShape = GetGreatCircle(new PointShape(Longitude1, Latitude1), new PointShape(vertex.X, vertex.Y));
greatCircleLayer.InternalFeatures.Add(new Feature(greatCircleMultiLineShape));
winformsMap1.Refresh();
}
private MultilineShape GetGreatCircle(PointShape pointShape1, PointShape pointShape2)
{
//Projection from Geodetic to Google Map.
Proj4Projection proj4 = new Proj4Projection();
proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();
proj4.Open();
Vertex offsetVertexReference = proj4.ConvertToExternalProjection(180, 0);
//Gets the Great Circle in decimal degrees.
MultilineShape greatCircleMultiLineShape = pointShape1.GetShortestLineTo(pointShape2, GeographyUnit.DecimalDegree);
//Builds the MultilineShape in the Google Map projection.
MultilineShape resultGreatMultiLineShape = new MultilineShape();
foreach (LineShape lineShape in greatCircleMultiLineShape.Lines)
{
//For the western hemisphere, simply converts to Google Map projection
if (lineShape.Vertices[0].X < 0)
{
LineShape resultLineShape = new LineShape();
foreach (Vertex vertex in lineShape.Vertices)
{
Vertex projVertex = proj4.ConvertToExternalProjection(vertex.X, vertex.Y);
resultLineShape.Vertices.Add(projVertex);
}
resultGreatMultiLineShape.Lines.Add(resultLineShape);
}
//For the eastern hemisphere, converts to Google Map projection and offsets.
else
{
LineShape resultLineShape = new LineShape();
foreach (Vertex vertex in lineShape.Vertices)
{
Vertex projVertex = proj4.ConvertToExternalProjection(vertex.X, vertex.Y);
resultLineShape.Vertices.Add(projVertex);
}
resultGreatMultiLineShape.Lines.Add(resultLineShape);
}
}
proj4.Close();
return resultGreatMultiLineShape;
}
Any more questions just feel free to let me know.
Thanks.
Yale