Esempio n. 1
0
        /// <summary>
        /// Adds a point.
        /// </summary>
        /// <returns>The point.</returns>
        /// <param name="coordinate">Coordinate.</param>
        /// <param name="sizePixels">Size pixels.</param>
        public void AddPoint(GeoCoordinate coordinate, float sizePixels, int color)
        {
            double[] projectedCoordinates = _projection.ToPixel(
                coordinate);
            uint pointId = _scene.AddPoint(projectedCoordinates[0], projectedCoordinates[1]);

            _scene.AddStylePoint(pointId, 0, float.MinValue, float.MaxValue, color, sizePixels);
            this.RaiseLayerChanged();
        }
Esempio n. 2
0
        /// <summary>
        /// Adds a point.
        /// </summary>
        /// <returns>The point.</returns>
        /// <param name="coordinate">Coordinate.</param>
        /// <param name="sizePixels">Size pixels.</param>
        public uint AddPoint(GeoCoordinate coordinate, float sizePixels, int color)
        {
            double[] projectedCoordinates = _projection.ToPixel(
                coordinate);
            uint id = _scene.AddPoint(float.MinValue, float.MaxValue,
                                      projectedCoordinates[0], projectedCoordinates[1],
                                      color, sizePixels);

            this.RaiseLayerChanged();
            return(id);
        }
Esempio n. 3
0
        /// <summary>
        /// Sets the layout.
        /// </summary>
        /// <param name="pixelsWidth">Pixels width.</param>
        /// <param name="pixelsHeight">Pixels height.</param>
        /// <param name="view">View.</param>
        /// <param name="projection">Projection.</param>
        internal bool SetLayout(double pixelsWidth, double pixelsHeight, View2D view, IProjection projection)
        {
            double[] projected     = projection.ToPixel(this.Location);
            double[] locationPixel = view.ToViewPort(pixelsWidth, pixelsHeight, projected [0], projected [1]);

//			if (locationPixel [0] > 0 && locationPixel [0] < pixelsWidth &&
//			    locationPixel [1] > 0 && locationPixel [1] < pixelsHeight) {

            // set the new location depending on the size of the image and the alignment parameter.
            double leftMargin = locationPixel [0];
            double topMargin  = locationPixel [1];

            switch (_alignment)
            {
            case MapMarkerAlignmentType.CenterBottom:
                topMargin = locationPixel [1] - (this.LayoutParameters as FrameLayout.LayoutParams).Height / 2.0;
                break;

            case MapMarkerAlignmentType.CenterTop:
                topMargin = locationPixel [1] + (this.LayoutParameters as FrameLayout.LayoutParams).Height / 2.0;
                break;
            }

            (this.LayoutParameters as FrameLayout.LayoutParams).LeftMargin = (int)leftMargin;
            (this.LayoutParameters as FrameLayout.LayoutParams).TopMargin  = (int)topMargin;
            return(true);
//			}
//			return false;
        }
Esempio n. 4
0
        /// <summary>
        /// Adds a point.
        /// </summary>
        /// <returns>The point.</returns>
        /// <param name="coordinate">Coordinate.</param>
        /// <param name="sizePixels">Size pixels.</param>
        /// <param name="color"></param>
        public void AddPoint(GeoCoordinate coordinate, float sizePixels, int color)
        {
            // update envelope.
            if (_envelope == null)
            { // create initial envelope.
                _envelope = new GeoCoordinateBox(coordinate, coordinate);
            }
            // also include the current point.
            _envelope.ExpandWith(coordinate);

            double[] projectedCoordinates = _projection.ToPixel(coordinate);
            uint     pointId = _scene.AddPoint(projectedCoordinates[0], projectedCoordinates[1]);

            _scene.AddStylePoint(pointId, 0, float.MinValue, float.MaxValue, color, sizePixels);
            this.RaiseLayerChanged();
        }
