Exemplo n.º 1
0
        private void TestForm_Load(object sender, EventArgs e)
        {
            //Sets timers properties.
            timer.Interval = 800;
            timer.Tick    += new EventHandler(timer_Tick);


            winformsMap1.MapUnit       = GeographyUnit.DecimalDegree;
            winformsMap1.CurrentExtent = new RectangleShape(-97.7591, 30.3126, -97.7317, 30.2964);
            winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.FromArgb(255, 198, 255, 255));

            //Displays the World Map Kit as a background.
            ThinkGeo.MapSuite.DesktopEdition.WorldMapKitWmsDesktopOverlay worldMapKitDesktopOverlay = new ThinkGeo.MapSuite.DesktopEdition.WorldMapKitWmsDesktopOverlay();
            winformsMap1.Overlays.Add(worldMapKitDesktopOverlay);

            //InMemoryFeatureLayer for vehicle.
            InMemoryFeatureLayer carLayer = new InMemoryFeatureLayer();

            carLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.PointType     = PointType.Bitmap;
            carLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.Image         = new GeoImage(@"..\..\data\sedan.png");
            carLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.RotationAngle = 45;
            carLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel             = ApplyUntilZoomLevel.Level20;
            carLayer.InternalFeatures.Add("Car", new Feature(new PointShape()));

            LayerOverlay vehicleOverlay = new LayerOverlay();

            vehicleOverlay.Layers.Add("CarLayer", carLayer);
            winformsMap1.Overlays.Add("VehicleOverlay", vehicleOverlay);

            //InMemoryFeatureLayer for Tolerance RectangleShape. (Displayed for the purpose of the project. It does not need to be displayed for a real world application)
            InMemoryFeatureLayer toleranceLayer = new InMemoryFeatureLayer();

            toleranceLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle    = AreaStyles.CreateSimpleAreaStyle(GeoColor.StandardColors.Transparent, GeoColor.StandardColors.Green, 2);
            toleranceLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            //Uses a Rectangle 60% smaller than the current extent of the map for the tolerance.
            RectangleShape toleranceRectangleShape = new RectangleShape(winformsMap1.CurrentExtent.UpperLeftPoint, winformsMap1.CurrentExtent.LowerRightPoint);

            toleranceRectangleShape.ScaleDown(60);

            toleranceLayer.InternalFeatures.Add("Tolerance", new Feature(toleranceRectangleShape));

            LayerOverlay toleranceOverlay = new LayerOverlay();

            toleranceOverlay.Layers.Add("ToleranceLayer", toleranceLayer);
            winformsMap1.Overlays.Add("ToleranceOverlay", toleranceOverlay);


            winformsMap1.Refresh();

            timer.Start();
        }
        protected override void DrawSampleCore(GeoCanvas canvas, DrawingRectangleF drawingExtent)
        {
            base.DrawSampleCore(canvas, drawingExtent);
            PointShape upperLeftPoint = ExtentHelper.ToWorldCoordinate(canvas.CurrentWorldExtent, drawingExtent.CenterX - drawingExtent.Width / 2, drawingExtent.CenterY - drawingExtent.Height / 2, canvas.Width, canvas.Height);
            PointShape lowerRightPoint = ExtentHelper.ToWorldCoordinate(canvas.CurrentWorldExtent, drawingExtent.CenterX + drawingExtent.Width / 2, drawingExtent.CenterY + drawingExtent.Height / 2, canvas.Width, canvas.Height);
            RectangleShape rectangle = new RectangleShape(upperLeftPoint, lowerRightPoint);
            rectangle.ScaleDown(10);

            // Here draw the points on Legend Image
            Random random = new Random(DateTime.Now.Millisecond);
            Collection<BaseShape> drawingPoints = new Collection<BaseShape>();
            for (int i = 0; i < DrawingPointsNumber; i++)
            {
                double x = rectangle.LowerLeftPoint.X + random.NextDouble() * (rectangle.Width);
                double y = rectangle.LowerLeftPoint.Y + random.NextDouble() * (rectangle.Height);
                drawingPoints.Add(new PointShape(x, y));
            }
            TextStyle textStyle = new TextStyle(DrawingPointsNumber.ToString(), new GeoFont("Arial", 20, DrawingFontStyles.Bold), new GeoSolidBrush(GeoColor.FromArgb(180, GeoColor.FromHtml("#d3d3d3"))));
            textStyle.DrawSample(canvas, drawingExtent);
            CustomPointStyle.Draw(drawingPoints, canvas, new Collection<SimpleCandidate>(), new Collection<SimpleCandidate>());
        }
Exemplo n.º 3
0
        protected override void DrawCore(GeoCanvas canvas, Collection <SimpleCandidate> labelsInAllLayers)
        {
            GeoImage       miniImage         = new GeoImage(width, height);
            RectangleShape scaledWorldExtent = MapEngine.GetDrawingExtent(canvas.CurrentWorldExtent, width, height);

            scaledWorldExtent.ScaleUp(300);
            GdiPlusGeoCanvas minCanvas = new GdiPlusGeoCanvas();

            minCanvas.BeginDrawing(miniImage, scaledWorldExtent, canvas.MapUnit);
            foreach (Layer layer in layers)
            {
                layer.Draw(minCanvas, labelsInAllLayers);
            }

            minCanvas.DrawArea(RectangleShape.ScaleDown(minCanvas.CurrentWorldExtent, 1), new GeoPen(GeoColor.StandardColors.Gray, 2), DrawingLevel.LevelOne);
            minCanvas.DrawArea(canvas.CurrentWorldExtent, new GeoPen(GeoColor.StandardColors.Black, 2), DrawingLevel.LevelOne);

            minCanvas.EndDrawing();

            ScreenPointF drawingLocation = GetDrawingLocation(canvas, width, height);

            canvas.DrawScreenImageWithoutScaling(miniImage, (drawingLocation.X + width / 2) + 10, (drawingLocation.Y + height / 2) - 10, DrawingLevel.LevelOne, 0, 0, 0);
        }
