Beispiel #1
1
        public static CATextLayer RenderLabel(Mapsui.Geometries.Point point, LabelStyle style, IFeature feature, IViewport viewport, string text)
        {
            // Offset stackOffset,
            Mapsui.Geometries.Point p = viewport.WorldToScreen(point);
            //var pointF = new xPointF((float)p.X, (float)p.Y);
            var label = new CATextLayer ();

            var aString = new Foundation.NSAttributedString (text,
                                                                       new CoreText.CTStringAttributes(){
                Font = new CoreText.CTFont("ArialMT", 10)
            });

            var frame = new CGRect(new CoreGraphics.CGPoint((int)p.X, (int)p.Y), GetSizeForText(0, aString));
            //label.Frame = frame;
            //frame.Width = (float)(p2.X - p1.X);// + margin);
            //frame.Height = (float)(p1.Y - p2.Y);

            label.FontSize = 10;
            label.ForegroundColor = new CoreGraphics.CGColor (0, 0, 255, 150);
            label.BackgroundColor = new CoreGraphics.CGColor (255, 0, 2, 150);
            label.String = text;

            label.Frame = frame;

            Console.WriteLine ("Pos " + label.Frame.X + ":" + label.Frame.Y + " w " + label.Frame.Width + " h " + label.Frame.Height);

            // = MonoTouch.UIKit.UIScreen.MainScreen.Scale;
            //	label.ContentsScale = scale;

            return label;
        }
Beispiel #2
0
        private static SKPath ToSkia(IViewport viewport, Polygon polygon)
        {
            var vertices = polygon.ExteriorRing.Vertices;
            var path     = new SKPath();
            {
                // todo: use transform matrix
                var first = viewport.WorldToScreen(vertices[0].X, vertices[0].Y);
                path.MoveTo((float)first.X, (float)first.Y);

                for (var i = 1; i < vertices.Count; i++)
                {
                    var point = viewport.WorldToScreen(vertices[i].X, vertices[i].Y);
                    path.LineTo((float)point.X, (float)point.Y);
                }
                path.Close();
                foreach (var interiorRing in polygon.InteriorRings)
                {
                    // note: For Skia inner rings need to be clockwise and outer rings
                    // need to be counter clockwise (if this is the other way around it also
                    // seems to work)
                    // this is not a requirement of the OGC polygon.
                    var firstInner = viewport.WorldToScreen(interiorRing.Vertices[0].X, interiorRing.Vertices[0].Y);
                    path.MoveTo((float)firstInner.X, (float)firstInner.Y);
                    for (var i = 1; i < interiorRing.Vertices.Count; i++)
                    {
                        var point = viewport.WorldToScreen(interiorRing.Vertices[i].X, interiorRing.Vertices[i].Y);
                        path.LineTo((float)point.X, (float)point.Y);
                    }
                }
                path.Close();
                return(path);
            }
        }
Beispiel #3
0
        public static RectangleF ConvertBoundingBox(BoundingBox boundingBox, IViewport viewport)
        {
            var min = viewport.WorldToScreen(boundingBox.Min);
            var max = viewport.WorldToScreen(boundingBox.Max);

            return(RoundToPixel(min, max));
        }
Beispiel #4
0
 public static void PositionRaster(UIElement renderedGeometry, BoundingBox boundingBox, IViewport viewport)
 {
     ((XamlMedia.RectangleGeometry)((XamlShapes.Path)renderedGeometry).Data).Rect =
         RoundToPixel(new Rect(
                          viewport.WorldToScreen(boundingBox.Min).ToXaml(),
                          viewport.WorldToScreen(boundingBox.Max).ToXaml()));
 }
Beispiel #5
0
        public static void Render(Graphics graphics, IGeometry feature, IStyle style, IViewport viewport)
        {
            var stream = ((IRaster)feature).Data;
            stream.Position = 0;
            var bitmap = new Bitmap(stream);

            Geometries.Point min = viewport.WorldToScreen(new Geometries.Point(feature.GetBoundingBox().MinX, feature.GetBoundingBox().MinY));
            Geometries.Point max = viewport.WorldToScreen(new Geometries.Point(feature.GetBoundingBox().MaxX, feature.GetBoundingBox().MaxY));

            Rectangle destination = RoundToPixel(new RectangleF((float)min.X, (float)max.Y, (float)(max.X - min.X), (float)(min.Y - max.Y)));
            graphics.DrawImage(bitmap,
                destination,
                0, 0, bitmap.Width, bitmap.Height,
                GraphicsUnit.Pixel,
                new ImageAttributes());

            if (DeveloperTools.DeveloperMode)
            {
                var font = new System.Drawing.Font("Arial", 12);
                var message = (GC.GetTotalMemory(true) / 1000).ToString(CultureInfo.InvariantCulture) + " KB";
                graphics.DrawString(message, font, new SolidBrush(Color.Black), 10f, 10f);
            }

            bitmap.Dispose();
        }
Beispiel #6
0
        public static CGRect ConvertBoundingBox(BoundingBox boundingBox, IViewport viewport)
        {
            var min = viewport.WorldToScreen(boundingBox.Min);
            var max = viewport.WorldToScreen(boundingBox.Max);

            return RoundToPixel(min, max);
        }
Beispiel #7
0
        private static Rect WorldToView(Extent extent, IViewport viewport)
        {
            var min = viewport.WorldToScreen(extent.MinX, extent.MinY);
            var max = viewport.WorldToScreen(extent.MaxX, extent.MaxY);

            return(new Rect(min.X, max.Y, max.X - min.X, min.Y - max.Y));
        }
Beispiel #8
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);
        }
Beispiel #9
0
        private static SKPath ToSkia(IViewport viewport, Polygon polygon)
        {
            var vertices = polygon.ExteriorRing.Vertices;
            var path = new SKPath();
            {
                // todo: use transform matrix
                var first = viewport.WorldToScreen(vertices[0].X, vertices[0].Y);
                path.MoveTo((float)first.X, (float) first.Y);

                for (var i = 1; i < vertices.Count; i++)
                {
                   var point = viewport.WorldToScreen(vertices[i].X, vertices[i].Y);
                    path.LineTo((float) point.X, (float) point.Y);
                }
                path.Close();
                foreach (var interiorRing in polygon.InteriorRings)
                {
                    // note: For Skia inner rings need to be clockwise and outer rings
                    // need to be counter clockwise (if this is the other way around it also
                    // seems to work)
                    // this is not a requirement of the OGC polygon.
                    var firstInner = viewport.WorldToScreen(interiorRing.Vertices[0].X, interiorRing.Vertices[0].Y);
                    path.MoveTo((float)firstInner.X, (float)firstInner.Y);
                    for (var i = 1; i < interiorRing.Vertices.Count; i++)
                    {
                        var point = viewport.WorldToScreen(interiorRing.Vertices[i].X, interiorRing.Vertices[i].Y);
                        path.LineTo((float)point.X, (float)point.Y);
                    }
                }
                path.Close();
                return path;
            }
        }
Beispiel #10
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;
        }
