示例#1
0
        /*
         * public static void CenterClusters(IEnumerable<Cluster> clusters, IViewport viewport)
         * {
         *      foreach (var cluster in clusters)
         *      {
         *              var feature = cluster.Features.FirstOrDefault ();
         *              var center = cluster.Box.GetCentroid ();
         *
         *              var styles = feature.Styles ?? Enumerable.Empty<IStyle>();
         *              var style = styles.FirstOrDefault () as SymbolStyle;
         *
         *              var min = viewport.WorldToScreen (cluster.Box.Left, cluster.Box.Bottom);
         *              var max = viewport.WorldToScreen (cluster.Box.Right, cluster.Box.Top);
         *              //style.Width = .Width;
         *              //style.Height = cluster.Box.Height;
         *
         *              var size = (int)Math.Min ((max.X - min.X), (min.Y - max.Y));
         *
         *              //Console.WriteLine ("Size = " + size);
         *              //style.Width = size;
         *              //style.Height = size;
         *
         *              feature.Geometry = center;
         *
         *              //var fCenter = firstFeature.Geometry.GetBoundingBox ().GetCentroid ();
         *              //if(fCenter.X == cluster.Box.GetCentroid().X)
         *      }
         * }
         */

        private static BoundingBox GetFeatureBoundingBox(IFeature feature,
                                                         IViewport viewport)
        {
            var styles      = feature.Styles ?? Enumerable.Empty <IStyle>();
            var symbolStyle = styles.FirstOrDefault() as SymbolStyle;
            var boundingBox = feature.Geometry.GetBoundingBox();
            //var width = style.Width;

            //var frame = GeometryRenderer.ConvertPointBoundingBox (style, feature.Geometry.GetBoundingBox (), viewport);
            var screenMin = viewport.WorldToScreen(boundingBox.Min);
            var screenMax = viewport.WorldToScreen(boundingBox.Max);

            var min = new Mapsui.Geometries.Point(screenMin.X - (symbolStyle.Width / 2), screenMax.Y - (symbolStyle.Height / 2));
            var max = new Mapsui.Geometries.Point((min.X + symbolStyle.Width), (min.Y + symbolStyle.Height));

            var x      = min.X;
            var y      = min.Y;
            var width  = max.X - min.X;
            var height = max.Y - min.Y;

            var frame = new RectangleF((float)x, (float)y, (float)width, (float)height);

            var nmin = viewport.ScreenToWorld(frame.Left, frame.Bottom);
            var nmax = viewport.ScreenToWorld(frame.Right, frame.Top);


            var bb = new BoundingBox(nmin, nmax);


            return(bb);
        }
 public static void Pan(IViewport transform, Point currentMap, Point previousMap)
 {
   var current = transform.ScreenToWorld(currentMap.X, currentMap.Y);
   var previous = transform.ScreenToWorld(previousMap.X, previousMap.Y);
   var diffX = previous.X - current.X;
   var diffY = previous.Y - current.Y;
   transform.Center = new Point(transform.Center.X + diffX, transform.Center.Y + diffY);
 }
示例#3
0
        public static void Pan(IViewport transform, Point currentMap, Point previousMap)
        {
            var current  = transform.ScreenToWorld(currentMap.X, currentMap.Y);
            var previous = transform.ScreenToWorld(previousMap.X, previousMap.Y);
            var diffX    = previous.X - current.X;
            var diffY    = previous.Y - current.Y;

            transform.Center = new Point(transform.Center.X + diffX, transform.Center.Y + diffY);
        }
示例#4
0
        public void ZoomTo(double resolution, Point centerOfZoom)
        {
            // 1) Temporarily center on the center of zoom
            _viewport.SetCenter(_viewport.ScreenToWorld(centerOfZoom));

            // 2) Then zoom
            _viewport.SetResolution(resolution);

            // 3) Then move the temporary center of the map back to the mouse position
            _viewport.SetCenter(_viewport.ScreenToWorld(
                                    _viewport.Width - centerOfZoom.X,
                                    _viewport.Height - centerOfZoom.Y));
        }
