public static void PositionMultiPolygon(CALayer shape, MultiPolygon multiPolygon, IStyle style, IViewport viewport) { var shapeLayer = shape as CAShapeLayer; var path = multiPolygon.ToUIKit(viewport); //var frame = ConvertBoundingBox (multiPolygon.GetBoundingBox(), viewport); shapeLayer.Path = path.CGPath; //shape.Frame = frame; /* * if (viewport.Resolution > MinResolution || viewport.Resolution < MaxResolution) { * //recalculate * var newImage = RenderMultiPolygonOnLayer (multiPolygon, style, viewport); * * shape.Contents = newImage.Contents; * shape.Frame = newImage.Frame; * * var resolution = ZoomHelper.ClipToExtremes (Resolutions, viewport.Resolution); * * MinResolution = ZoomHelper.ZoomOut (Resolutions, resolution); * MaxResolution = ZoomHelper.ZoomIn (Resolutions, resolution); * * } else { * //reposition Geometry * var frame = ConvertBoundingBox (multiPolygon.GetBoundingBox(), viewport); * var newFrame = new RectangleF (frame.X, (frame.Y), frame.Width, frame.Height); * * shape.Frame = newFrame; * //shape.Frame = frame; * } */ }
public static CALayer RenderMultiPolygonOnLayer(MultiPolygon multiPolygon, IStyle style, IViewport viewport) { var tile = new CAShapeLayer(); if (!(style is VectorStyle)) { throw new ArgumentException("Style is not of type VectorStyle"); } var vectorStyle = style as VectorStyle; var strokeAlpha = (float)vectorStyle.Outline.Color.A / 255; var fillAlpha = (float)vectorStyle.Fill.Color.A / 255; var strokeColor = new CGColor(new CGColor(vectorStyle.Outline.Color.R, vectorStyle.Outline.Color.G, vectorStyle.Outline.Color.B), strokeAlpha); var fillColor = new CGColor(new CGColor(vectorStyle.Fill.Color.R, vectorStyle.Fill.Color.G, vectorStyle.Fill.Color.B), fillAlpha); var path = multiPolygon.ToUIKit(viewport); tile.StrokeColor = strokeColor; tile.FillColor = fillColor; tile.LineWidth = (float)vectorStyle.Outline.Width; tile.Path = path.CGPath; return(tile); }
private static CALayer RenderImage(MultiPolygon multiPolygon, IStyle style, IViewport viewport) { var geom = new CAShapeLayer(); if (!(style is VectorStyle)) { throw new ArgumentException("Style is not of type VectorStyle"); } var vectorStyle = style as VectorStyle; float strokeAlpha = (float)vectorStyle.Outline.Color.A / 255; float fillAlpha = (float)vectorStyle.Fill.Color.A / 255; var strokeColor = new CGColor(new CGColor(vectorStyle.Outline.Color.R, vectorStyle.Outline.Color.G, vectorStyle.Outline.Color.B), strokeAlpha); var fillColor = new CGColor(new CGColor(vectorStyle.Fill.Color.R, vectorStyle.Fill.Color.G, vectorStyle.Fill.Color.B), fillAlpha); geom.StrokeColor = strokeColor; geom.FillColor = fillColor; geom.LineWidth = (float)vectorStyle.Outline.Width; var bbRect = GeometryRenderer.ConvertBoundingBox(multiPolygon.GetBoundingBox(), viewport); var offset = new System.Drawing.Point((int)bbRect.GetMinX(), (int)bbRect.GetMinY()); GeometryExtension.OffSet = offset; var path = multiPolygon.ToUIKit(viewport); var frame = new RectangleF(0, 0, (int)(bbRect.GetMaxX() - bbRect.GetMinX()), (int)(bbRect.GetMaxY() - bbRect.GetMinY())); var size = frame.Size; geom.Path = path.CGPath; UIGraphics.BeginImageContext(size); var context = UIGraphics.GetCurrentContext(); context.SetBlendMode(CGBlendMode.Multiply); geom.RenderInContext(context); var image = UIGraphics.GetImageFromCurrentImageContext(); var imageTile = new CALayer { Contents = image.CGImage, Frame = frame }; return(imageTile); }