Esempio n. 5
0
        /// <summary>
        /// Sets the layout.
        /// </summary>
        /// <param name="pixelsWidth">Pixels width.</param>
        /// <param name="pixelsHeight">Pixels height.</param>
        /// <param name="view">View.</param>
        /// <param name="projection">Projection.</param>
        internal override bool SetLayout(double pixelsWidth, double pixelsHeight, View2D view, IProjection projection)
        {
            base.SetLayout(pixelsWidth, pixelsHeight, view, projection);

            if (this.MoveWithMap)
            { // keep location the same and move with map.
                if (this.Location != null &&
                    _popupView != null)
                { // only set layout if there is a location set.
                    var    projected = projection.ToPixel(this.Location);
                    var    toView = view.CreateToViewPort(pixelsWidth, pixelsHeight);
                    double locationPixelX, locationPixelY;
                    // var locationPixel = view.ToViewPort(pixelsWidth, pixelsHeight, projected[0], projected[1]);
                    toView.Apply(projected[0], projected[1], out locationPixelX, out locationPixelY);

                    // set the new location depending on the size of the image and the alignment parameter.
                    double leftPopupMargin = locationPixelX;
                    double topPopupMargin  = locationPixelY;

                    leftPopupMargin = locationPixelX - (_popupView.LayoutParameters as FrameLayout.LayoutParams).Width / 2.0;

                    switch (this.Alignment)
                    {
                    case MapControlAlignmentType.Center:
                        topPopupMargin = locationPixelY
                                         - (this.View.LayoutParameters as FrameLayout.LayoutParams).Height / 2.0
                                         - (_popupView.LayoutParameters as FrameLayout.LayoutParams).Height;
                        break;

                    case MapControlAlignmentType.CenterTop:
                        topPopupMargin = locationPixelY
                                         - (_popupView.LayoutParameters as FrameLayout.LayoutParams).Height;
                        break;

                    case MapControlAlignmentType.CenterBottom:
                        topPopupMargin = locationPixelY
                                         - (this.View.LayoutParameters as FrameLayout.LayoutParams).Height
                                         - (_popupView.LayoutParameters as FrameLayout.LayoutParams).Height;
                        break;
                    }

                    // add offsets.
                    leftPopupMargin = leftPopupMargin + _popupXOffset;
                    topPopupMargin  = topPopupMargin + _popupYOffset;

                    (_popupView.LayoutParameters as FrameLayout.LayoutParams).LeftMargin = (int)leftPopupMargin;
                    (_popupView.LayoutParameters as FrameLayout.LayoutParams).TopMargin  = (int)topPopupMargin;

                    _popupLayoutSet = true;
                }
            }
            return(true);
        }
Esempio n. 6
0
        /// <summary>
        /// Sets the layout.
        /// </summary>
        /// <param name="pixelsWidth">Pixels width.</param>
        /// <param name="pixelsHeight">Pixels height.</param>
        /// <param name="view">View.</param>
        /// <param name="projection">Projection.</param>
        internal bool SetLayout(double pixelsWidth, double pixelsHeight, View2D view, IProjection projection)
        {
            double[] projected     = projection.ToPixel(this.Location);
            double[] locationPixel = view.ToViewPort(pixelsWidth, pixelsHeight, projected [0], projected [1]);

//			if (locationPixel [0] > 0 && locationPixel [0] < pixelsWidth &&
//			    locationPixel [1] > 0 && locationPixel [1] < pixelsHeight) {

            // set the new location depending on the size of the image and the alignment parameter.
				double leftMargin = locationPixel [0];// - this.Bitmap.Size.Width / 2.0;
				double topMargin = locationPixel [1];
				switch (_alignment) {
				case MapMarkerAlignmentType.CenterTop:
					topMargin = locationPixel [1] + this.Image.Size.Height / 2.0;
					break;
				case MapMarkerAlignmentType.CenterBottom:
					topMargin = locationPixel [1] - this.Image.Size.Height / 2.0;
					break;
				}
            this.Center = new System.Drawing.PointF((float)leftMargin, (float)topMargin);

            return(true);
//			}
//			return false;
        }
Esempio n. 7
0
        /// <summary>
        /// Sets the layout.
        /// </summary>
        /// <param name="pixelsWidth">Pixels width.</param>
        /// <param name="pixelsHeight">Pixels height.</param>
        /// <param name="view">View.</param>
        /// <param name="projection">Projection.</param>
        internal bool SetLayout(double pixelsWidth, double pixelsHeight, View2D view, IProjection projection)
        {
            double[] projected     = projection.ToPixel(this.Location);
            double[] locationPixel = view.ToViewPort(pixelsWidth, pixelsHeight, projected [0], projected [1]);

            if (locationPixel [0] > 0 && locationPixel [0] < pixelsWidth &&
                locationPixel [1] > 0 && locationPixel [1] < pixelsHeight)
            {
                (this.LayoutParameters as FrameLayout.LayoutParams).LeftMargin = (int)(locationPixel [0] -
                                                                                       (this.LayoutParameters as FrameLayout.LayoutParams).Width / 2.0);
                (this.LayoutParameters as FrameLayout.LayoutParams).TopMargin = (int)locationPixel [1] -
                                                                                (this.LayoutParameters as FrameLayout.LayoutParams).Height;
                return(true);
            }
            return(false);
        }