Beispiel #11
0
        public static void DrawRaster(Graphics graphics, IGeometry feature, IStyle style, IViewport viewport)
        {
            var stream = ((IRaster)feature).Data;

            stream.Position = 0;
            var bitmap = new Bitmap(stream);

            Point min = viewport.WorldToScreen(new Point(feature.GetBoundingBox().MinX, feature.GetBoundingBox().MinY));
            Point max = viewport.WorldToScreen(new Point(feature.GetBoundingBox().MaxX, feature.GetBoundingBox().MaxY));

            Rectangle destination = RoundToPixel(new RectangleF((float)min.X, (float)max.Y, (float)(max.X - min.X), (float)(min.Y - max.Y)));

            graphics.DrawImage(bitmap,
                               destination,
                               0, 0, bitmap.Width, bitmap.Height,
                               GraphicsUnit.Pixel,
                               new ImageAttributes());

            if (DeveloperTools.DeveloperMode)
            {
                var font    = new System.Drawing.Font("Arial", 12);
                var message = (GC.GetTotalMemory(true) / 1000).ToString(CultureInfo.InvariantCulture) + " KB";
                graphics.DrawString(message, font, new SolidBrush(Color.Black), 10f, 10f);
            }

            bitmap.Dispose();
        }
Beispiel #12
0
        private static RectangleF WorldToView(Extent extent, IViewport viewport)
        {
            Point min = viewport.WorldToScreen(new Point(extent.MinX, extent.MinY));
            Point max = viewport.WorldToScreen(new Point(extent.MaxX, extent.MaxY));

            return(new RectangleF((float)min.X, (float)max.Y,
                                  (float)(max.X - min.X), (float)(min.Y - max.Y)));
        }
Beispiel #13
0
 private static BoundingBox WorldToScreen(IViewport viewport, BoundingBox boundingBox)
 {
     var box = new BoundingBox
         {
             Min = viewport.WorldToScreen(boundingBox.Min),
             Max = viewport.WorldToScreen(boundingBox.Max)
         };
     return box;
 }
Beispiel #14
0
 private static XamlMedia.Geometry ConvertRaster(BoundingBox boundingBox, IViewport viewport)
 {
     return(new XamlMedia.RectangleGeometry
     {
         Rect = RoundToPixel(new Rect(
                                 viewport.WorldToScreen(boundingBox.Min).ToXaml(),
                                 viewport.WorldToScreen(boundingBox.Max).ToXaml()))
     });
 }
Beispiel #15
0
        private static BoundingBox WorldToScreen(IViewport viewport, BoundingBox boundingBox)
        {
            var box = new BoundingBox
            {
                Min = viewport.WorldToScreen(boundingBox.Min),
                Max = viewport.WorldToScreen(boundingBox.Max)
            };

            return(box);
        }
Beispiel #16
0
 private static BoundingBox WorldToScreen(IViewport viewport, BoundingBox boundingBox)
 {
     var first = viewport.WorldToScreen(boundingBox.Min);
     var second = viewport.WorldToScreen(boundingBox.Max);
     return new BoundingBox
         (
             Math.Min(first.X, second.X),
             Math.Min(first.Y, second.Y),
             Math.Max(first.X, second.X),
             Math.Max(first.Y, second.Y)
         );
 }
Beispiel #17
0
        private static BoundingBox WorldToScreen(IViewport viewport, BoundingBox boundingBox)
        {
            var first  = viewport.WorldToScreen(boundingBox.Min);
            var second = viewport.WorldToScreen(boundingBox.Max);

            return(new BoundingBox
                   (
                       Math.Min(first.X, second.X),
                       Math.Min(first.Y, second.Y),
                       Math.Max(first.X, second.X),
                       Math.Max(first.Y, second.Y)
                   ));
        }
Beispiel #18
0
        public static void Draw(SKCanvas canvas, IViewport viewport, IStyle style, IFeature feature,
                                IDictionary <int, SKBitmapInfo> symbolBitmapCache)
        {
            var point       = feature.Geometry as Point;
            var destination = viewport.WorldToScreen(point);

            var labelStyle = style as LabelStyle;

            if (labelStyle != null)
            {
                LabelRenderer.Draw(canvas, labelStyle, labelStyle.GetLabelText(feature),
                                   (float)destination.X, (float)destination.Y);
            }
            var symbolStyle = style as SymbolStyle;

            if (symbolStyle != null)
            {
                if (symbolStyle.BitmapId >= 0)
                {
                    DrawPointWithSymbolStyle(canvas, symbolStyle, destination, symbolBitmapCache);
                }
                else
                {
                    DrawPointWithVectorStyle(canvas, (VectorStyle)style, destination, symbolStyle.SymbolType);
                }
            }
            else if (style is VectorStyle)
            {
                DrawPointWithVectorStyle(canvas, (VectorStyle)style, destination);
            }
        }
Beispiel #19
0
        // todo:
        // try to remove the feature argument. LabelStyle should already contain the feature specific text
        // The visible feature iterator should create this LabelStyle
        public static void Draw(SKCanvas canvas, IViewport viewport, IStyle style, IFeature feature, 
            IGeometry geometry, IDictionary<int, SKBitmapInfo> symbolBitmapCache)
        {
            var point = geometry as Point;
            var destination = viewport.WorldToScreen(point);

            if (style is LabelStyle)              // case 1) LabelStyle
            {
                LabelRenderer.Draw(canvas, (LabelStyle) style, feature, (float) destination.X, (float) destination.Y);
            }
            else if (style is SymbolStyle)
            {
                var symbolStyle = (SymbolStyle)style;

                if ( symbolStyle.BitmapId >= 0)   // case 2) Bitmap Style
                {
                    DrawPointWithBitmapStyle(canvas, symbolStyle, destination, symbolBitmapCache);
                }
                else                              // case 3) SymbolStyle without bitmap
                {
                    DrawPointWithSymbolStyle(canvas, symbolStyle, destination, symbolStyle.SymbolType);
                }
            }
            else if (style is VectorStyle)        // case 4) VectorStyle
            {
                DrawPointWithVectorStyle(canvas, (VectorStyle) style, destination);
            }
            else
            {
                throw new Exception($"Style of type '{style.GetType()}' is not supported for points");
            }
        }
 internal static IEnumerable<Point> WorldToScreen(LineString linearRing, IViewport viewport)
 {
     var v = new Point[linearRing.Vertices.Count];
     for (int i = 0; i < linearRing.Vertices.Count; i++)
         v[i] = viewport.WorldToScreen(linearRing.Vertices[i]);
     return v;
 }
Beispiel #21
0
        private static void RenderVectorPoint(Graphics graphics, Point point, IStyle style, IViewport viewport, StyleContext context)
        {
            var symbolStyle = ToSymbolStyle(style);

            if (symbolStyle.Fill == null)
            {
                return;
            }

            var symbolscale = symbolStyle.SymbolScale;
            var offset      = symbolStyle.SymbolOffset.ToGdi();
            var rotation    = symbolStyle.SymbolRotation;
            var dest        = ConvertPoint(viewport.WorldToScreen(point));

            var width  = symbolStyle.Width * symbolscale;
            var height = symbolStyle.Height * symbolscale;

            graphics.TranslateTransform(dest.X, dest.Y);
            graphics.RotateTransform((float)rotation);
            graphics.TranslateTransform(offset.X, -offset.Y);
            graphics.TranslateTransform((int)(-width / 2.0), (int)(-height / 2.0));

            DrawSymbol(graphics, symbolStyle, context);
            graphics.ResetTransform();
        }
