void timer_Tick(object sender, EventArgs e) { //Gets the GPS info from the textfile. DataTable carData = GetCarData(); float angleOffset; double angle; LayerOverlay dynamicOverlay = (LayerOverlay)winformsMap1.Overlays["DynamicOverlay"]; InMemoryFeatureLayer inMemoryFeatureLayer = (InMemoryFeatureLayer)dynamicOverlay.Layers["CarLayer"]; //InMemoryFeatureLayer labelInMemoryFeatureLayer = (InMemoryFeatureLayer)dynamicOverlay.Layers["CarLabel"]; PointShape pointShape = inMemoryFeatureLayer.InternalFeatures[0].GetShape() as PointShape; // Get the Row of Data we are working with. DataRow carDataRow = carData.Rows[0]; double Lat = Convert.ToDouble(carDataRow["LAT"]); double Long = Convert.ToDouble(carDataRow["LONG"]); //Gets the angle based on the current GPS position and the previous one to get the direction of the vehicle. angle = GetAngleFromTwoVertices(new Vertex(previousLong, previousLat), new Vertex(Long, Lat)); //Gets the correct icon depending on the direction of the vehicle. if (previousLong < Long) { inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.Image = carGeoImageDown; angleOffset = 180; } else { inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.Image = carGeoImageUp; angleOffset = 360; } inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.RotationAngle = angleOffset - (float)angle; pointShape.X = Long; pointShape.Y = Lat; pointShape.Id = "Car"; //Updates the column "VehiclePosition" of the feature to the current Longitude/Latitude. Feature feature = inMemoryFeatureLayer.InternalFeatures[0]; feature.ColumnValues["VehiclePosition"] = DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegreePoint(pointShape); //Updates the PointShape of the Feature. inMemoryFeatureLayer.Open(); inMemoryFeatureLayer.EditTools.BeginTransaction(); inMemoryFeatureLayer.EditTools.Update(pointShape); inMemoryFeatureLayer.EditTools.CommitTransaction(); inMemoryFeatureLayer.Close(); previousLong = Long; previousLat = Lat; winformsMap1.Refresh(dynamicOverlay); }
private void ShowCoordinate(MouseEventArgs e) { PointShape WorldPointR = ExtentHelper.ToWorldCoordinate(winformsMap1.CurrentExtent, e.X, e.Y, winformsMap1.Width, winformsMap1.Height); statusStrip.Items[1].Text = string.Format(CultureInfo.InvariantCulture, "X: {0:F4} Y: {1:F4}", WorldPointR.X, WorldPointR.Y); statusStrip.Items[2].Text = string.Format(CultureInfo.InvariantCulture, "X: {0} Y: {1}", e.X, e.Y); if (winformsMap1.MapUnit == GeographyUnit.DecimalDegree && ((WorldPointR.X > -180 && WorldPointR.X < 180 && WorldPointR.Y > -90 && WorldPointR.Y < 90))) { statusStrip.Items[0].Text = DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegreePoint(WorldPointR); return; } statusStrip.Items[0].Text = ""; }
private void TestForm_Load(object sender, EventArgs e) { winformsMap1.MapUnit = GeographyUnit.Meter; winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.FromArgb(255, 198, 255, 255)); GoogleMapsOverlay googleOverlay = new GoogleMapsOverlay(); //(@"Insert your key here!", @"C:\GoogleCache"); googleOverlay.MapType = GoogleMapsMapType.Terrain; winformsMap1.Overlays.Add(googleOverlay); // This sets the zoom levels to map to Googles. We next make sure we snap to the zoomlevels winformsMap1.ZoomLevelSet = new GoogleMapsZoomLevelSet(); 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 pointOverlay = new LayerOverlay(); pointOverlay.Layers.Add("PointLayer", pointLayer); winformsMap1.Overlays.Add("PointOverlay", pointOverlay); //Sets the extend of the map based on the GPS point. proj4.Open(); Vertex projVertex = proj4.ConvertToExternalProjection(Longitude, Latitude); proj4.Close(); double extendWidth = 2300; double extendHeight = 1200; winformsMap1.CurrentExtent = new RectangleShape((projVertex.X - extendWidth), (projVertex.Y + extendHeight), (projVertex.X + extendWidth), (projVertex.Y - extendHeight)); winformsMap1.Refresh(); }