Inheritance: GMarkerGoogle
Exemplo n.º 1
0
Arquivo: GCS.cs Projeto: kkouer/PcGcs
        /// <summary>
        /// used to add a marker to the map display
        /// </summary>
        /// <param name="tag"></param>
        /// <param name="lng"></param>
        /// <param name="lat"></param>
        /// <param name="alt"></param>
        private void addpolygonmarker(string tag, double lng, double lat, int alt, Color? color)
        {
            try
            {
                PointLatLng point = new PointLatLng(lat, lng);
                GMapMarkerWP m = new GMapMarkerWP(point, tag);
                m.ToolTipMode = MarkerTooltipMode.OnMouseOver;
                m.ToolTipText = "高度: " + alt.ToString("0");
                m.Tag = tag;

                try
                {
                    // preselect groupmarker
                    if (groupmarkers.Count > 0)
                        if (groupmarkers.Contains(int.Parse(tag)))
                            m.selected = true;
                }
                catch { }

                //MissionPlanner.GMapMarkerRectWPRad mBorders = new MissionPlanner.GMapMarkerRectWPRad(point, (int)float.Parse(TXT_WPRad.Text), MainMap);
                GMapMarkerRect mBorders = new GMapMarkerRect(point);
                {
                    mBorders.InnerMarker = m;
                    mBorders.Tag = tag;

                    //隐藏到达航点半径
                    //mBorders.wprad = (int)(float.Parse(TXT_WPRad.Text) / CurrentState.multiplierdist);
                    if (color.HasValue)
                    {
                        mBorders.Color = color.Value;
                    }
                }

                objectsoverlay.Markers.Add(m);
                objectsoverlay.Markers.Add(mBorders);
            }
            catch (Exception) { }
        }