Beispiel #22
0
        // todo:
        // try to remove the feature argument. LabelStyle should already contain the feature specific text
        // The visible feature iterator should create this LabelStyle
        public static void Draw(SKCanvas canvas, IViewport viewport, IStyle style, IFeature feature,
                                IGeometry geometry, SymbolCache symbolCache)
        {
            var point       = geometry as Point;
            var destination = viewport.WorldToScreen(point);

            if (style is LabelStyle)              // case 1) LabelStyle
            {
                LabelRenderer.Draw(canvas, (LabelStyle)style, feature, (float)destination.X, (float)destination.Y);
            }
            else if (style is SymbolStyle)
            {
                var symbolStyle = (SymbolStyle)style;

                if (symbolStyle.BitmapId >= 0)    // case 2) Bitmap Style
                {
                    DrawPointWithBitmapStyle(canvas, symbolStyle, destination, symbolCache);
                }
                else                              // case 3) SymbolStyle without bitmap
                {
                    DrawPointWithSymbolStyle(canvas, symbolStyle, destination, symbolStyle.SymbolType);
                }
            }
            else if (style is VectorStyle)        // case 4) VectorStyle
            {
                DrawPointWithVectorStyle(canvas, (VectorStyle)style, destination);
            }
            else
            {
                throw new Exception($"Style of type '{style.GetType()}' is not supported for points");
            }
        }
Beispiel #23
0
        public static CATextLayer RenderLabel(Mapsui.Geometries.Point point, LabelStyle style, IFeature feature, IViewport viewport, string text)
        {
            // Offset stackOffset,
            Mapsui.Geometries.Point p = viewport.WorldToScreen(point);
            //var pointF = new xPointF((float)p.X, (float)p.Y);
            var label = new CATextLayer();


            var aString = new MonoTouch.Foundation.NSAttributedString(text,
                                                                      new MonoTouch.CoreText.CTStringAttributes()
            {
                Font = new MonoTouch.CoreText.CTFont("ArialMT", 10)
            });

            var frame = new RectangleF(new System.Drawing.Point((int)p.X, (int)p.Y), GetSizeForText(0, aString));

            //label.Frame = frame;
            //frame.Width = (float)(p2.X - p1.X);// + margin);
            //frame.Height = (float)(p1.Y - p2.Y);

            label.FontSize        = 10;
            label.ForegroundColor = new MonoTouch.CoreGraphics.CGColor(0, 0, 255, 150);
            label.BackgroundColor = new MonoTouch.CoreGraphics.CGColor(255, 0, 2, 150);
            label.String          = text;

            label.Frame = frame;

            Console.WriteLine("Pos " + label.Frame.X + ":" + label.Frame.Y + " w " + label.Frame.Width + " h " + label.Frame.Height);

            // = MonoTouch.UIKit.UIScreen.MainScreen.Scale;
            //	label.ContentsScale = scale;

            return(label);
        }
Beispiel #24
0
 private static void WorldToScreen(IViewport viewport, PointF[] points)
 {
     for (var i = 0; i < points.Length; i++)
     {
         var point = viewport.WorldToScreen(points[i].X, points[i].Y);
         points [i] = new PointF((float)point.X, (float)point.Y);
     }
 }
Beispiel #25
0
        public static void DrawRaster(Graphics graphics, IRaster raster, IViewport viewport)
        {
            var imageAttributes = new ImageAttributes();

            var bitmap = new Bitmap(raster.Data);

            Point min = viewport.WorldToScreen(new Point(raster.GetBoundingBox().MinX, raster.GetBoundingBox().MinY));
            Point max = viewport.WorldToScreen(new Point(raster.GetBoundingBox().MaxX, raster.GetBoundingBox().MaxY));

            Rectangle destination = RoundToPixel(new RectangleF((float)min.X, (float)max.Y, (float)(max.X - min.X), (float)(min.Y - max.Y)));

            graphics.DrawImage(bitmap,
                               destination,
                               0, 0, bitmap.Width, bitmap.Height,
                               GraphicsUnit.Pixel,
                               imageAttributes);
        }
Beispiel #26
0
        public static void Draw(SKCanvas canvas, IViewport viewport, IStyle style, IFeature feature, IGeometry geometry,
                                float opacity)
        {
            if (style is LabelStyle labelStyle)
            {
                var worldCenter = geometry.BoundingBox.Centroid;
                var center      = viewport.WorldToScreen(worldCenter);
                LabelRenderer.Draw(canvas, labelStyle, feature, (float)center.X, (float)center.Y, opacity);
            }
            else
            {
                var lineString = ((LineString)geometry).Vertices;

                float lineWidth = 1;
                var   lineColor = new Color();

                var     vectorStyle      = style as VectorStyle;
                var     strokeCap        = PenStrokeCap.Butt;
                var     strokeJoin       = StrokeJoin.Miter;
                var     strokeMiterLimit = 4f;
                var     strokeStyle      = PenStyle.Solid;
                float[] dashArray        = null;

                if (vectorStyle != null)
                {
                    lineWidth        = (float)vectorStyle.Line.Width;
                    lineColor        = vectorStyle.Line.Color;
                    strokeCap        = vectorStyle.Line.PenStrokeCap;
                    strokeJoin       = vectorStyle.Line.StrokeJoin;
                    strokeMiterLimit = vectorStyle.Line.StrokeMiterLimit;
                    strokeStyle      = vectorStyle.Line.PenStyle;
                    dashArray        = vectorStyle.Line.DashArray;
                }

                var path = lineString.ToSkiaPath(viewport, canvas.LocalClipBounds);

                using (var paint = new SKPaint {
                    IsAntialias = true
                })
                {
                    paint.IsStroke    = true;
                    paint.StrokeWidth = lineWidth;
                    paint.Color       = lineColor.ToSkia(opacity);
                    paint.StrokeCap   = strokeCap.ToSkia();
                    paint.StrokeJoin  = strokeJoin.ToSkia();
                    paint.StrokeMiter = strokeMiterLimit;
                    if (strokeStyle != PenStyle.Solid)
                    {
                        paint.PathEffect = strokeStyle.ToSkia(lineWidth, dashArray);
                    }
                    else
                    {
                        paint.PathEffect = null;
                    }
                    canvas.DrawPath(path, paint);
                }
            }
        }
 private static List<Point> WorldToScreen(IViewport viewport, IEnumerable<Point> points)
 {
     var result = new List<Point>();
     foreach (var point in points)
     {
         result.Add(viewport.WorldToScreen(point.X, point.Y));
     }
     return result;
 }
 private static void WorldToScreen(IViewport viewport, float[] points)
 {
     for (var i = 0; i < points.Length / 2; i++)
     {
         var point = viewport.WorldToScreen(points[i * 2], points[i * 2 + 1]);
         points[i * 2]     = (float)point.X;
         points[i * 2 + 1] = (float)point.Y;
     }
 }
        private static UIBezierPath CreatePathFigure(LineString linearRing, IViewport viewport)
        {
            var pathFigure = new UIBezierPath();
            var start      = linearRing.Vertices[0];
            var startPos   = viewport.WorldToScreen(start);

            pathFigure.MoveTo(ToUIKit(startPos));

            for (int i = 1; i < linearRing.Vertices.Count; i++)
            {
                var pos       = linearRing.Vertices[i];
                var screenPos = viewport.WorldToScreen(pos);
                pathFigure.AddLineTo(ToUIKit(screenPos));
            }
            pathFigure.ClosePath();

            return(pathFigure);
        }
 private static void WorldToScreen(IViewport viewport, float[] points)
 {
     for (var i = 0; i < points.Length / 2; i++)
     {
         var point = viewport.WorldToScreen(points[i * 2], points[i * 2 + 1]);
         points[i * 2] = (float)point.X;
         points[i * 2 + 1] = (float)point.Y;
     }
 }
