ThinkGeo Cloud
ThinkGeo UI Controls
ThinkGeo Open Source
Help and Support
External Resources
ThinkGeo Cloud
ThinkGeo UI Controls
ThinkGeo Open Source
Help and Support
External Resources
using System; using System.Collections.Generic; using System.Linq; using System.Text; using ThinkGeo.MapSuite.Core; namespace GreatCircleWithGoogleMap { //This class, inheriting from Projection, applies the very simple projection of offsetting all the points //360 degrees to the left. class OffsetProjection: Projection, IDisposable { public double offset; // = 20026376.393709917 * 2;//20037503; //360 protected override Vertex[] ConvertToExternalProjectionCore(double[] x, double[] y) { Vertex[] vertices = new Vertex[x.Length]; for (int i = 0; i < vertices.Length; i++) { vertices[i] = new Vertex(x[i] - offset , y[i]); } return vertices; } protected override Vertex[] ConvertToInternalProjectionCore(double[] x, double[] y) { Vertex[] vertices = new Vertex[x.Length]; for (int i = 0; i < vertices.Length; i++) { vertices[i] = new Vertex(x[i] + offset, y[i]); } return vertices; } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } private void Dispose(bool disposing) { Close(); } } }
using System; using System.Configuration; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.WebEdition; namespace GreatCircleWithGoogleMap { public partial class TestForm : System.Web.UI.Page { enum OffsetType { OffsetWest, OffsetEast } protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF")); Map1.CurrentExtent = new RectangleShape(-27663034,9063122,-10064167,-468782); Map1.MapUnit = GeographyUnit.Meter; Map1.MapTools.OverlaySwitcher.Enabled = true; Map1.MapTools.MouseCoordinate.Enabled = true; //Adds the Google Map as an overlay GoogleOverlay google = new GoogleOverlay("Google Map"); google.JavaScriptLibraryUri = new Uri(ConfigurationManager.AppSettings["GoogleUri"]); google.GoogleMapType = GoogleMapType.Normal; Map1.CustomOverlays.Add(google); LayerOverlay layerOverlay = new LayerOverlay("PointOverlay", false, TileType.SingleTile); layerOverlay.TransitionEffect = TransitionEffect.None; //Projection to go from Geodetic to Google Map projection. Proj4Projection proj4 = new Proj4Projection(); proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326); proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString(); //Longitude1 = -93.697919536597226 //Latitude1= 47.9236905227374 //Longitude2 = 37.549353522156949 //Latitude2 = 37.660395791749444 //Display the feature for Los Angeles simply projecting from Geodetic to Google map projection. double Longitude1 = -118.55; //-93.697919536597226; // // double Latitude1 = 34.08; //47.9236905227374; // proj4.Open(); Vertex googleMapLAVertex = proj4.ConvertToExternalProjection(Longitude1, Latitude1); PointShape LA_Point = new PointShape(googleMapLAVertex); //Display the feature for Shanghai by projecting from Geodetic to Google map projection and then by using offseting projection. double Longitude2 = 121.78; //37.549353522156949; // double Latitude2 = 31.01; //37.660395791749444; // Vertex googleMapSVertex = proj4.ConvertToExternalProjection(Longitude2, Latitude2); OffsetProjection offsetProj = new OffsetProjection(); //Calculates what 360 degrees of offset corresponds to the Google projection for the offset value Vertex offsetVertexReference = proj4.ConvertToExternalProjection(180, 0); offsetProj.offset = - offsetVertexReference.X * 2; offsetProj.Open(); Vertex offsetVertex = offsetProj.ConvertToExternalProjection(googleMapSVertex.X,googleMapSVertex.Y); offsetProj.Close(); PointShape S_Point = new PointShape(offsetVertex); //(googleMapSVertex); //offsetVertex); Feature GPSFeature = new Feature(LA_Point); Feature GPSFeature2 = new Feature(S_Point); InMemoryFeatureLayer pointLayer = new InMemoryFeatureLayer(); pointLayer.InternalFeatures.Add(GPSFeature2); pointLayer.InternalFeatures.Add(GPSFeature); pointLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimplePointStyle(PointSymbolType.Square, GeoColor.StandardColors.Red, GeoColor.StandardColors.Black, 2, 20); pointLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; //InMemoryFeatureLayer for the Great Circle. InMemoryFeatureLayer GreatCircle = new InMemoryFeatureLayer(); GreatCircle.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.SimpleColors.Red, 3, true); GreatCircle.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; //The great circle requires to have the part being in the eastern hemisphere to be offset to the left // so that it display on the pacific rim. //We need to pass the points in decimal degrees. MultilineShape greatCircleMultiLineShape = GetGreatCircle(new PointShape(Longitude1, Latitude1), new PointShape(Longitude2, Latitude2),OffsetType.OffsetWest); Feature GreatCirclefeature = new Feature(greatCircleMultiLineShape); GreatCircle.InternalFeatures.Add("Great Circle", GreatCirclefeature); layerOverlay.Layers.Add(pointLayer); layerOverlay.Layers.Add(GreatCircle); Map1.CustomOverlays.Add(layerOverlay); } } private MultilineShape GetGreatCircle(PointShape pointShape1, PointShape pointShape2, OffsetType offsetType) { //Projection from Geodetic to Google Map. Proj4Projection proj4 = new Proj4Projection(); proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326); proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString(); //Offset projection for Google map. OffsetProjection offsetGoogleProj = new OffsetProjection(); proj4.Open(); Vertex offsetVertexReference = proj4.ConvertToExternalProjection(180, 0); if (offsetType == OffsetType.OffsetWest) { offsetGoogleProj.offset = offsetVertexReference.X * 2; } else { offsetGoogleProj.offset = -offsetVertexReference.X * 2; } offsetGoogleProj.Open(); //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(); if (greatCircleMultiLineShape.Lines.Count > 1) { foreach (LineShape lineShape in greatCircleMultiLineShape.Lines) { if (lineShape.Vertices[0].X < 0) { LineShape resultLineShape = new LineShape(); if (offsetType == OffsetType.OffsetWest) { foreach (Vertex vertex in lineShape.Vertices) { Vertex projVertex = proj4.ConvertToExternalProjection(vertex.X, vertex.Y); resultLineShape.Vertices.Add(projVertex); } } else { foreach (Vertex vertex in lineShape.Vertices) { Vertex projVertex = proj4.ConvertToExternalProjection(vertex.X, vertex.Y); Vertex offsetVertex = offsetGoogleProj.ConvertToExternalProjection(projVertex.X, projVertex.Y); resultLineShape.Vertices.Add(offsetVertex); } } resultGreatMultiLineShape.Lines.Add(resultLineShape); } else { LineShape resultLineShape = new LineShape(); if (offsetType == OffsetType.OffsetWest) { foreach (Vertex vertex in lineShape.Vertices) { Vertex projVertex = proj4.ConvertToExternalProjection(vertex.X, vertex.Y); Vertex offsetVertex = offsetGoogleProj.ConvertToExternalProjection(projVertex.X, projVertex.Y); resultLineShape.Vertices.Add(offsetVertex); } } else { foreach (Vertex vertex in lineShape.Vertices) { Vertex projVertex = proj4.ConvertToExternalProjection(vertex.X, vertex.Y); resultLineShape.Vertices.Add(projVertex); } } resultGreatMultiLineShape.Lines.Add(resultLineShape); } } } else { LineShape resultLineShape = new LineShape(); foreach (Vertex vertex in greatCircleMultiLineShape.Lines[0].Vertices) { Vertex projVertex = proj4.ConvertToExternalProjection(vertex.X, vertex.Y); resultLineShape.Vertices.Add(projVertex); } resultGreatMultiLineShape.Lines.Add(resultLineShape); } proj4.Close(); offsetGoogleProj.Close(); return resultGreatMultiLineShape; } } }
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestForm.aspx.cs" Inherits="GreatCircleWithGoogleMap.TestForm" %> <%@ Register Assembly="WebEdition" Namespace="ThinkGeo.MapSuite.WebEdition" TagPrefix="cc1" %> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <link href="~/theme/default/samplepic/style.css" rel="stylesheet" type="text/css" /> <title>Great Circle on Google Map</title> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <cc1:Map ID="Map1" runat="server" Height="100%" Width="100%"> </cc1:Map> <%-- <description:descriptionpanel ID="DescPanel" runat="server"> This sample displays a google map. Click buttons below to switch between different Google maps. <br /> <br /> <asp:Button CssClass="btn" ID="btnRoad" runat="server" Text="Normal" OnClientClick="Map1.SetCurrentBackgroundMapType(G_NORMAL_MAP); return false;" /> <asp:Button CssClass="btn" ID="btnAerial" runat="server" Text="Hybrid" OnClientClick="Map1.SetCurrentBackgroundMapType(G_HYBRID_MAP); return false;" /><br /> <asp:Button CssClass="btn" ID="btnSatellite" runat="server" Text="Satellite" OnClientClick="Map1.SetCurrentBackgroundMapType(G_SATELLITE_MAP); return false;" /> <asp:Button CssClass="btn" ID="btnPhysical" runat="server" Text="Physical" OnClientClick="Map1.SetCurrentBackgroundMapType(G_PHYSICAL_MAP); return false;" /> </description:descriptionpanel>--%> </form> </body> </html>