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); }
private static void RenderGeometry(CALayer target, IViewport viewport, IStyle style, IFeature feature) { if (feature.Geometry is Point) { PointRenderer2.RenderPoint(target, (Point)feature.Geometry, style, viewport, feature); } else if (feature.Geometry is LineString) { LineStringRenderer.Draw(target, viewport, style, feature); } else if (feature.Geometry is Polygon) { GeometryRenderer.RenderPolygonOnLayer(feature.Geometry as Polygon, style, viewport); } else if (feature.Geometry is MultiPolygon) { GeometryRenderer.RenderMultiPolygonOnLayer(feature.Geometry as MultiPolygon, style, viewport); } else if (feature.Geometry is IRaster) { RasterRenderer.Draw(target, viewport, style, feature); } }