Beispiel #31
0
        public static void Draw(Canvas canvas, IViewport viewport, IStyle style, IFeature feature)
        {
            var point      = feature.Geometry as Point;
            var dest       = viewport.WorldToScreen(point);
            var symbolSize = (float)SymbolStyle.DefaultHeight;
            var symbolType = SymbolType.Ellipse;

            var symbolStyle = style as SymbolStyle;

            if (symbolStyle != null)
            {
                if (symbolStyle.BitmapId >= 0)
                {
                    // Bitmap
                    if (!feature.RenderedGeometry.ContainsKey(style))
                    {
                        var imageStream = BitmapRegistry.Instance.Get(symbolStyle.BitmapId);
                        imageStream.Position = 0;
                        var androidBitmap = BitmapFactory.DecodeStream(imageStream);
                        feature.RenderedGeometry[style] = androidBitmap;
                    }

                    var bitmap           = (Bitmap)feature.RenderedGeometry[style];
                    var halfWidth        = bitmap.Width / 2;
                    var halfHeight       = bitmap.Height / 2;
                    var dstRectForRender = new RectF((float)dest.X - halfWidth, (float)dest.Y - halfHeight, (float)dest.X + halfWidth, (float)dest.Y + halfHeight);
                    canvas.DrawBitmap(bitmap, null, dstRectForRender, null);
                    return;
                }
                symbolType = symbolStyle.SymbolType;
                if (symbolStyle.SymbolScale > 0)
                {
                    symbolSize = (float)symbolStyle.SymbolScale * symbolSize;
                }
            }

            // Drawing
            var paints = style.ToAndroid();

            if (symbolType == SymbolType.Ellipse)
            {
                foreach (var paint in paints)
                {
                    canvas.DrawCircle((int)dest.X, (int)dest.Y, symbolSize, paint);
                    paint.Dispose();
                }
            }
            else
            {
                foreach (var paint in paints)
                {
                    canvas.DrawRect(-(float)SymbolStyle.DefaultWidth, (float)SymbolStyle.DefaultHeight, (float)SymbolStyle.DefaultWidth, -(float)SymbolStyle.DefaultHeight, paint);
                    paint.Dispose();
                }
            }
        }
        private static List <Point> WorldToScreen(IViewport viewport, IEnumerable <Point> points)
        {
            var result = new List <Point>();

            foreach (var point in points)
            {
                result.Add(viewport.WorldToScreen(point.X, point.Y));
            }
            return(result);
        }
Beispiel #33
0
        internal static IEnumerable <Point> WorldToScreen(LineString linearRing, IViewport viewport)
        {
            var v = new Point[linearRing.Vertices.Count];

            for (int i = 0; i < linearRing.Vertices.Count; i++)
            {
                v[i] = viewport.WorldToScreen(linearRing.Vertices[i]);
            }
            return(v);
        }
        private static UIElement RenderBox(BoundingBox box, IViewport viewport)
        {
            const int margin = 32;
            const int halfMargin = margin / 2;

            var p1 = viewport.WorldToScreen(box.Min);
            var p2 = viewport.WorldToScreen(box.Max);

            var rectangle = new Rectangle();
            rectangle.Width = p2.X - p1.X + margin;
            rectangle.Height = p1.Y - p2.Y + margin;
            Canvas.SetLeft(rectangle, p1.X - halfMargin);
            Canvas.SetTop(rectangle, p2.Y - halfMargin);

            rectangle.Stroke = new SolidColorBrush(Colors.White);
            rectangle.StrokeThickness = 2;

            return rectangle;
        }
		public static UIBezierPath ToUIKit(this IEnumerable<Point> points, IViewport viewport)
		{
			var pathGeometry = new UIBezierPath ();
		    points = points.ToList();
			if (points.Any()) {

				var first = points.FirstOrDefault ();
				var start = viewport.WorldToScreen (first);

				pathGeometry.MoveTo(ToUIKit (start));

				for (int i = 1; i < points.Count (); i++) {
					var point = points.ElementAt (i);
					var p = viewport.WorldToScreen (point);
					pathGeometry.AddLineTo (new CGPoint ((float)p.X, (float)p.Y));
				}
			}
			return pathGeometry;
		}
Beispiel #36
0
        public static void DrawPoint(Graphics graphics, Point point, Styles.IStyle style, IViewport viewport)
        {
            var vectorStyle = (Styles.SymbolStyle)style;

            if (vectorStyle.Symbol == null)
            {
                throw  new ArgumentException("No bitmap symbol set in Gdi rendering");                             //todo: allow vector symbol
            }
            Bitmap symbol      = vectorStyle.Symbol.Convert();
            var    symbolscale = vectorStyle.SymbolScale;
            PointF offset      = vectorStyle.SymbolOffset.Convert();
            var    rotation    = vectorStyle.SymbolRotation;

            if (point == null)
            {
                return;
            }
            if (symbol == null)
            {
                symbol = DefaultSymbol;
            }

            PointF dest = ConvertPoint(viewport.WorldToScreen(point));

            if (rotation != 0 && !double.IsNaN(rotation))
            {
                graphics.TranslateTransform(dest.X, dest.Y);
                graphics.RotateTransform((float)rotation);
                graphics.TranslateTransform((int)(-symbol.Width / 2.0), (int)(-symbol.Height / 2.0));
                if (symbolscale == 1f)
                {
                    graphics.DrawImageUnscaled(symbol, (int)(dest.X - symbol.Width / 2.0 + offset.X), (int)(dest.Y - symbol.Height / 2.0 + offset.Y));
                }
                else
                {
                    var width  = symbol.Width * symbolscale;
                    var height = symbol.Height * symbolscale;
                    graphics.DrawImage(symbol, (int)(dest.X - width / 2 + offset.X * symbolscale), (int)(dest.Y - height / 2 + offset.Y * symbolscale), (float)width, (float)height);
                }
            }
            else
            {
                if (symbolscale == 1f)
                {
                    graphics.DrawImageUnscaled(symbol, (int)(dest.X - symbol.Width / 2.0 + offset.X), (int)(dest.Y - symbol.Height / 2.0 + offset.Y));
                }
                else
                {
                    var width  = symbol.Width * symbolscale;
                    var height = symbol.Height * symbolscale;
                    graphics.DrawImage(symbol, (int)(dest.X - width / 2 + offset.X * symbolscale), (int)(dest.Y - height / 2 + offset.Y * symbolscale), (float)width, (float)height);
                }
            }
        }
Beispiel #37
0
        private static UIElement RenderBox(BoundingBox box, IViewport viewport)
        {
            const int margin     = 32;
            const int halfMargin = margin / 2;

            var p1 = viewport.WorldToScreen(box.Min);
            var p2 = viewport.WorldToScreen(box.Max);

            var rectangle = new Rectangle();

            rectangle.Width  = p2.X - p1.X + margin;
            rectangle.Height = p1.Y - p2.Y + margin;
            Canvas.SetLeft(rectangle, p1.X - halfMargin);
            Canvas.SetTop(rectangle, p2.Y - halfMargin);

            rectangle.Stroke          = new SolidColorBrush(Colors.White);
            rectangle.StrokeThickness = 2;

            return(rectangle);
        }