Exemplo n.º 2
0
        // Do Work
        private void domainUpDown1_ValueChanged(object sender, EventArgs e)
        {
            if (CMB_camera.Text != "" && sender != NUM_Distance)
                doCalc();

            // new grid system test

            grid = Grid.CreateGrid(list, CurrentState.fromDistDisplayUnit((double)NUM_altitude.Value), (double)NUM_Distance.Value, (double)NUM_spacing.Value, (double)NUM_angle.Value, (double)NUM_overshoot.Value, (double)NUM_overshoot2.Value, (Grid.StartPosition)Enum.Parse(typeof(Grid.StartPosition), CMB_startfrom.Text), false, (float)NUM_Lane_Dist.Value, (float)NUM_leadin.Value);

            List<PointLatLng> list2 = new List<PointLatLng>();

            grid.ForEach(x => { list2.Add(x); });

            map.HoldInvalidation = true;

            routesOverlay.Routes.Clear();
            routesOverlay.Polygons.Clear();
            routesOverlay.Markers.Clear();

            if (grid.Count == 0)
            {
                return;
            }

            if (CHK_boundary.Checked)
                AddDrawPolygon();

            int strips = 0;
            int images = 0;
            int a = 1;
            PointLatLngAlt prevpoint = grid[0];
            float routetotal = 0;
            List<PointLatLng> segment = new List<PointLatLng>();

            foreach (var item in grid)
            {
                if (item.Tag == "M")
                {
                    images++;

                    if (CHK_internals.Checked)
                    {
                        routesOverlay.Markers.Add(new GMarkerGoogle(item, GMarkerGoogleType.green) { ToolTipText = a.ToString(), ToolTipMode = MarkerTooltipMode.OnMouseOver });
                        a++;

                        segment.Add(prevpoint);
                        segment.Add(item);
                        prevpoint = item;
                    }
                    try
                    {
                        if (TXT_fovH.Text != "")
                        {
                            double fovh = double.Parse(TXT_fovH.Text);
                            double fovv = double.Parse(TXT_fovV.Text);

                            double startangle = 0;

                            if (!CHK_camdirection.Checked)
                            {
                                startangle = 90;
                            }

                            double angle1 = startangle - (Math.Tan((fovv / 2.0) / (fovh / 2.0)) * rad2deg);
                            double dist1 = Math.Sqrt(Math.Pow(fovh / 2.0, 2) + Math.Pow(fovv / 2.0, 2));

                            double bearing = (double)NUM_angle.Value;// (prevpoint.GetBearing(item) + 360.0) % 360;

                            List<PointLatLng> footprint = new List<PointLatLng>();
                            footprint.Add(item.newpos(bearing + angle1, dist1));
                            footprint.Add(item.newpos(bearing + 180 - angle1, dist1));
                            footprint.Add(item.newpos(bearing + 180 + angle1, dist1));
                            footprint.Add(item.newpos(bearing - angle1, dist1));

                            GMapPolygon poly = new GMapPolygon(footprint, a.ToString());
                            poly.Stroke = new Pen(Color.FromArgb(250 - ((a * 5) % 240), 250 - ((a * 3) % 240), 250 - ((a * 9) % 240)), 1);
                            poly.Fill = new SolidBrush(Color.FromArgb(40, Color.Purple));
                            if (CHK_footprints.Checked)
                                routesOverlay.Polygons.Add(poly);
                        }
                    }
                    catch { }
                }
                else
                {
                    strips++;
                    if (CHK_markers.Checked)
                    {
                        var marker = new GMapMarkerWP(item, a.ToString()) { ToolTipText = a.ToString(), ToolTipMode = MarkerTooltipMode.OnMouseOver };
                        routesOverlay.Markers.Add(marker);
                    }

                    segment.Add(prevpoint);
                    segment.Add(item);
                    prevpoint = item;
                    a++;
                }
                GMapRoute seg = new GMapRoute(segment, "segment" + a.ToString());
                seg.Stroke = new Pen(Color.Yellow, 4);
                seg.Stroke.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom;
                seg.IsHitTestVisible = true;
                if (CHK_grid.Checked)
                    routesOverlay.Routes.Add(seg);
                routetotal = routetotal + (float)seg.Distance;
                segment.Clear();
            }

            /*      Old way of drawing route, incase something breaks using segments
            GMapRoute wproute = new GMapRoute(list2, "GridRoute");
            wproute.Stroke = new Pen(Color.Yellow, 4);
            if (chk_grid.Checked)
                routesOverlay.Routes.Add(wproute);
            */

            // turn radrad = tas^2 / (tan(angle) * G)
            float v_sq = (float)(((float)NUM_UpDownFlySpeed.Value / CurrentState.multiplierspeed) * ((float)NUM_UpDownFlySpeed.Value / CurrentState.multiplierspeed));
            float turnrad = (float)(v_sq / (float)(9.808f * Math.Tan(35 * deg2rad)));

            // Update Stats 
            if (DistUnits == "Feet")
            {
                // Area
                float area = (float)calcpolygonarea(list) * 10.7639f; // Calculate the area in square feet
                lbl_area.Text = area.ToString("#") + " ft^2";
                if (area < 21780f)
                {
                    lbl_area.Text = area.ToString("#") + " ft^2";
                }
                else
                {
                    area = area / 43560f;
                    if (area < 640f)
                    {
                        lbl_area.Text = area.ToString("0.##") + " acres";
                    }
                    else
                    {
                        area = area / 640f;
                        lbl_area.Text = area.ToString("0.##") + " miles^2";
                    }
                }

                // Distance
                float distance = routetotal * 3280.84f; // Calculate the distance in feet
                if (distance < 5280f)
                {
                    lbl_distance.Text = distance.ToString("#") + " ft";
                }
                else
                {
                    distance = distance / 5280f;
                    lbl_distance.Text = distance.ToString("0.##") + " miles";
                }

                lbl_spacing.Text = (NUM_spacing.Value * 3.2808399m).ToString("#") + " ft";
                lbl_grndres.Text = inchpixel;
                lbl_distbetweenlines.Text = (NUM_Distance.Value * 3.2808399m).ToString("0.##") + " ft";
                lbl_footprint.Text = feet_fovH + " x " + feet_fovV + " ft";
                lbl_turnrad.Text = (turnrad * 2 * 3.2808399).ToString("0") + " ft";
            }
            else
            {
                // Meters
                lbl_area.Text = calcpolygonarea(list).ToString("#") + " m^2";
                lbl_distance.Text = routetotal.ToString("0.##") + " km";
                lbl_spacing.Text = NUM_spacing.Value.ToString("#") + " m";
                lbl_grndres.Text = TXT_cmpixel.Text;
                lbl_distbetweenlines.Text = NUM_Distance.Value.ToString("0.##") + " m";
                lbl_footprint.Text = TXT_fovH.Text + " x " + TXT_fovV.Text + " m";
                lbl_turnrad.Text = (turnrad * 2).ToString("0") + " m";
            }

            double flyspeedms = CurrentState.fromSpeedDisplayUnit((double)NUM_UpDownFlySpeed.Value);

            lbl_pictures.Text = images.ToString();
            lbl_strips.Text = ((int)(strips / 2)).ToString();
            double seconds = ((routetotal * 1000.0) / ((flyspeedms) * 0.8));
            // reduce flying speed by 20 %
            lbl_flighttime.Text = secondsToNice(seconds);
            seconds = ((routetotal * 1000.0) / (flyspeedms));
            lbl_photoevery.Text = secondsToNice(((double)NUM_spacing.Value / flyspeedms));
            map.HoldInvalidation = false;
            if (!isMouseDown)
                map.ZoomAndCenterMarkers("routes");

            CalcHeadingHold();
        }