示例#5
0
        public static InfoEventArgs GetInfoEventArgs(IViewport viewport, Point screenPosition, IEnumerable <ILayer> layers,
                                                     ISymbolCache symbolCache)
        {
            var worldPosition = viewport.ScreenToWorld(new Point(screenPosition.X, screenPosition.Y));

            return(GetInfoEventArgs(layers, worldPosition, screenPosition, viewport.Resolution, symbolCache));
        }
示例#6
0
        public static CGRect ConvertPointBoundingBox(SymbolStyle symbolStyle, BoundingBox boundingBox, IViewport viewport)
        {
            var screenMin = viewport.WorldToScreen(boundingBox.Min);
            var screenMax = viewport.WorldToScreen(boundingBox.Max);

            //boundingBox.Offset = symbolStyle.SymbolOffset;
            //var newMin = boundingBox.Min;
            //var newMax = boundingBox.Max;

            if (symbolStyle.SymbolOffset != null)
            {
                screenMin = new Geometries.Point(
                    screenMin.X - symbolStyle.SymbolOffset.X,
                    screenMin.Y - symbolStyle.SymbolOffset.Y);
                screenMax = new Geometries.Point(
                    screenMax.X - symbolStyle.SymbolOffset.X,
                    screenMax.Y - symbolStyle.SymbolOffset.Y);

                var w = viewport.ScreenToWorld(screenMin);

                boundingBox.Offset(new Geometries.Point(w.X - boundingBox.MinX, w.Y - boundingBox.MinY));

                screenMin = viewport.WorldToScreen(boundingBox.Min);
                screenMax = viewport.WorldToScreen(boundingBox.Max);
            }

            var min = new Geometries.Point(screenMin.X - (32 / 2), screenMax.Y - (32 / 2)); //!!!
            var max = new Geometries.Point((min.X + 32), (min.Y + 32)); //!!!

            var frame = RoundToPixel(min, max);
            //if(symbolStyle.SymbolOffset != null)
            //	frame.Offset ((float)symbolStyle.SymbolOffset.X, (float)symbolStyle.SymbolOffset.Y);

            return frame;
        }
示例#7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="viewport"></param>
        /// <param name="screenPosition"></param>
        /// <param name="layers"></param>
        /// <param name="symbolCache"></param>
        /// <param name="margin">Margin of error in pixels. If the distance between screen position and geometry
        /// is smaller than the margin it is seen as a hit.</param>
        /// <returns></returns>
        public static MapInfo GetMapInfo(IViewport viewport, Point screenPosition,
                                         IEnumerable <ILayer> layers, ISymbolCache symbolCache, int margin = 0)
        {
            var worldPosition = viewport.ScreenToWorld(screenPosition);

            return(GetMapInfo(layers, worldPosition, screenPosition, viewport.Resolution, symbolCache, margin));
        }
示例#8
0
        public static MapInfo GetMapInfo(IViewport viewport, Point screenPosition,
                                         float scale, IEnumerable <ILayer> layers, ISymbolCache symbolCache)
        {
            var worldPosition = viewport.ScreenToWorld(
                new Point(screenPosition.X / scale, screenPosition.Y / scale));

            return(GetMapInfo(layers, worldPosition, screenPosition, viewport.Resolution, symbolCache));
        }
示例#9
0
        public static RectangleF ConvertPointBoundingBox(SymbolStyle symbolStyle, BoundingBox boundingBox, IViewport viewport)
        {
            var screenMin = viewport.WorldToScreen(boundingBox.Min);
            var screenMax = viewport.WorldToScreen(boundingBox.Max);

            //boundingBox.Offset = symbolStyle.SymbolOffset;
            //var newMin = boundingBox.Min;
            //var newMax = boundingBox.Max;

            if (symbolStyle.SymbolOffset != null)
            {
                screenMin = new Geometries.Point(
                    screenMin.X - symbolStyle.SymbolOffset.X,
                    screenMin.Y - symbolStyle.SymbolOffset.Y);
                screenMax = new Geometries.Point(
                    screenMax.X - symbolStyle.SymbolOffset.X,
                    screenMax.Y - symbolStyle.SymbolOffset.Y);

                var w = viewport.ScreenToWorld(screenMin);

                boundingBox.Offset(new Geometries.Point(w.X - boundingBox.MinX, w.Y - boundingBox.MinY));

                screenMin = viewport.WorldToScreen(boundingBox.Min);
                screenMax = viewport.WorldToScreen(boundingBox.Max);
            }


            var min = new Geometries.Point(screenMin.X - (32 / 2), screenMax.Y - (32 / 2)); //!!!
            var max = new Geometries.Point((min.X + 32), (min.Y + 32));                     //!!!

            var frame = RoundToPixel(min, max);

            //if(symbolStyle.SymbolOffset != null)
            //	frame.Offset ((float)symbolStyle.SymbolOffset.X, (float)symbolStyle.SymbolOffset.Y);

            return(frame);
        }