Beispiel #38
0
        private static CALayer RenderBox(BoundingBox box, IViewport viewport)
        {
            const int margin = 32;

            var p1 = viewport.WorldToScreen(box.Min);
            var p2 = viewport.WorldToScreen(box.Max);

            var rectangle = new RectangleF {
                Width = (float)(p2.X - p1.X + margin), Height = (float)(p1.Y - p2.Y + margin)
            };

            var canvas = new CALayer
            {
                Frame       = rectangle,
                BorderColor = new MonoTouch.CoreGraphics.CGColor(0, 0, 0, 1),
                BorderWidth = 2
            };

            return(canvas);
        }
Beispiel #39
0
        private static PointF[] WorldToScreen2(IViewport viewport, PointF[] points)
        {
            var newPoints = new PointF[points.Length];

            for (var i = 0; i < points.Length; i++)
            {
                var point = viewport.WorldToScreen(points[i].X, points[i].Y);
                newPoints [i] = new PointF((float)point.X, (float)point.Y);
            }

            return(newPoints);
        }
Beispiel #40
0
        public static void Draw(SKCanvas canvas, IViewport viewport, IStyle style, IFeature feature, IGeometry geometry,
                                float opacity)
        {
            if (style is LabelStyle)
            {
                var worldCenter = geometry.GetBoundingBox().GetCentroid();
                var center      = viewport.WorldToScreen(worldCenter);
                LabelRenderer.Draw(canvas, (LabelStyle)style, feature, (float)center.X, (float)center.Y, opacity);
            }
            else
            {
                var polygon = (Polygon)geometry;

                float lineWidth   = 1;
                var   lineColor   = Color.Black;       // default
                var   fillColor   = Color.Gray;        // default
                var   strokeCap   = PenStrokeCap.Butt; // default
                var   strokeStyle = PenStyle.Solid;    // default

                var vectorStyle = style as VectorStyle;

                if (vectorStyle != null)
                {
                    lineWidth   = (float)vectorStyle.Outline.Width;
                    lineColor   = vectorStyle.Outline.Color;
                    strokeCap   = vectorStyle.Outline.PenStrokeCap;
                    strokeStyle = vectorStyle.Outline.PenStyle;

                    fillColor = vectorStyle.Fill?.Color;
                }

                using (var path = ToSkia(viewport, polygon))
                {
                    using (var paint = new SKPaint())
                    {
                        paint.IsAntialias = true;
                        paint.StrokeWidth = lineWidth;

                        paint.Style = SKPaintStyle.Fill;
                        paint.Color = fillColor.ToSkia(opacity);
                        canvas.DrawPath(path, paint);
                        paint.Style     = SKPaintStyle.Stroke;
                        paint.Color     = lineColor.ToSkia(opacity);
                        paint.StrokeCap = strokeCap.ToSkia();
                        if (strokeStyle != PenStyle.Solid)
                        {
                            paint.PathEffect = strokeStyle.ToSkia(lineWidth);
                        }
                        canvas.DrawPath(path, paint);
                    }
                }
            }
        }
        public static UIBezierPath ToUIKit(this IEnumerable <Point> points, IViewport viewport)
        {
            var pathGeometry = new UIBezierPath();

            points = points.ToList();
            if (points.Any())
            {
                var first = points.FirstOrDefault();
                var start = viewport.WorldToScreen(first);

                pathGeometry.MoveTo(ToUIKit(start));

                for (int i = 1; i < points.Count(); i++)
                {
                    var point = points.ElementAt(i);
                    var p     = viewport.WorldToScreen(point);
                    pathGeometry.AddLineTo(new CGPoint((float)p.X, (float)p.Y));
                }
            }
            return(pathGeometry);
        }
Beispiel #42
0
		private static CALayer RenderBox(BoundingBox box, IViewport viewport)
		{
			//const int margin = 32;
			//const int halfMargin = margin / 2;

			var p1 = viewport.WorldToScreen(box.Min);
			var p2 = viewport.WorldToScreen(box.Max);

			var rectangle = new RectangleF();
			rectangle.Width = (float)(p2.X - p1.X);// + margin);
			rectangle.Height = (float)(p1.Y - p2.Y);// + margin);

			var v = GeometryRenderer.ConvertBoundingBox (box, viewport);

			var canvas = new CALayer ();

			canvas.Frame = v;
			canvas.BorderColor = new MonoTouch.CoreGraphics.CGColor (255, 255, 255, 1);
			canvas.BorderWidth = 2;

			return canvas;
		}
Beispiel #43
0
        public static UIElement RenderLabel(Geometries.Point position, LabelStyle labelStyle, IViewport viewport,
                                            string labelText)
        {
            var screenPosition  = viewport.WorldToScreen(position);
            var windowsPosition = screenPosition.ToXaml();

            // Set some defaults which should be configurable someday
            const double witdhMargin  = 3.0;
            const double heightMargin = 0.0;

            var textblock = new TextBlock
            {
                Text       = labelText,
                Foreground = new SolidColorBrush(labelStyle.ForeColor.ToXaml()),
                FontFamily = new FontFamily(labelStyle.Font.FontFamily),
                FontSize   = labelStyle.Font.Size,
                Margin     = new Thickness(witdhMargin, heightMargin, witdhMargin, heightMargin),
            };

            // TODO: Halo is not supported by WPF, but we CAN do an outer glow-like effect...
            if (labelStyle.Halo != null)
            {
                System.Windows.Media.Effects.DropShadowEffect haloEffect = new System.Windows.Media.Effects.DropShadowEffect();
                haloEffect.ShadowDepth = 0;
                haloEffect.Color       = labelStyle.Halo.Color.ToXaml();
                haloEffect.Opacity     = haloEffect.Color.A / 255.0;
                haloEffect.BlurRadius  = labelStyle.Halo.Width * 2;
                textblock.Effect       = haloEffect;
            }

            var border = new Border
            {
                // TODO: We have no SymbolCache, so we get problems, if there is a bitmap as background
                Background   = labelStyle.BackColor.ToXaml(rotate: (float)viewport.Rotation),
                CornerRadius = new CornerRadius(4),
                Child        = textblock,
                Opacity      = labelStyle.Opacity,
            };

            DetermineTextWidthAndHeightWpf(out var textWidth, out var textHeight, labelStyle, labelText);

            var offsetX = labelStyle.Offset.IsRelative ? textWidth * labelStyle.Offset.X : labelStyle.Offset.X;
            var offsetY = labelStyle.Offset.IsRelative ? textHeight * labelStyle.Offset.Y : labelStyle.Offset.Y;

            border.SetValue(Canvas.LeftProperty, windowsPosition.X + offsetX
                            - (textWidth + 2 * witdhMargin) * (short)labelStyle.HorizontalAlignment * 0.5f);
            border.SetValue(Canvas.TopProperty, windowsPosition.Y + offsetY
                            - (textHeight + 2 * heightMargin) * (short)labelStyle.VerticalAlignment * 0.5f);

            return(border);
        }
