示例#1
0
 /*************************************************************/
 private void pointOverlay_MouseDown(object sender, MouseEventArgs e)
 {
     if (sender is PointMapMarker)
     {
         PointMapMarker selectedPoint = sender as PointMapMarker;
         if (this.m_editTrail != null)
         {
             if (e.Button == MouseButtons.Left ||
                 //Google Maps always reports button None
                 e.Button == MouseButtons.None)
             {
                 SetMovingWaypoint(selectedPoint);
                 //Save offset from click to marker reference
                 Point midPoint = MapControl.MapProjection.GPSToPixel(MapControl.MapBounds.NorthWest,
                                                                      MapControl.Zoom, selectedPoint.TrailPoint);
                 this.m_clickToCenterOffset = new Point(midPoint.X - e.Location.X, midPoint.Y - e.Location.Y);
             }
         }
         else
         {
             //TODO: Not working
             //toolTip.ShowAlways = true;
             //this.toolTip.Show(selectedPoint.TrailPoint.Name,MapControl.Control.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent, 2000);
         }
     }
 }
示例#2
0
        private void SetMovingWaypoint(PointMapMarker waypoint)
        {
            if (this.m_editTrail != null)
            {
                if (this._selectedPointMoving != null)
                {
                    if (this._selectedPointMoving != null &&
                        this._selectedPointOriginal != null)
                    {
                        //New selection before old finished - set old location back
                        this._selectedPointMoving.TrailPoint = this._selectedPointOriginal;
                        this.m_editTrail.UpdatePointFromMap(this._selectedPointMoving.TrailPoint);
                    }
                }

                if (waypoint != null)
                {
                    //Start - offset saved separately
                    this._selectedPointOriginal = waypoint.TrailPoint;

                    this._selectedPointMoving = waypoint;
                    this.m_editTrail.UpdatePointFromMap(this._selectedPointMoving.TrailPoint);
                    this.MapControl.CanMouseDrag = false;
                }
                else
                {
                    //End or cancel
                    this._selectedPointMoving    = null;
                    this._selectedPointOriginal  = null;
                    this.MapControl.CanMouseDrag = true;
                    this.RefreshOverlays(true);
                }
            }
        }
示例#3
0
        private void RefreshOverlays(bool clear)
        {
            if (clear || MapControlChanged)
            {
                ClearOverlays();
                ResetMapControl();
            }

            if (!m_showPage)
            {
                return;
            }

            IGPSBounds          windowBounds  = MapControlBounds;
            IList <IMapOverlay> addedOverlays = new List <IMapOverlay>();

            //RouteOverlay
            //Only add a route exactly once, prefer marked routes
            IDictionary <IList <IGPSPoint>, MapPolyline> allRoutes = new Dictionary <IList <IGPSPoint>, MapPolyline>();
            IDictionary <IList <IGPSPoint>, MapPolyline> dupRoutes = new Dictionary <IList <IGPSPoint>, MapPolyline>();

            foreach (KeyValuePair <string, MapPolyline> pair in m_MarkedTrailRoutes)
            {
                if (!allRoutes.ContainsKey(pair.Value.Locations))
                {
                    allRoutes.Add(new KeyValuePair <IList <IGPSPoint>, MapPolyline>(pair.Value.Locations, pair.Value));
                }
            }
            foreach (KeyValuePair <string, MapPolyline> pair in m_TrailRoutes)
            {
                if (!allRoutes.ContainsKey(pair.Value.Locations))
                {
                    allRoutes.Add(new KeyValuePair <IList <IGPSPoint>, MapPolyline>(pair.Value.Locations, pair.Value));
                }
                else if (!dupRoutes.ContainsKey(pair.Value.Locations))
                {
                    dupRoutes.Add(new KeyValuePair <IList <IGPSPoint>, MapPolyline>(pair.Value.Locations, pair.Value));
                }
            }
            IDictionary <IList <IGPSPoint>, MapPolyline> visibleRoutes = new Dictionary <IList <IGPSPoint>, MapPolyline>();

            foreach (KeyValuePair <IList <IGPSPoint>, MapPolyline> pair in allRoutes)
            {
                IList <IGPSPoint> r = new List <IGPSPoint>();
                foreach (IGPSPoint point in pair.Value.Locations)
                {
                    if (windowBounds.Contains(point))
                    {
                        visibleRoutes.Add(pair);
                        break;
                    }
                }
                //check for route in bounds only - the following does not seem to speed up
                //foreach (IGPSPoint point in pair.Value.Locations)
                //{
                //    if (windowBounds.Contains(point))
                //    {
                //        r.Add(point);
                //    }
                //}
                //if (r.Count > 0)
                //{
                //    MapPolyline m = new MapPolyline(r, pair.Value.LineWidth, pair.Value.LineColor);
                //    visibleRoutes.Add(pair.Key, m);
                //}
            }
            IDictionary <IList <IGPSPoint>, IMapOverlay> newRouteOverlays = new Dictionary <IList <IGPSPoint>, IMapOverlay>();

            foreach (KeyValuePair <IList <IGPSPoint>, MapPolyline> pair in visibleRoutes)
            {
                MapPolyline m = pair.Value;
                newRouteOverlays.Add(m.Locations, m);
                if ((!m_scalingChanged) &&
                    m_routeOverlays.ContainsKey(m.Locations) &&
                    !dupRoutes.ContainsKey(m.Locations))
                {
                    //No need to refresh this point
                    m_routeOverlays.Remove(m.Locations);
                }
                else
                {
                    addedOverlays.Add(m);
                }
            }

            //TrailPoints
            IDictionary <IGPSPoint, IMapOverlay> newPointOverlays = new Dictionary <IGPSPoint, IMapOverlay>();

            foreach (TrailGPSLocation location in m_TrailPoints)
            {
                PointMapMarker pointOverlay = new PointMapMarker(location, getCircleIcon(this.MapControl, location.Radius), MouseEvents && (this.m_editTrail != null));
                if (this.MouseEvents && location.Name != "DebugNotClickableDebug")
                {
                    pointOverlay.MouseDown += new MouseEventHandler(pointOverlay_MouseDown);
                    pointOverlay.MouseUp   += new MouseEventHandler(pointOverlay_MouseUp);
                }
                if (!newPointOverlays.ContainsKey(location))
                {
                    newPointOverlays.Add(location, pointOverlay);
                }
                addedOverlays.Add(pointOverlay);
            }

            //SplitPoints
            foreach (SplitGPSLocation location in m_SplitPoints)
            {
                PointMapMarker pointOverlay = new PointMapMarker(location, getRhombusIcon(location.PointColor), false);
                if (!newPointOverlays.ContainsKey(location))
                {
                    newPointOverlays.Add(location, pointOverlay);
                }
                addedOverlays.Add(pointOverlay);
            }

            // Draw overlay
            if (0 == newPointOverlays.Count && 0 == visibleRoutes.Count)
            {
                return;
            }

            m_scalingChanged = false;
            if (!clear && !MapControlChanged)
            {
                ClearOverlays();
            }
            MapControl.AddOverlays(addedOverlays);
            m_pointOverlays = newPointOverlays;
            m_routeOverlays = newRouteOverlays;
            if (m_extraMapLayer != null)
            {
                try
                {
                    //Remove overlays are not working properly, the Map is not very usable
                    m_extraMapLayer.MapControl.AddOverlays(addedOverlays);
                }
                catch (Exception) {}
                m_extraMapLayer.m_pointOverlays = newPointOverlays;
                m_extraMapLayer.m_routeOverlays = newRouteOverlays;
            }
        }