示例#10
0
 public Point ScreenToWorld(Point position)
 {
     return(_viewport.ScreenToWorld(position));
 }
示例#11
0
        public static Point ScreenToWorld(IViewport viewport, float scale, Point screenPosition)
        {
            var worldPosition = viewport.ScreenToWorld(screenPosition.X * scale, screenPosition.Y * scale);

            return(new Point(worldPosition.X, worldPosition.Y));
        }
示例#12
0
		/*
		public static void CenterClusters(IEnumerable<Cluster> clusters, IViewport viewport)
		{
			foreach (var cluster in clusters)
			{
				var feature = cluster.Features.FirstOrDefault ();
				var center = cluster.Box.GetCentroid ();

				var styles = feature.Styles ?? Enumerable.Empty<IStyle>();
				var style = styles.FirstOrDefault () as SymbolStyle;

				var min = viewport.WorldToScreen (cluster.Box.Left, cluster.Box.Bottom);
				var max = viewport.WorldToScreen (cluster.Box.Right, cluster.Box.Top);
				//style.Width = .Width;
				//style.Height = cluster.Box.Height;

				var size = (int)Math.Min ((max.X - min.X), (min.Y - max.Y));

				//Console.WriteLine ("Size = " + size);
				//style.Width = size;
				//style.Height = size;

				feature.Geometry = center;

				//var fCenter = firstFeature.Geometry.GetBoundingBox ().GetCentroid ();
				//if(fCenter.X == cluster.Box.GetCentroid().X)
			}
		}
		*/

		private static BoundingBox GetFeatureBoundingBox(IFeature feature, 
		                                   IViewport viewport)
		{
			var styles = feature.Styles ?? Enumerable.Empty<IStyle>();
			var symbolStyle = styles.FirstOrDefault () as SymbolStyle;
			var boundingBox = feature.Geometry.GetBoundingBox ();
			//var width = style.Width;

			//var frame = GeometryRenderer.ConvertPointBoundingBox (style, feature.Geometry.GetBoundingBox (), viewport); 
			var screenMin = viewport.WorldToScreen(boundingBox.Min);
			var screenMax = viewport.WorldToScreen(boundingBox.Max);

			var min = new Mapsui.Geometries.Point(screenMin.X - (symbolStyle.Width / 2), screenMax.Y - (symbolStyle.Height / 2));
			var max = new Mapsui.Geometries.Point((min.X + symbolStyle.Width), (min.Y + symbolStyle.Height));
	
			var x = min.X;
			var y = min.Y;
			var width = max.X - min.X;
			var height = max.Y - min.Y;

			var frame = new RectangleF((float)x, (float)y, (float)width, (float)height);

			var nmin = viewport.ScreenToWorld (frame.Left, frame.Bottom);
			var nmax = viewport.ScreenToWorld (frame.Right, frame.Top);


			var bb = new BoundingBox (nmin, nmax);


			return bb;
		}
 public static Geometries.BoundingBox MapToWorld(Geometries.BoundingBox box, IViewport view)
 {
     Geometries.Point lowerLeft = view.ScreenToWorld(box.BottomLeft);
     Geometries.Point upperRight = view.ScreenToWorld(box.TopRight);
     return new Geometries.BoundingBox(lowerLeft, upperRight);
 }
示例#14
0
 public static Geometries.BoundingBox MapToWorld(Geometries.BoundingBox box, IViewport view)
 {
     Geometries.Point lowerLeft  = view.ScreenToWorld(box.BottomLeft);
     Geometries.Point upperRight = view.ScreenToWorld(box.TopRight);
     return(new Geometries.BoundingBox(lowerLeft, upperRight));
 }