Beispiel #44
0
        private static Label CreateLabel(IGeometry feature, string text, float rotation, int priority, LabelStyle style, IViewport viewport,
                                         Graphics g)
        {
            var gdiSize = g.MeasureString(text, style.Font.ToGdi());
            var size    = new Styles.Size {
                Width = gdiSize.Width, Height = gdiSize.Height
            };

            var position = viewport.WorldToScreen(feature.GetBoundingBox().GetCentroid());

            position.X = position.X - size.Width * (short)style.HorizontalAlignment * 0.5f;
            position.Y = position.Y - size.Height * (short)style.VerticalAlignment * 0.5f;
            if (position.X - size.Width > viewport.Width || position.X + size.Width < 0 ||
                position.Y - size.Height > viewport.Height || position.Y + size.Height < 0)
            {
                return(null);
            }

            Label label;

            if (!style.CollisionDetection)
            {
                label = new Label(text, position, rotation, priority, null, style);
            }
            else
            {
                //Collision detection is enabled so we need to measure the size of the string
                label = new Label(text, position, rotation, priority,
                                  new LabelBox(position.X - size.Width * 0.5f - style.CollisionBuffer.Width,
                                               position.Y + size.Height * 0.5f + style.CollisionBuffer.Height,
                                               size.Width + 2f * style.CollisionBuffer.Width,
                                               size.Height + style.CollisionBuffer.Height * 2f), style);
            }

            if (!(feature is LineString))
            {
                return(label);
            }
            var line = feature as LineString;

            if (line.Length / viewport.Resolution > size.Width) //Only label feature if it is long enough
            {
                CalculateLabelOnLinestring(line, ref label, viewport);
            }
            else
            {
                return(null);
            }

            return(label);
        }
Beispiel #45
0
        public static void Draw(Canvas canvas, IViewport viewport, IStyle style, IFeature feature)
        {
            var point = feature.Geometry as Point;
            var dest = viewport.WorldToScreen(point);
            var symbolSize = (float)SymbolStyle.DefaultHeight;
            var symbolType = SymbolType.Ellipse;

            var symbolStyle = style as SymbolStyle;
            if (symbolStyle != null)
            {
                if (symbolStyle.BitmapId >= 0)
                {
                    // Bitmap
                    if (!feature.RenderedGeometry.ContainsKey(style))
                    {
                        var imageStream = BitmapRegistry.Instance.Get(symbolStyle.BitmapId);
                        imageStream.Position = 0;
                        var androidBitmap = BitmapFactory.DecodeStream(imageStream);
                        feature.RenderedGeometry[style] = androidBitmap;
                    }

                    var bitmap = (Bitmap)feature.RenderedGeometry[style];
                    var halfWidth = bitmap.Width / 2;
                    var halfHeight = bitmap.Height / 2;
                    var dstRectForRender = new RectF((float)dest.X - halfWidth, (float)dest.Y - halfHeight, (float)dest.X + halfWidth, (float)dest.Y + halfHeight);
                    canvas.DrawBitmap(bitmap, null, dstRectForRender, null);
                    return;
                }
                symbolType = symbolStyle.SymbolType;
                if (symbolStyle.SymbolScale > 0) symbolSize = (float)symbolStyle.SymbolScale * symbolSize;
            }

            // Drawing
            var paints = style.ToAndroid();
            if (symbolType == SymbolType.Ellipse)
            {
                foreach (var paint in paints)
                {
                    canvas.DrawCircle((int)dest.X, (int)dest.Y, symbolSize, paint);
                    paint.Dispose();
                }
            }
            else
            {
                foreach (var paint in paints)
                {
                    canvas.DrawRect(-(float)SymbolStyle.DefaultWidth, (float)SymbolStyle.DefaultHeight, (float)SymbolStyle.DefaultWidth, -(float)SymbolStyle.DefaultHeight, paint);
                    paint.Dispose();
                }
            }
        }
Beispiel #46
0
        public static void Draw(IViewport viewport, IStyle style, IFeature feature, IDictionary<int, TextureInfo> bitmapCache)
        {
            var point = feature.Geometry as Point;
            var destination = viewport.WorldToScreen(point);

            if (style is LabelStyle)
            {
                var labelStyle = (LabelStyle) style;
                LabelRenderer.Draw(labelStyle, labelStyle.GetLabelText(feature), (float)destination.X, (float)destination.Y);
            }
            var symbolStyle = style as SymbolStyle;
            if (symbolStyle != null && symbolStyle.BitmapId >= 0) DrawPointWithSymbolStyle(symbolStyle, destination, bitmapCache);
            else if (style is VectorStyle) DrawPointWithVectorStyle((VectorStyle)style, destination);
        }
        public static UIElement RenderLabel(Geometries.Point position, LabelStyle labelStyle, IViewport viewport, string labelText)
        {
            var screenPosition = viewport.WorldToScreen(position);
            var windowsPosition = screenPosition.ToXaml();

            //set some defaults which should be configurable someday
            const double witdhMargin = 3.0;
            const double heightMargin = 0.0;

            var textblock = new TextBlock
            {
                Text = labelText,
                Foreground = new SolidColorBrush(labelStyle.ForeColor.ToXaml()),

                FontFamily = new FontFamily(labelStyle.Font.FontFamily),
                FontSize = labelStyle.Font.Size,
                Margin = new Thickness(witdhMargin, heightMargin, witdhMargin, heightMargin),
                FontWeight = FontWeights.Bold
            };

            var border = new Border
                {
                    Background = new SolidColorBrush(labelStyle.BackColor == null ? Colors.Transparent : labelStyle.BackColor.Color.ToXaml()),
                    CornerRadius = new CornerRadius(4),
                    Child = textblock
                };

            double textWidth;
            double textHeight;

#if NETFX_CORE
            DetermineTextWidthAndHeightWindows8(out textWidth, out textHeight, border, textblock);
#elif SILVERLIGHT
            DetermineTextWidthAndHeightSilverlight(out textWidth, out textHeight, textblock);
#else // WPF
            DetermineTextWidthAndHeightWpf(out textWidth, out textHeight, labelStyle, labelText);
#endif
            border.SetValue(Canvas.LeftProperty, windowsPosition.X + labelStyle.Offset.X
                - (textWidth + 2 * witdhMargin) * (short)labelStyle.HorizontalAlignment * 0.5f);
            border.SetValue(Canvas.TopProperty, windowsPosition.Y + labelStyle.Offset.Y
                - (textHeight + 2 * heightMargin) * (short)labelStyle.VerticalAlignment * 0.5f);

            return border;
        }
Beispiel #48
0
        private static void RenderBitmapPoint(Graphics graphics, Point point, IViewport viewport, SymbolStyle symbolStyle)
        {
            var symbol = new Bitmap(BitmapRegistry.Instance.Get(symbolStyle.BitmapId));
            var symbolscale = symbolStyle.SymbolScale;
            var offset = symbolStyle.SymbolOffset.ToGdi();
            var rotation = symbolStyle.SymbolRotation;
            var dest = ConvertPoint(viewport.WorldToScreen(point));

            var width = symbol.Width * symbolscale;
            var height = symbol.Height * symbolscale;

            graphics.TranslateTransform(dest.X, dest.Y);
            graphics.RotateTransform((float)rotation);
            graphics.TranslateTransform(offset.X, -offset.Y);
            graphics.TranslateTransform((int)(-width / 2.0), (int)(-height / 2.0));

            graphics.DrawImage(symbol, 0, 0, (float)width, (float)height);
            graphics.ResetTransform();
        }
