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.Globalization; using System.Configuration; using System.Collections.ObjectModel; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.WebEdition; namespace DetectGPS { public partial class TestForm : System.Web.UI.Page { Collection<PointShape> GPSlocations = new Collection<PointShape>(); int index; WebImage webImage = null; WebImage webImage2 = null; protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF")); Map1.CurrentExtent = new RectangleShape(-95.3018,38.9647,-95.2818,38.9534); Map1.MapUnit = GeographyUnit.DecimalDegree; WorldMapKitWmsWebOverlay overlay = new WorldMapKitWmsWebOverlay(); Map1.CustomOverlays.Add(overlay); //InMemoryFeatureLayer for the two reference points en red. InMemoryFeatureLayer pointLayer = new InMemoryFeatureLayer(); pointLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimpleCircleStyle(GeoColor.StandardColors.Red, 12, GeoColor.StandardColors.Black); pointLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; Feature feature1 = new Feature(new PointShape(-95.2949, 38.957)); Feature feature2 = new Feature(new PointShape(-95.2883, 38.957)); pointLayer.InternalFeatures.Add(feature1); pointLayer.InternalFeatures.Add(feature2); LayerOverlay pointOverlay = new LayerOverlay("PointOverlay"); pointOverlay.Layers.Add("PointLayer", pointLayer); pointOverlay.IsBaseOverlay = false; Map1.CustomOverlays.Add(pointOverlay); //Collection of PointShapes for the GPS locations. GPSlocations.Add(new PointShape(-95.2946, 38.9602)); GPSlocations.Add(new PointShape(-95.2928, 38.9602)); GPSlocations.Add(new PointShape( -95.2903,38.9602)); GPSlocations.Add(new PointShape(-95.2883,38.9602)); GPSlocations.Add(new PointShape(-95.2883,38.9587)); GPSlocations.Add(new PointShape(-95.2883,38.957)); GPSlocations.Add(new PointShape(-95.2897,38.957)); GPSlocations.Add(new PointShape(-95.2918,38.957)); GPSlocations.Add(new PointShape(-95.2934,38.957)); GPSlocations.Add(new PointShape(-95.2947,38.957)); GPSlocations.Add(new PointShape(-95.2946,38.9582)); GPSlocations.Add(new PointShape(-95.2946,38.9593)); //SimpleMarkerOverlay for autorefresh GPS locations SimpleMarkerOverlay markerOverlay = new SimpleMarkerOverlay("MarkerOverlay"); markerOverlay.AutoRefreshInterval = TimeSpan.FromMilliseconds(1000); markerOverlay.Tick += new EventHandler<EventArgs>(markerOverlay_Tick); webImage = new WebImage("/Images/top.png"); webImage2 = new WebImage("/Images/top2.png"); markerOverlay.Markers.Add(new Marker(new PointShape(-95.2946, 38.9602), webImage)); Map1.CustomOverlays.Add(markerOverlay); } } void markerOverlay_Tick(object sender, EventArgs e) { if (index == GPSlocations.Count - 1) { index = 0; } else { index = index + 1; } LayerOverlay pointOverlay = (LayerOverlay)Map1.CustomOverlays["PointOverlay"]; InMemoryFeatureLayer pointLayer = (InMemoryFeatureLayer)pointOverlay.Layers["PointLayer"]; SimpleMarkerOverlay markerOverlay = (SimpleMarkerOverlay)Map1.CustomOverlays["MarkerOverlay"]; double lon = GPSlocations[index].X; double lat = GPSlocations[index].Y; markerOverlay.Markers[0].Position = new PointShape(lon, lat); //If the new GPS location is within 200 meters of a reference point, it displays with a different icon. pointLayer.Open(); Collection<Feature> features = pointLayer.QueryTools.GetFeaturesWithinDistanceOf(new PointShape(lon, lat), Map1.MapUnit, DistanceUnit.Meter, 200, ReturningColumnsType.NoColumns); pointLayer.Close(); if (features.Count > 0) { markerOverlay.Markers[0].WebImage = webImage2; } else { markerOverlay.Markers[0].WebImage = webImage; } } } }
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestForm.aspx.cs" Inherits="DetectGPS.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>Detect GPS</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>