User Tools

Site Tools


source_code_webeditionsample_gpstogooglemap_cs_100108.zip

Source Code WebEditionSample GPStoGoogleMap CS 100108.zip

TestForm.aspx.cs

using System;
using System.Configuration;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.WebEdition;
namespace GPStoGoogleMap
{
    public partial class TestForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"));
                Map1.CurrentExtent = new RectangleShape(-10608900,4716556,-10604285,4714110);
                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;
                InMemoryFeatureLayer pointLayer = new InMemoryFeatureLayer();
                pointLayer.Open();
                pointLayer.Columns.Add(new FeatureSourceColumn("Text"));
                pointLayer.Close();
                //Sets the projection parameters to go from Geodetic (EPSG 4326) or decimal degrees to Google Map projection (Spherical Mercator).
                //
                Proj4Projection proj4 = new Proj4Projection();
                proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
                proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();
                //Applies the projection to the InMemoryFeatureLayer so that the point in decimal degrees (Longitude/Latitude) can be
                //match the projection of Google Map.
                pointLayer.FeatureSource.Projection = proj4;
                //Values in Longitude and Latitude.
                double Longitude = -95.2809;
                double Latitude = 38.9543;
 
                //Creates the feature made of a PointShape with the Longitude and Latitude values.
                Feature GPSFeature = new Feature(new PointShape(Longitude, Latitude));
                //Format the Longitude and Latitude into a nice string as Degrees Minutes and Seconds
                string LongLat = DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegreePoint(GPSFeature);
                //Sets the InMemoryFeatureLayer to have it displayed with Square symbol and with text.
                GPSFeature.ColumnValues.Add("Text",LongLat);
                pointLayer.InternalFeatures.Add(GPSFeature);
                pointLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimplePointStyle(PointSymbolType.Square,
                                                                        GeoColor.StandardColors.Red, GeoColor.StandardColors.Black, 2, 12);
                pointLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.CreateSimpleTextStyle("Text", "Arial", 12, DrawingFontStyles.Bold,
                                                                        GeoColor.StandardColors.Black, GeoColor.StandardColors.White, 3, -10, 10);
                pointLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
                layerOverlay.Layers.Add(pointLayer);
                Map1.CustomOverlays.Add(layerOverlay);
             }
        }
    }
}

TestForm.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestForm.aspx.cs" Inherits="GPStoGoogleMap.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>Use 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>
source_code_webeditionsample_gpstogooglemap_cs_100108.zip.txt · Last modified: 2015/09/09 03:37 by admin