Beispiel #49
0
        internal static System.Drawing.PointF[] WorldToScreenGDI(LineString linearRing, IViewport viewport)
        {
            var v = new List<System.Drawing.PointF>(linearRing.Vertices.Count);
            for (int i = 0; i < linearRing.Vertices.Count; i++)
            {
                var point = viewport.WorldToScreen(linearRing.Vertices[i]);
                if (v.Count > 0 && i < linearRing.Vertices.Count - 1)
                {
                    var previousPoint = v.Last();
                    var xRange = Math.Round(previousPoint.X - point.X, 2);
                    var yRange = Math.Round(previousPoint.Y - point.Y, 2);

                    // Filter the point based on range.
                    if (!Filter(xRange) && !Filter(yRange))
                        continue;
                }
                v.Add(new System.Drawing.PointF((float)Math.Round(point.X, 2), (float)Math.Round(point.Y, 2)));
            }
            return v.ToArray();
        }
Beispiel #50
0
        public static void RenderPoint(CALayer target, CGPoint point, IStyle style, IViewport viewport, IFeature feature)
        {
            CALayer symbol;
			float rotation = 0;
			float scale = 1;

            if (style is SymbolStyle)
            {
                var symbolStyle = style as SymbolStyle;
				rotation = (float)symbolStyle.SymbolRotation;
				scale = (float)symbolStyle.SymbolScale;

				if (symbolStyle.BitmapId < 0)
                {
                    symbol = CreateSymbolFromVectorStyle(symbolStyle);
                }
                else
                {
                    symbol = CreateSymbolFromBitmap(symbolStyle);
                }

                if (symbolStyle.Outline != null)
                {
                    symbol.BorderColor = symbolStyle.Outline.Color.ToCG();
                    symbol.BorderWidth = (float)symbolStyle.Outline.Width;
                }

            }
            else if (style is VectorStyle)
            {
                var vectorStyle = (VectorStyle)style;
                symbol = CreateSymbolFromVectorStyle(vectorStyle);
            }
            else
            {
                symbol = CreateSymbolFromVectorStyle(new VectorStyle());
            }

			symbol.AffineTransform = CreateAffineTransform(rotation, viewport.WorldToScreen(point), scale);
            target.AddSublayer(symbol);
        }
Beispiel #51
0
		public static void Draw(CALayer target, IViewport viewport, IStyle style, IFeature feature)
		{
			var point = feature.Geometry as Geometries.Point;
			var dest = viewport.WorldToScreen(point);
            //var path = UIBezierPath.FromRect(new Rectangle((int)dest.X, (int)dest.Y, 20, 20));
            var path = CGPath.FromRect(new CGRect((float)dest.X, (float)dest.Y, 20, 20), CGAffineTransform.MakeIdentity());
            

            style = new VectorStyle();
            if (!feature.RenderedGeometry.Keys.Contains(style))
		    {
		        feature.RenderedGeometry[style] = CreateRenderedPoint();
		    }
            else
            {
                Console.WriteLine("test");
            }
		    var renderedGeometry = (CAShapeLayer) feature.RenderedGeometry[style];
		    renderedGeometry.Path = path;
            target.AddSublayer(renderedGeometry);
		}
Beispiel #52
0
        private static void RenderVectorPoint(Graphics graphics, Point point, IStyle style, IViewport viewport, StyleContext context)
        {
            var symbolStyle = ToSymbolStyle(style);
            if (symbolStyle.Fill == null) return;

            var symbolscale = symbolStyle.SymbolScale;
            var offset = symbolStyle.SymbolOffset.ToGdi();
            var rotation = symbolStyle.SymbolRotation;
            var dest = ConvertPoint(viewport.WorldToScreen(point));

            var width = symbolStyle.Width * symbolscale;
            var height = symbolStyle.Height * symbolscale;

            graphics.TranslateTransform(dest.X, dest.Y);
            graphics.RotateTransform((float)rotation);
            graphics.TranslateTransform(offset.X, -offset.Y);
            graphics.TranslateTransform((int)(-width / 2.0), (int)(-height / 2.0));

            DrawSymbol(graphics, symbolStyle, context);
            graphics.ResetTransform();
        }
 internal static Point WorldToScreen(Point point, IViewport viewport)
 {
     return viewport.WorldToScreen(point);
 }
        public static void DrawRaster(Graphics graphics, IRaster raster, IViewport viewport)
        {
            var imageAttributes = new ImageAttributes();

            var bitmap = new Bitmap(raster.Data);

            Point min = viewport.WorldToScreen(new Point(raster.GetBoundingBox().MinX, raster.GetBoundingBox().MinY));
            Point max = viewport.WorldToScreen(new Point(raster.GetBoundingBox().MaxX, raster.GetBoundingBox().MaxY));

            Rectangle destination = RoundToPixel(new RectangleF((float)min.X, (float)max.Y, (float)(max.X - min.X), (float)(min.Y - max.Y)));
            graphics.DrawImage(bitmap,
                destination,
                0, 0, bitmap.Width, bitmap.Height,
                GraphicsUnit.Pixel,
                imageAttributes);
        }
 private static Rect WorldToView(Extent extent, IViewport viewport)
 {
     Mapsui.Geometries.Point min = viewport.WorldToScreen(extent.MinX, extent.MinY);
     Mapsui.Geometries.Point max = viewport.WorldToScreen(extent.MaxX, extent.MaxY);
     return new Rect(min.X, max.Y, max.X - min.X, min.Y - max.Y);
 }
        public static UIElement RenderLabel(Mapsui.Geometries.Point point, Offset stackOffset, LabelStyle style, IViewport viewport, string text)
        {
            Mapsui.Geometries.Point p = viewport.WorldToScreen(point);
            var windowsPoint = new WinPoint(p.X, p.Y);

            var border = new Border();
            var textblock = new TextBlock();

            //Text
            textblock.Text = text;

            //Colors
            textblock.Foreground = new SolidColorBrush(style.ForeColor.ToXaml());
            border.Background = new SolidColorBrush(style.BackColor.Color.ToXaml());

            //Font
            textblock.FontFamily = new FontFamily(style.Font.FontFamily);
            textblock.FontSize = style.Font.Size;

            //set some defaults which should be configurable someday
            const double witdhMargin = 3.0;
            const double heightMargin = 0.0;
            textblock.Margin = new Thickness(witdhMargin, heightMargin, witdhMargin, heightMargin);
            border.CornerRadius = new CornerRadius(4);
            border.Child = textblock;
            //Offset

            var textWidth = textblock.ActualWidth;
            var textHeight = textblock.ActualHeight;
#if !SILVERLIGHT && !NETFX_CORE
            // in WPF the width and height is not calculated at this point. So we use FormattedText
            getTextWidthAndHeight(ref textWidth, ref textHeight, style, text);
#endif
            border.SetValue(Canvas.LeftProperty, windowsPoint.X + style.Offset.X + stackOffset.X - (textWidth + 2 * witdhMargin) * (short)style.HorizontalAlignment * 0.5f);
            border.SetValue(Canvas.TopProperty, windowsPoint.Y + style.Offset.Y + stackOffset.Y - (textHeight + 2 * heightMargin) * (short)style.VerticalAlignment * 0.5f);
                
            return border;
        }