Exemplo n.º 4
0
        protected override void DrawSampleCore(GeoCanvas canvas, DrawingRectangleF drawingExtent)
        {
            base.DrawSampleCore(canvas, drawingExtent);
            PointShape     upperLeftPoint  = ExtentHelper.ToWorldCoordinate(canvas.CurrentWorldExtent, drawingExtent.CenterX - drawingExtent.Width / 2, drawingExtent.CenterY - drawingExtent.Height / 2, canvas.Width, canvas.Height);
            PointShape     lowerRightPoint = ExtentHelper.ToWorldCoordinate(canvas.CurrentWorldExtent, drawingExtent.CenterX + drawingExtent.Width / 2, drawingExtent.CenterY + drawingExtent.Height / 2, canvas.Width, canvas.Height);
            RectangleShape rectangle       = new RectangleShape(upperLeftPoint, lowerRightPoint);

            rectangle.ScaleDown(10);

            // Here draw the points on Legend Image
            Random random = new Random(DateTime.Now.Millisecond);
            Collection <BaseShape> drawingPoints = new Collection <BaseShape>();

            for (int i = 0; i < DrawingPointsNumber; i++)
            {
                double x = rectangle.LowerLeftPoint.X + random.NextDouble() * (rectangle.Width);
                double y = rectangle.LowerLeftPoint.Y + random.NextDouble() * (rectangle.Height);
                drawingPoints.Add(new PointShape(x, y));
            }
            TextStyle textStyle = new TextStyle(DrawingPointsNumber.ToString(), new GeoFont("Arial", 20, DrawingFontStyles.Bold), new GeoSolidBrush(GeoColor.FromArgb(180, GeoColor.FromHtml("#d3d3d3"))));

            textStyle.DrawSample(canvas, drawingExtent);
            CustomPointStyle.Draw(drawingPoints, canvas, new Collection <SimpleCandidate>(), new Collection <SimpleCandidate>());
        }
Exemplo n.º 5
0
        void timer_Tick(object sender, EventArgs e)
        {
            //Gets the GPS info from the textfile.
            DataTable carData = GetCarData();

            double               angle;
            LayerOverlay         vehicleOverlay = (LayerOverlay)winformsMap1.Overlays["VehicleOverlay"];
            InMemoryFeatureLayer carLayer       = vehicleOverlay.Layers["CarLayer"] as InMemoryFeatureLayer;

            PointShape pointShape = carLayer.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"]);

            if (previousLong == 0)
            {
                previousLong = Long;
                previousLat  = Lat;
            }

            double Xdiff = previousLong - Long;
            double Ydiff = previousLat - Lat;

            //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));

            carLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.RotationAngle = 90 - (float)angle;

            pointShape.X  = Long;
            pointShape.Y  = Lat;
            pointShape.Id = "Car";

            carLayer.Open();
            carLayer.EditTools.BeginTransaction();
            carLayer.EditTools.Update(pointShape);
            carLayer.EditTools.CommitTransaction();
            carLayer.Close();

            previousLong = Long;
            previousLat  = Lat;

            //Function to center the map to a point (the moving moving vehicle feature)if it goes outside the tolerance.
            RectangleShape toleranceRectangleShape = new RectangleShape(winformsMap1.CurrentExtent.UpperLeftPoint, winformsMap1.CurrentExtent.LowerRightPoint);

            toleranceRectangleShape.ScaleDown(60);
            if (toleranceRectangleShape.Contains(new PointShape(Long, Lat)) == false)
            {
                winformsMap1.CenterAt(new PointShape(Long, Lat));

                //Resets the RectangleShape of the tolerance layer (for displaying only)
                LayerOverlay         toleranceOverlay = (LayerOverlay)winformsMap1.Overlays["ToleranceOverlay"];
                InMemoryFeatureLayer toleranceLayer   = toleranceOverlay.Layers["ToleranceLayer"] as InMemoryFeatureLayer;

                RectangleShape newToleranceRectangleShape = new RectangleShape(winformsMap1.CurrentExtent.UpperLeftPoint, winformsMap1.CurrentExtent.LowerRightPoint);
                newToleranceRectangleShape.ScaleDown(60);
                newToleranceRectangleShape.Id = "Tolerance";

                toleranceLayer.Open();
                toleranceLayer.EditTools.BeginTransaction();
                toleranceLayer.EditTools.Update(newToleranceRectangleShape);
                toleranceLayer.EditTools.CommitTransaction();
                toleranceLayer.Close();

                winformsMap1.Refresh();
            }
            else
            {
                winformsMap1.Refresh(vehicleOverlay);
            }
        }