Exemplo n.º 3
0
        CurrentState c = new MissionPlanner.CurrentState(); //reference or instance so that HomeBase is actually home now, not a WP
        // Do Work
        private void domainUpDown1_ValueChanged(object sender, EventArgs e)
        {
            myGrid.Clear();         //reset the elements in myGrid because it'll be a new version since this function was called again

            if (CHK_usespeed.Checked)    //if the use speed box is checked
            {         //if user unchecks the box, the same speed that was previously there will be used, not the default 5 m/s
                speed = (double)NUM_UpDownFlySpeed.Value;
                maxFlightDist = ((double)maxFlight.Value * 60) * (speed / 1000);
            }

            if (CMB_camera.Text != "")
                    doCalc();

            // new grid system test

            grid = Grid.CreateGrid(list, CurrentState.fromDistDisplayUnit((double)NUM_altitude.Value), 
                (double)NUM_Distance.Value, (double)NUM_spacing.Value, (double)NUM_angle.Value, 
                (double)NUM_overshoot.Value, (double)NUM_overshoot2.Value, 
                (Grid.StartPosition)Enum.Parse(typeof(Grid.StartPosition), CMB_startfrom.Text), 
                false, (float)NUM_Lane_Dist.Value, (float)NUM_leadin.Value);

            List<PointLatLng> list2 = new List<PointLatLng>(); //not really sure what this number is because
                                                               //doesn't seem like the numberflight path points
            grid.ForEach(x => { list2.Add(x); });              //adds the number of WPs to list two

            map.HoldInvalidation = true;
            //below is clearing everything on the map I think
            routesOverlay.Routes.Clear();
            routesOverlay.Polygons.Clear();
            routesOverlay.Markers.Clear();

            if (grid.Count == 0)    //if there is nothing to plot on the map
            {
                return;
            }

            if (CHK_boundary.Checked)
                AddDrawPolygon();

            int strips = 0;
            int images = 0;
            int a = 1;
            PointLatLngAlt prevpoint = grid[0];
            float routetotal = 0;
            float renewedRouteTotal = 0;                                //I added this temp variable
            List<PointLatLng> segment = new List<PointLatLng>();        //list of the WPs to add to the map
            List<PointLatLng> segmentHome = new List<PointLatLng>();    //list of the WP from end of segment back to home
            List<PointLatLng> segmentNext = new List<PointLatLng>();    //list of the WP for the next segment
            GMapRoute seg;      //I added this
            GMapRoute segHome;  //I added this too as a test variable to get dist from current point to home
            GMapRoute segNext;  //I added this too as a test variable to get dist for the next segment
            PointLatLngAlt homeBaseBegin = c.HomeLocation;   // grid[0];    //stores the very first point       && I added this
            c.HomeLocation.Tag = "Home";                     //creating the home tag
            int backHomeLines = 0;      //going to be used for debugging
            double distance1 = 0;

            //I added so that I could see the home base in the beginning
            var marker = new GMapMarkerWP(homeBaseBegin, "H") { ToolTipText = a.ToString(), ToolTipMode = MarkerTooltipMode.OnMouseOver };
            routesOverlay.Markers.Add(marker);  //adds a H marker for home

            for (int i = 0; i < grid.Count; i++)
            {
                if (grid[i].Tag == "M")         //I think that this if statement just places down all of the markers we use for the segments
                {
                    images++;

                    if (CHK_internals.Checked)
                    {
                        routesOverlay.Markers.Add(new GMarkerGoogle(grid[i], GMarkerGoogleType.green) { ToolTipText = a.ToString(), ToolTipMode = MarkerTooltipMode.OnMouseOver });
                        a++;

                        segment.Add(prevpoint);
                        segment.Add(grid[i]);
                        prevpoint = grid[i];
                    }
                    try
                    {
                        if (TXT_fovH.Text != "")
                        {
                            double fovh = double.Parse(TXT_fovH.Text);
                            double fovv = double.Parse(TXT_fovV.Text);

                            double startangle = 0;

                            if (!CHK_camdirection.Checked)
                            {
                                startangle = 90;
                            }

                            double angle1 = startangle - (Math.Tan((fovv / 2.0) / (fovh / 2.0)) * rad2deg);
                            double dist1 = Math.Sqrt(Math.Pow(fovh / 2.0, 2) + Math.Pow(fovv / 2.0, 2));

                            double bearing = (double)NUM_angle.Value;// (prevpoint.GetBearing(item) + 360.0) % 360;

                            List<PointLatLng> footprint = new List<PointLatLng>();
                            footprint.Add(grid[i].newpos(bearing + angle1, dist1));
                            footprint.Add(grid[i].newpos(bearing + 180 - angle1, dist1));
                            footprint.Add(grid[i].newpos(bearing + 180 + angle1, dist1));
                            footprint.Add(grid[i].newpos(bearing - angle1, dist1));

                            GMapPolygon poly = new GMapPolygon(footprint, i.ToString());
                            poly.Stroke = new Pen(Color.FromArgb(250 - ((a * 5) % 240), 250 - ((a * 3) % 240), 250 - ((a * 9) % 240)), 1);
                            poly.Fill = new SolidBrush(Color.FromArgb(40, Color.Purple));
                            if (CHK_footprints.Checked)
                                routesOverlay.Polygons.Add(poly);
                        }
                    }
                    catch { }
                }
                else
                {   
                    strips++;                                   //number of line strips to connect the WPs
                    if (CHK_markers.Checked)
                    {
                        marker = new GMapMarkerWP(grid[i], a.ToString()) { ToolTipText = a.ToString(), ToolTipMode = MarkerTooltipMode.OnMouseOver };
                        routesOverlay.Markers.Add(marker);      //adding new WPs to the map to fill the Polygon Points in
                    }
                    
                    //below is only run when the drone needs to go back home
                    if (distance1 >= maxFlightDist)  //should be updated when the Max Flight Dist NumUpDown is changed
                    {   //need to check if the drone can make it to both the next WP and back home before the routetotal is 10 hectares
                        createMyGridList(i);        //creates a new list for me to manipulate only when need to return home for recharge

                        backHomeLines++;            //increment every time drone goes back home
                        segment.Add(prevpoint);     //whatever beginning point the drone was at previously
                        segment.Add(homeBaseBegin); //telling the drone to go back to home
                        renewedRouteTotal = 0;      //reset this variable

                        //making the segment for this point to home segment
                        seg = new GMapRoute(segment, "segment" + a.ToString());     //I modified this from the above line && commented out
                        seg.Stroke = new Pen(Color.Yellow, 4);
                        seg.Stroke.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom;
                        seg.IsHitTestVisible = true;
                        if (CHK_grid.Checked)
                            routesOverlay.Routes.Add(seg);
                        routetotal = routetotal + (float)seg.Distance;      //routetotal is the summation of the total flight distance
                        segment.Clear();

                        //point going from home back to the point we left off
                        segment.Add(homeBaseBegin);
                        segment.Add(prevpoint);       //grid[i] should be at the same WP point right now
                        seg = new GMapRoute(segment, "segment" + a.ToString());
                        seg.Stroke = new Pen(Color.Yellow, 4);
                        seg.Stroke.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom;
                        seg.IsHitTestVisible = true;
                        if (CHK_grid.Checked)
                            routesOverlay.Routes.Add(seg);
                        routetotal = routetotal + (float)seg.Distance;
                        renewedRouteTotal = renewedRouteTotal + (float)seg.Distance;    //stores the distance from home to point

                        segment.Clear();
                     }

                     segment.Add(prevpoint);     //adding the beginning points of the line segment to output onto the map
                     segment.Add(grid[i]);       //ending point of line segment
                     prevpoint = grid[i];        //new beginning point for next time around the loop       moved below at the end
                     a++;
                }
                seg = new GMapRoute(segment, "segment" + a.ToString());     //I modified this from the above line && commented out
                seg.Stroke = new Pen(Color.Navy, 4);                        //changed base segment color
                seg.Stroke.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom;
                seg.IsHitTestVisible = true;
                if (CHK_grid.Checked)
                    routesOverlay.Routes.Add(seg);
                routetotal = routetotal + (float)seg.Distance;      //routetotal is the summation of the total flight distance
                renewedRouteTotal = renewedRouteTotal + (float)seg.Distance; //temporary routetotal to clear upon landing
                segment.Clear();

                if (i + 1 < grid.Count)
                {
                    segmentHome.Add(grid[i + 1]);     //this should be the new segment from the next point to home
                }
                if (i + 1 > grid.Count)
                {
                    segmentHome.Add(grid[grid.Count - 2]);  //last point in the grid
                }
                if (i + 1 == grid.Count)
                {
                    segmentHome.Add(grid[grid.Count - 1]);  //last point in the grid
                }
                segmentHome.Add(homeBaseBegin);       //used to calculate the distance from point to home below
                segHome = new GMapRoute(segmentHome, "segment home" + a.ToString());

                if (i + 1 < grid.Count)
                {
                    segmentNext.Add(prevpoint);       //used to calculate the distance from point to home below
                    segmentNext.Add(grid[i + 1]);     //this should be the new segment from point to home
                }
                else
                {
                    segmentNext.Add(prevpoint);     //two of the same points should give
                    segmentNext.Add(prevpoint);     //a distance of 0 since there is no next point left
                }
                segNext = new GMapRoute(segmentNext, "segment next" + a.ToString());

                distance1 = renewedRouteTotal + segNext.Distance + segHome.Distance;    //need to get seg.Distance of next segment
                segmentHome.Clear();
                segmentNext.Clear();
            }

            double numShouldReturnHome = routetotal / maxFlightDist;

            /*      Old way of drawing route, incase something breaks using segments
            GMapRoute wproute = new GMapRoute(list2, "GridRoute");
            wproute.Stroke = new Pen(Color.Yellow, 4);
            if (chk_grid.Checked)
                routesOverlay.Routes.Add(wproute);
            */

            // turn radrad = tas^2 / (tan(angle) * G)
            float v_sq = (float)(((float)NUM_UpDownFlySpeed.Value / CurrentState.multiplierspeed) * ((float)NUM_UpDownFlySpeed.Value / CurrentState.multiplierspeed));
            float turnrad = (float)(v_sq / (float)(9.808f * Math.Tan(35 * deg2rad)));

            // Update Stats 
            if (DistUnits == "Feet")
            {
                // Area
                float area = (float)calcpolygonarea(list) * 10.7639f; // Calculate the area in square feet
                lbl_area.Text = area.ToString("#") + " ft^2";
                if (area < 21780f)
                {
                    lbl_area.Text = area.ToString("#") + " ft^2";
                }
                else
                {
                    area = area / 43560f;
                    if (area < 640f)
                    {
                        lbl_area.Text = area.ToString("0.##") + " acres";
                    }
                    else
                    {
                        area = area / 640f;
                        lbl_area.Text = area.ToString("0.##") + " miles^2";
                    }
                }

                // Distance
                float distance = routetotal * 3280.84f; // Calculate the distance in feet
                if (distance < 5280f)
                {
                    lbl_distance.Text = distance.ToString("#") + " ft";
                }
                else
                {
                    distance = distance / 5280f;
                    lbl_distance.Text = distance.ToString("0.##") + " miles";
                }

                lbl_spacing.Text = (NUM_spacing.Value * 3.2808399m).ToString("#") + " ft";
                lbl_grndres.Text = inchpixel;
                lbl_distbetweenlines.Text = (NUM_Distance.Value * 3.2808399m).ToString("0.##") + " ft";
                lbl_footprint.Text = feet_fovH + " x " + feet_fovV + " ft";
                lbl_turnrad.Text = (turnrad * 2 * 3.2808399).ToString("0") + " ft";
            }
            else
            {
                // Meters
                lbl_area.Text = calcpolygonarea(list).ToString("#") + " m^2";
                lbl_distance.Text = routetotal.ToString("0.##") + " km";
                lbl_spacing.Text = NUM_spacing.Value.ToString("#") + " m";
                lbl_grndres.Text = TXT_cmpixel.Text;
                lbl_distbetweenlines.Text = NUM_Distance.Value.ToString("0.##") + " m";
                lbl_footprint.Text = TXT_fovH.Text + " x " + TXT_fovV.Text + " m";
                lbl_turnrad.Text = (turnrad * 2).ToString("0") + " m";
                lbl_recharge.Text = backHomeLines.ToString();
                lbl_shouldrecharge.Text = numShouldReturnHome.ToString();

                if ((int)numShouldReturnHome > backHomeLines)
                {
                    CustomMessageBox.Show("Error! Bad grid! Need more flights back home. Drone will not complete mission. Move home base closer to survey area.");
                }
            }

            double flyspeedms = CurrentState.fromSpeedDisplayUnit(speed);

            lbl_pictures.Text = images.ToString();
            lbl_strips.Text = ((int)(strips / 2)).ToString();
            double seconds = ((routetotal * 1000.0) / ((flyspeedms) * 0.8));
            // reduce flying speed by 20 %
            lbl_flighttime.Text = secondsToNice(seconds);
            seconds = ((routetotal * 1000.0) / (flyspeedms));
            lbl_photoevery.Text = secondsToNice(((double)NUM_spacing.Value / flyspeedms));
            map.HoldInvalidation = false;
            if (!isMouseDown)
                map.ZoomAndCenterMarkers("routes");

            CalcHeadingHold();

            completeMyGridList();       //copies the remaining WPs over
        }