Beispiel #57
0
        // todo: delete the code below if you don't know what it was supposed to do
        //public static List<IFeature> RenderStackedLabelLayer(IViewport viewport, LabelLayer layer)
        //{
        //    var renderedFeatures = new List<IFeature> ();
        //    var canvas = new CALayer ();
        //    canvas.Opacity = (float)layer.Opacity;
        //    //todo: take into account the priority
        //    var features = layer.GetFeaturesInView(viewport.Extent, viewport.Resolution);
        //    var margin = viewport.Resolution * 50;
        //    if(layer.Style != null)
        //    {
        //        var clusters = new List<Cluster>();
        //        //todo: repeat until there are no more merges
        //        ClusterFeatures(clusters, features, margin, layer.Style, viewport.Resolution);
        //        foreach (var cluster in clusters)
        //        {
        //            var feature = cluster.Features.OrderBy(f => f.Geometry.GetBoundingBox().GetCentroid().Y).FirstOrDefault();
        //            //SetFeatureOutline (feature, layer.Name, cluster.Features.Count);
        //            //var bb = RenderBox(cluster.Box, viewport);
        //            //Zorg dat dit ALTIJD decimal zelfde ISet als ViewChanged is
        //            //var feature = cluster.Features.FirstOrDefault ();
        //            var styles = feature.Styles ?? Enumerable.Empty<IStyle>();
        //            foreach (var style in styles)
        //            {
        //                if (feature.Styles != null && style.Enabled)
        //                {
        //                    var styleKey = layer.Name; //feature.GetHashCode ().ToString ();
        //                    var renderedGeometry = (feature[styleKey] != null) ? (CALayer)feature[styleKey] : null;
        //                    var labelText = layer.GetLabelText(feature);
        //                    if (renderedGeometry == null) {
        //                    //Mapsui.Geometries.Point point, Offset stackOffset, LabelStyle style, IFeature feature, IViewport viewport, string text)
        //                        renderedGeometry = RenderLabel(feature.Geometry as Mapsui.Geometries.Point,
        //                                                       style as LabelStyle, feature, viewport, labelText);
        //                        feature [styleKey] = renderedGeometry;
        //                        feature ["first"] = true;
        //                    } else {
        //                        feature ["first"] = false;
        //                    }
        //                }
        //            }
        //            renderedFeatures.Add (feature);
        //            /*
        //            Offset stackOffset = null;
        //            foreach (var feature in cluster.Features.OrderBy(f => f.Geometry.GetBoundingBox().GetCentroid().Y))
        //            {
        //                if (layerStyle is IThemeStyle) style = (layerStyle as IThemeStyle).GetStyle(feature);
        //                if ((style == null) || (style.Enabled == false) || (style.MinVisible > viewport.Resolution) || (style.MaxVisible < viewport.Resolution)) continue;
        //                if (stackOffset == null) //first time
        //                {
        //                    stackOffset = new Offset();
        //                    if (cluster.Features.Count > 1)
        //                        canvas.AddSublayer (RenderBox(cluster.Box, viewport));
        //                }
        //                else stackOffset.Y += 18; //todo: get size from text, (or just pass stack nr)
        //                if (!(style is LabelStyle)) throw new Exception("Style of label is not a LabelStyle");
        //                var labelStyle = style as LabelStyle;
        //                string labelText = layer.GetLabel(feature);
        //                var position = new Mapsui.Geometries.Point(cluster.Box.GetCentroid().X, cluster.Box.Bottom);
        //                canvas.AddSublayer(RenderLabel(position, stackOffset, labelStyle, feature, viewport, labelText));
        //            }
        //            */
        //        }
        //    }
        //    return renderedFeatures;
        //}
        private static CALayer RenderBox(BoundingBox box, IViewport viewport)
        {
            const int margin = 32;

            var p1 = viewport.WorldToScreen(box.Min);
            var p2 = viewport.WorldToScreen(box.Max);

            var rectangle = new CGRect {Width = (float) (p2.X - p1.X + margin), Height = (float) (p1.Y - p2.Y + margin)};

            var canvas = new CALayer
            {
                Frame = rectangle,
                BorderColor = new CoreGraphics.CGColor(0, 0, 0, 1),
                BorderWidth = 2
            };

            return canvas;
        }
Beispiel #58
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;
		}
        private static void CalculateLabelOnLinestring(LineString line, ref Label label, IViewport viewportTransform)
        {
            double dx, dy;

            // first find the middle segment of the line
            int midPoint = (line.Vertices.Count - 1) / 2;
            if (line.Vertices.Count > 2)
            {
                dx = line.Vertices[midPoint + 1].X - line.Vertices[midPoint].X;
                dy = line.Vertices[midPoint + 1].Y - line.Vertices[midPoint].Y;
            }
            else
            {
                midPoint = 0;
                dx = line.Vertices[1].X - line.Vertices[0].X;
                dy = line.Vertices[1].Y - line.Vertices[0].Y;
            }
            if (Math.Abs(dy - 0) < Constants.Epsilon)
                label.Rotation = 0;
            else if (Math.Abs(dx - 0) < Constants.Epsilon)
                label.Rotation = 90;
            else
            {
                // calculate angle of line
                double angle = -Math.Atan(dy / dx) + Math.PI * 0.5;
                angle *= (180d / Math.PI); // convert radians to degrees
                label.Rotation = (float)angle - 90; // -90 text orientation
            }
            double tmpx = line.Vertices[midPoint].X + (dx * 0.5);
            double tmpy = line.Vertices[midPoint].Y + (dy * 0.5);
            label.LabelPoint = viewportTransform.WorldToScreen(new Geometries.Point(tmpx, tmpy));
        }
        private static Label CreateLabel(IGeometry feature, string text, float rotation, int priority, LabelStyle style, IViewport viewport,
                                  Graphics g)
        {
            var gdiSize = g.MeasureString(text, style.Font.ToGdi());
            var size = new Styles.Size { Width = gdiSize.Width, Height = gdiSize.Height };

            var position = viewport.WorldToScreen(feature.GetBoundingBox().GetCentroid());
            position.X = position.X - size.Width * (short)style.HorizontalAlignment * 0.5f;
            position.Y = position.Y - size.Height * (short)style.VerticalAlignment * 0.5f;
            if (position.X - size.Width > viewport.Width || position.X + size.Width < 0 ||
                position.Y - size.Height > viewport.Height || position.Y + size.Height < 0)
                return null;

            Label label;

            if (!style.CollisionDetection)
                label = new Label(text, position, rotation, priority, null, style);
            else
            {
                //Collision detection is enabled so we need to measure the size of the string
                label = new Label(text, position, rotation, priority,
                                new LabelBox(position.X - size.Width * 0.5f - style.CollisionBuffer.Width,
                                             position.Y + size.Height * 0.5f + style.CollisionBuffer.Height,
                                             size.Width + 2f * style.CollisionBuffer.Width,
                                             size.Height + style.CollisionBuffer.Height * 2f), style);
            }

            if (!(feature is LineString)) return label;
            var line = feature as LineString;

            if (line.Length / viewport.Resolution > size.Width) //Only label feature if it is long enough
                CalculateLabelOnLinestring(line, ref label, viewport);
            else
                return null;

            return label;
        }