Пример #1
0
        /// <summary>
        /// Raises the mousemove event.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            var currentCoordinates = new double[] { e.X, e.Y };

            if (this.MapAllowPan &&
                e.Button == MouseButtons.Left &&
                _draggingCoordinates != null)
            {
                var delta = new double[] { _draggingCoordinates[0] - currentCoordinates[0],
                                           (_draggingCoordinates[1] - currentCoordinates[1]) };

                var newCenter = new double[] { this.Width / 2.0f + delta[0], this.Height / 2.0f + delta[1] };

                this.MapCenter = _oldCenter;

                View2D view = _renderer.Create(this.Width, this.Height, this.Map,
                                               (float)this.Map.Projection.ToZoomFactor(this.MapZoom), this.MapCenter, false, true);

                double x, y;
                var    fromMatrix = view.CreateFromViewPort(this.Width, this.Height);
                fromMatrix.Apply(newCenter[0], newCenter[1], out x, out y);

                // project to new center.
                this.MapCenter = this.Map.Projection.ToGeoCoordinates(x, y);

                // notify the map.
                this.QueueNotifyMapViewChanged();
            }
            this.RaiseOnMapMouseMove(e);
        }
Пример #2
0
        /// <summary>
        /// Transforms the canvas to the coordinate system of the view.
        /// </summary>
        /// <param name="view"></param>
        /// <param name="target"></param>
        protected override void Transform(Target2DWrapper <global::Android.Graphics.Canvas> target, View2D view)
        {
            _view   = view;
            _target = target;

            _toViewPort   = _view.CreateToViewPort(_target.Width, _target.Height);
            _fromViewPort = _view.CreateFromViewPort(_target.Width, _target.Height);
        }
Пример #3
0
        /// <summary>
        /// Raises the OnMapMouseDoubleClick event.
        /// </summary>
        /// <param name="e"></param>
        private void RaiseOnMapMouseDoubleClick(MouseEventArgs e)
        {
            if (this.Map != null)
            {
                View2D view = _renderer.Create(this.Width, this.Height, this.Map,
                                               (float)this.Map.Projection.ToZoomFactor(this.MapZoom), this.MapCenter, false, true);

                // get scene coordinates.
                double x, y;
                var    fromMatrix = view.CreateFromViewPort(this.Width, this.Height);
                fromMatrix.Apply(e.X, e.Y, out x, out y);
                var geoCoordinates = this.Map.Projection.ToGeoCoordinates(x, y);

                // create map user control event args.
                var args = new MapControlEventArgs(e, geoCoordinates);
                this.OnMapMouseDoubleClick(args);
                if (MapMouseDoubleClick != null)
                {
                    MapMouseDoubleClick(args);
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Utility method for ensuring a view stays within a bounding box of geo coordinated.
        /// </summary>
        /// <param name="center">The map center we want to move to.</param>
        /// <param name="boundingBox">A GeoCoordinateBox defining the bounding box.</param>
        /// <param name="view" The current view.</param>
        /// <returns>Returns a center geo coordinate that is corrected so the view stays within the bounding box.</returns>
        public GeoCoordinate EnsureViewWithinBoundingBox(GeoCoordinate center, GeoCoordinateBox boundingBox, View2D view)
        {
            double[] mapCenterSceneCoords = this.Projection.ToPixel(center);

            var    toViewPort = view.CreateToViewPort(view.Width, view.Height);
            double mapCenterPixelsX, mapCenterPixelsY;

            toViewPort.Apply(mapCenterSceneCoords[0], mapCenterSceneCoords[1], out mapCenterPixelsX, out mapCenterPixelsY);

            //double[] mapCenterPixels = view.ToViewPort(view.Width, view.Height, mapCenterSceneCoords[0], mapCenterSceneCoords[1]);

            var    fromViewPort = view.CreateFromViewPort(view.Height, view.Width);
            double leftScene, topScene, rightScene, bottomScene;

            fromViewPort.Apply(mapCenterPixelsX - (view.Width) / 2.0, mapCenterPixelsY - (view.Height) / 2.0, out leftScene, out topScene);

            //double[] topLeftSceneCoordinates = view.FromViewPort(view.Width,
            //                                                    view.Height,
            //                                                    mapCenterPixels[0] - (view.Width) / 2.0,
            //                                                    mapCenterPixels[1] - (view.Height) / 2.0);
            GeoCoordinate topLeft = this.Projection.ToGeoCoordinates(leftScene, topScene);

            //GeoCoordinate topLeft = this.Projection.ToGeoCoordinates(topLeftSceneCoordinates[0], topLeftSceneCoordinates[1]);

            fromViewPort.Apply(mapCenterPixelsX + (view.Width) / 2.0, mapCenterPixelsY + (view.Height) / 2.0, out rightScene, out bottomScene);
            //double[] bottomRightSceneCoordinates = view.FromViewPort(view.Width,
            //                                                    view.Height,
            //                                                    mapCenterPixels[0] + (view.Width) / 2.0,
            //                                                    mapCenterPixels[1] + (view.Height) / 2.0);
            GeoCoordinate bottomRight = this.Projection.ToGeoCoordinates(rightScene, bottomScene);

            // Early exit when the view is inside the box.
            if (boundingBox.Contains(topLeft) && boundingBox.Contains(bottomRight))
            {
                return(center);
            }

            double viewNorth = topLeft.Latitude;
            double viewEast  = bottomRight.Longitude;
            double viewSouth = bottomRight.Latitude;
            double viewWest  = topLeft.Longitude;

            double boxNorth = boundingBox.MaxLat;
            double boxEast  = boundingBox.MaxLon;
            double boxSouth = boundingBox.MinLat;
            double boxWest  = boundingBox.MinLon;

            //TODO: Check if the view acrually fits the bounding box, if not resize the view.

            // Correct all view bounds if neccecary.
            if (viewNorth > boxNorth)
            {
                viewSouth -= viewNorth - boxNorth;
                viewNorth  = boxNorth;
            }
            if (viewEast > boxEast)
            {
                viewWest -= viewEast - boxEast;
                viewEast  = boxEast;
            }
            if (viewSouth < boxSouth)
            {
                viewNorth += boxSouth - viewSouth;
                viewSouth  = boxSouth;
            }
            if (viewWest < boxWest)
            {
                viewEast += boxWest - viewWest;
                viewWest  = boxWest;
            }

            // Compute and return corrected map center
            return(new GeoCoordinate(viewSouth + (viewNorth - viewSouth) / 2.0f, viewWest + (viewEast - viewWest) / 2.0f));
        }