Esempio n. 8
0
        public override IEnumerable <Primitive2D> Get(float zoomFactor, View2D view)
        {
            var result  = new List <Primitive2D>();
            var viewBox = view.OuterBox;
            var box     = new GeoCoordinateBox(_projection.ToGeoCoordinates(viewBox.Min[0], viewBox.Min[1]),
                                               _projection.ToGeoCoordinates(viewBox.Max[0], viewBox.Max[1]));



            var point = _projection.ToPixel(box.Center.Latitude, box.Center.Longitude);
            var p     = new Icon2D(point[0], point[1], Create(""));

            p.ToolTip = "Подсказка";
            result.Add(p);

            return(result);
        }
Esempio n. 9
0
        /// <summary>
        /// Creates a view.
        /// </summary>
        /// <param name="height"></param>
        /// <param name="map"></param>
        /// <param name="zoomFactor"></param>
        /// <param name="center"></param>
        /// <param name="width"></param>
        /// <param name="angle"></param>
        /// <param name="xInverted">True when the x-axis on the target is inverted (right->left).</param>
        /// <param name="yInverted">True when the y-axis on the target is inverted (top->bottom).</param>
        /// <returns></returns>
        public View2D Create(float width, float height, Map map, float zoomFactor, GeoCoordinate center, bool xInverted, bool yInverted, Degree angle)
        {
            // get the projection.
            IProjection projection = map.Projection;

            // calculate the center/zoom in scene coordinates.
            double[] sceneCenter     = projection.ToPixel(center.Latitude, center.Longitude);
            float    sceneZoomFactor = zoomFactor;

            // inversion flags for view: only invert when different.
            bool invertX = xInverted && (xInverted != !projection.DirectionX);
            bool invertY = yInverted && (yInverted != !projection.DirectionY);

            // create the view for this control.
            return(View2D.CreateFrom((float)sceneCenter[0], (float)sceneCenter[1],
                                     width, height, sceneZoomFactor,
                                     invertX, invertY, angle));
        }
Esempio n. 10
0
        /// <summary>
        /// Sets the layout.
        /// </summary>
        /// <param name="pixelsWidth">Pixels width.</param>
        /// <param name="pixelsHeight">Pixels height.</param>
        /// <param name="view">View.</param>
        /// <param name="projection">Projection.</param>
        protected internal override bool SetLayout(double pixelsWidth, double pixelsHeight, View2D view, IProjection projection)
        {
            base.SetLayout(pixelsWidth, pixelsHeight, view, projection);

            if (this.Location != null &&
                _popupView != null)
            { // only set layout if there is a location set.
                var projected     = projection.ToPixel(this.Location);
                var locationPixel = view.ToViewPort(pixelsWidth, pixelsHeight, projected[0], projected[1]);

                // set the new location depending on the size of the image and the alignment parameter.
                double leftMargin = locationPixel [0];// - this.Bitmap.Size.Width / 2.0;
                double topMargin  = locationPixel [1];
                switch (this.Alignment)
                {
                case MapControlAlignmentType.CenterTop:
                    topMargin = locationPixel [1] - (_popupView.Frame.Height / 2.0);
                    break;

                case MapControlAlignmentType.Center:
                    topMargin = locationPixel [1] - (this.View.Frame.Height / 2.0) - (_popupView.Frame.Height / 2.0);
                    break;

                case MapControlAlignmentType.CenterBottom:
                    topMargin = locationPixel [1] - this.View.Frame.Height - (_popupView.Frame.Height / 2.0);
                    break;
                }

                // add offsets.
                leftMargin = leftMargin + _popupXOffset;
                topMargin  = topMargin + _popupYOffset;

                _popupView.Center = new CGPoint((float)leftMargin, (float)topMargin);

                return(true);
            }
            return(true);
        }
Esempio n. 11
0
		/// <summary>
		/// Sets the layout.
		/// </summary>
		/// <param name="pixelsWidth">Pixels width.</param>
		/// <param name="pixelsHeight">Pixels height.</param>
		/// <param name="view">View.</param>
		/// <param name="projection">Projection.</param>
		internal bool SetLayout(double pixelsWidth, double pixelsHeight, View2D view, IProjection projection)
		{
			double[] projected = projection.ToPixel (this.Location);
			double[] locationPixel = view.ToViewPort (pixelsWidth, pixelsHeight, projected [0], projected [1]);

//			if (locationPixel [0] > 0 && locationPixel [0] < pixelsWidth &&
//			    locationPixel [1] > 0 && locationPixel [1] < pixelsHeight) {

				// set the new location depending on the size of the image and the alignment parameter.
				double leftMargin = locationPixel [0];// - this.Bitmap.Size.Width / 2.0;
				double topMargin = locationPixel [1];
				switch (_alignment) {
				case MapMarkerAlignmentType.CenterTop:
					topMargin = locationPixel [1] + this.Image.Size.Height / 2.0;
					break;
				case MapMarkerAlignmentType.CenterBottom:
					topMargin = locationPixel [1] - this.Image.Size.Height / 2.0;
					break;
				}
				this.Center = new System.Drawing.PointF ((float)leftMargin, (float)topMargin);

				return true;
//			}
//			return false;
		}
Esempio n. 12
0
        /// <summary>
        /// Sets the layout.
        /// </summary>
        /// <param name="pixelsWidth">Pixels width.</param>
        /// <param name="pixelsHeight">Pixels height.</param>
        /// <param name="view">View.</param>
        /// <param name="projection">Projection.</param>
        internal bool SetLayout(double pixelsWidth, double pixelsHeight, View2D view, IProjection projection)
        {
            double[] projected = projection.ToPixel (this.Location);
            double[] locationPixel = view.ToViewPort (pixelsWidth, pixelsHeight, projected [0], projected [1]);

            //			if (locationPixel [0] > 0 && locationPixel [0] < pixelsWidth &&
            //			    locationPixel [1] > 0 && locationPixel [1] < pixelsHeight) {

                // set the new location depending on the size of the image and the alignment parameter.
                double leftMargin = locationPixel [0];
                double topMargin = locationPixel [1];

                switch (_alignment) {
                case MapMarkerAlignmentType.CenterBottom:
                    topMargin = locationPixel [1] - (this.LayoutParameters as FrameLayout.LayoutParams).Height / 2.0;
                    break;
                case MapMarkerAlignmentType.CenterTop:
                    topMargin = locationPixel [1] + (this.LayoutParameters as FrameLayout.LayoutParams).Height / 2.0;
                    break;
                }

                (this.LayoutParameters as FrameLayout.LayoutParams).LeftMargin = (int)leftMargin;
                (this.LayoutParameters as FrameLayout.LayoutParams).TopMargin = (int)topMargin;
                return true;
            //			}
            //			return false;
        }
Esempio n. 13
0
        /// <summary>
        /// Updates the tracker with the given location and angle.
        /// </summary>
        /// <param name="location">The measured location.</param>
        /// <param name="angle">The angle relative to the north measure clockwise.</param>
        public void Track(GeoCoordinate location, Degree angle)
        {
            if (location == null)
            {
                throw new ArgumentNullException("location");
            }

            if (_lastTouch.HasValue)
            {
                // is tracking disabled now?
                TimeSpan timeFromLastTouch = new TimeSpan(DateTime.Now.Ticks - _lastTouch.Value);
                if (timeFromLastTouch.TotalSeconds >= this.RestartAfterTouch.Value)
                {
                    // ok, the animator has waited long enough.
                    _lastTouch = null;
                }
                else
                {
                    // ok, the animator still has to wait for user-input.
                    return;
                }
            }

            // check if the minimum gap between tracking events is respected.
            long now = DateTime.Now.Ticks;

            if (_lastTrack.HasValue)
            {
                if (_minimumTrackGap > now - _lastTrack.Value)
                {
                    return;                     // too fast!
                }
            }
            _lastTrack = now;

            // animate the next step(s).
            TimeSpan lastTrackInterval = new TimeSpan(0, 0, 0, 0, 750);
            long     ticks             = DateTime.Now.Ticks;

            if (_lastTicks.HasValue)
            { // update the last track interval.
                lastTrackInterval = TimeSpan.FromTicks(ticks - _lastTicks.Value);
            }
            _lastTicks = ticks;
            OsmSharp.Logging.Log.TraceEvent("RouteTrackerAnimator", OsmSharp.Logging.TraceEventType.Information,
                                            "Interval: {0}ms", lastTrackInterval.TotalMilliseconds);

            // give location to the route tracker.
            _routeTracker.Track(location);

            // calculate all map view parameters (zoom, location, tilt) to display the route/direction correctly.
            float         zoom         = this.DefaultZoom;
            GeoCoordinate center       = _routeTracker.PositionRoute;
            double        nextDistance = 50;
            Degree        tilt         = _mapView.MapTilt;
            GeoCoordinate next         = _routeTracker.PositionAfter(nextDistance);

            if (next != null)
            {
                IProjection projection = _mapView.Map.Projection;
                VectorF2D   direction  = new PointF2D(projection.ToPixel(next)) -
                                         new PointF2D(projection.ToPixel(center));
                tilt = direction.Angle(new VectorF2D(0, -1));
            }

            // overwrite calculated tilt with the given degrees.
            if (angle != null)
            {
                tilt = angle;
            }


            OsmSharp.Logging.Log.TraceEvent("RouteTrackerAnimator", OsmSharp.Logging.TraceEventType.Information,
                                            "Tracking Event: {0}, {1}, {2}", center, zoom, tilt);

            // animate to the given parameter (zoom, location, tilt).
            _animator.Stop();
            _animator.Start(center, zoom, tilt, lastTrackInterval.Subtract(new TimeSpan(0, 0, 0, 0, 50)));
        }