Exemplo n.º 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;
        }
Exemplo n.º 2
0
        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.ClipResolutionToExtremes (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;
            }
            */
        }
Exemplo n.º 3
0
        public static void Render(Canvas target, IViewport viewport, IEnumerable<ILayer> layers, bool rasterizing)
        {
            #if !SILVERLIGHT &&  !NETFX_CORE
            target.BeginInit();
            #endif
            target.Visibility = Visibility.Collapsed;
            foreach (var child in target.Children)
            {
                if (child is Canvas)
                {
                    (child as Canvas).Children.Clear();
                }
            }
            target.Children.Clear();

            foreach (var layer in layers)
            {
                if (!layer.Enabled) continue;
                if (layer.MinVisible > viewport.Resolution) continue;
                if(layer.MaxVisible < viewport.Resolution) continue;

                RenderLayer(target, viewport, layer, rasterizing);

            }
            target.Arrange(new Rect(0, 0, viewport.Width, viewport.Height));
            target.Visibility = Visibility.Visible;

            //DrawDebugInfo(target, layers);

            #if !SILVERLIGHT &&  !NETFX_CORE
            target.EndInit();
            #endif
        }
Exemplo n.º 4
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;
 }
Exemplo n.º 5
0
        public static void Draw(SKCanvas canvas, IViewport viewport, IStyle style, IGeometry geometry)
        {
            var polygon = (Polygon)geometry;

            float lineWidth = 1;
            var lineColor = Color.Black; // default
            var fillColor = Color.Gray; // default

            var vectorStyle = style as VectorStyle;

            if (vectorStyle != null)
            {
                lineWidth = (float) vectorStyle.Outline.Width;
                lineColor = vectorStyle.Outline.Color;
                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();
                    canvas.DrawPath(path, paint);
                    paint.Style = SKPaintStyle.Stroke;
                    paint.Color = lineColor.ToSkia();
                    canvas.DrawPath(path, paint);
                }
            }
        }
Exemplo n.º 6
0
		public void Tick (IViewport viewport, AGS.API.Size roomSize, AGS.API.Size virtualResoution, bool resetPosition)
		{
			IObject target = Target == null ? null : Target();
			if (!Enabled || target == null) return;

			setScale(target, viewport, resetPosition);

			//todo: Allow control over which point in the target to follow
			float targetX = target.X;//target.CenterPoint == null ? target.X : target.CenterPoint.X;
			float targetY = target.Y;//target.CenterPoint == null ? target.Y : target.CenterPoint.Y;
			float maxResolutionX = virtualResoution.Width / viewport.ScaleX;
			float maxResolutionY = virtualResoution.Height / viewport.ScaleY;
			targetX = getTargetPos(targetX, roomSize.Width, maxResolutionX);
			targetY = getTargetPos(targetY, roomSize.Height, maxResolutionY);
			if (resetPosition)
			{
				viewport.X = targetX;
				viewport.Y = targetY;
				return;
			}
			float newX = getPos (viewport.X, targetX, StartSpeedX, 0.1f, ref _speedX);
			float newY = getPos (viewport.Y, targetY, StartSpeedY, 0.1f, ref _speedY);
			viewport.X = clamp(newX, roomSize.Width, maxResolutionX);
			viewport.Y = clamp(newY, roomSize.Height, maxResolutionY);
		}
Exemplo n.º 7
0
        public static void Draw(Canvas canvas, IViewport viewport, IStyle style, IFeature feature)
        {
            try
            {
                if (!feature.RenderedGeometry.ContainsKey(style)) feature.RenderedGeometry[style] = ToAndroidBitmap(feature.Geometry);
                var bitmap = (AndroidGraphics.Bitmap)feature.RenderedGeometry[style];
                
                var dest = WorldToScreen(viewport, feature.Geometry.GetBoundingBox());
                dest = new BoundingBox(
                    dest.MinX,
                    dest.MinY,
                    dest.MaxX,
                    dest.MaxY);

                var destination = RoundToPixel(dest);
                using (var paint = new Paint())
                {
                    canvas.DrawBitmap(bitmap, new Rect(0, 0, bitmap.Width, bitmap.Height), destination, paint);
                }

                DrawOutline(canvas, style, destination);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

        }
Exemplo n.º 8
0
        public static void DrawPolygon(Graphics graphics, Polygon pol, Brush brush, Pen pen, IViewport viewport)
        {
            if (pol.ExteriorRing == null) return;
            if (pol.ExteriorRing.Vertices.Count <= 2) return;

            //Use a graphics path instead of DrawPolygon. DrawPolygon has a problem with several interior holes
            var gp = new GraphicsPath();

            //Add the exterior polygon
            var points = GeometryRenderer.WorldToScreenGDI(pol.ExteriorRing, viewport);
            if (points.Length > 2)
                gp.AddPolygon(points);
            //Add the interior polygons (holes)
            foreach (LinearRing linearRing in pol.InteriorRings)
            {
                var interiorPoints = GeometryRenderer.WorldToScreenGDI(linearRing, viewport);
                if (interiorPoints.Length > 2)
                    gp.AddPolygon(interiorPoints);
            }

            if (gp.PointCount == 0) return;

            // Only render inside of polygon if the brush isn't null or isn't transparent
            if (brush != null && brush != Brushes.Transparent)
                graphics.FillPath(brush, gp);
            // Create an outline if a pen style is available
            if (pen != null)
                graphics.DrawPath(pen, gp);
        }
Exemplo n.º 9
0
		public void Render (IViewport viewport, IEnumerable<ILayer> layers)
		{
			var layerNames = new List<string> ();

			_featuresForLayer = new Dictionary<string, List<IFeature>>();

			foreach (var layer in layers)
			{
				if (layer.Enabled &&
				    layer.MinVisible <= viewport.Resolution &&
				    layer.MaxVisible >= viewport.Resolution)
				{
					var layerName = RenderFeaturesForLayer(viewport, layer);
					if(layerName != null)
						layerNames.Add (layerName);
					//renderQueue.PutLayer (layer.Name, features);
				}
			}

			foreach (var kv in _featuresForLayer) {
				renderQueue.PutLayer (kv.Key, kv.Value);
			}

			renderQueue.ResetQueue (layerNames);
		}
Exemplo n.º 10
0
        public static void Draw(IViewport viewport, IStyle style, IFeature feature)
        {
            var lineString = ((LineString)feature.Geometry).Vertices;

            float lineWidth = 1;
            var lineColor = Color.White;

            var vectorStyle = style as VectorStyle;

            if (vectorStyle != null)
            {
                lineWidth = (float)vectorStyle.Line.Width;
                lineColor = vectorStyle.Line.Color;
            }

            float[] points = ToOpenTK(lineString);
            WorldToScreen(viewport, points);

            GL.LineWidth(lineWidth);
            GL.Color4((byte)lineColor.R, (byte)lineColor.G, (byte)lineColor.B, (byte)lineColor.A);
            GL.EnableClientState(All.VertexArray);
            GL.VertexPointer(2, All.Float, 0, points);
            GL.DrawArrays(All.Lines, 0, points.Length / 2);
            GL.DisableClientState(All.VertexArray);
        }
Exemplo n.º 11
0
		private static string RenderFeaturesForLayer(IViewport viewport, ILayer layer)
		{
			if (layer.Enabled == false) return null;

			/*
			if (layer is BasicLayer) {
				var renderedFeatures = SymbolRenderer.RenderStackedLabelLayer (viewport, layer as BasicLayer);

				if (renderedFeatures != null && renderedFeatures.Count > 0){
					renderQueue.PutLayer (layer.Name, renderedFeatures);
					return layer.Name;
				}
			}
			else*/ if (layer is LabelLayer) {
				var renderedFeatures = LabelRenderer.RenderStackedLabelLayer (viewport, layer as LabelLayer);

				if (renderedFeatures != null && renderedFeatures.Count > 0){
					renderQueue.PutLayer (layer.Name, renderedFeatures);
					return layer.Name;
				}
			} else {
				var renderedFeatures = RenderVectorLayerFeatures (viewport, layer);// new List<CALayer> ();

				if (renderedFeatures != null && renderedFeatures.Count > 0){
					//renderQueue.PutLayer (layer.Name, renderedFeatures);
					_featuresForLayer.Add(layer.Name, renderedFeatures);
					return layer.Name;
				}
			}

			return null;
		}
Exemplo n.º 12
0
        private static void IterateLayer(IViewport viewport, ILayer layer,
            Action<IViewport, IStyle, IFeature> callback)
        {
            var features = layer.GetFeaturesInView(viewport.Extent, viewport.RenderResolution).ToList();

            var layerStyles = layer.Style is StyleCollection ? (layer.Style as StyleCollection).ToArray() : new [] {layer.Style};
            foreach (var layerStyle in layerStyles)
            {
                var style = layerStyle; // This is the default that could be overridden by an IThemeStyle

                foreach (var feature in features)
                {
                    if (layerStyle is IThemeStyle) style = (layerStyle as IThemeStyle).GetStyle(feature);
                    if ((style == null) || (style.Enabled == false) || (style.MinVisible > viewport.RenderResolution) || (style.MaxVisible < viewport.RenderResolution)) continue;

                    callback(viewport, style, feature);
                }
            }

            foreach (var feature in features)
            {
                var featureStyles = feature.Styles ?? Enumerable.Empty<IStyle>();
                foreach (var featureStyle in featureStyles)
                {
                    if (feature.Styles != null && featureStyle.Enabled)
                    {
                        callback(viewport, featureStyle, feature);
                    }
                }
            }
        }
Exemplo n.º 13
0
        public static void Draw(SKCanvas canvas, IViewport viewport, IStyle style, IGeometry geometry)
        {
            var lineString = ((LineString) geometry).Vertices;

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

            var vectorStyle = style as VectorStyle;

            if (vectorStyle != null)
            {
                lineWidth = (float) vectorStyle.Line.Width;
                lineColor = vectorStyle.Line.Color;
            }

            var line = WorldToScreen(viewport, lineString);
            var path = ToSkia(line);

            using (var paint = new SKPaint())
            {
                paint.IsStroke = true;
                paint.StrokeWidth = lineWidth;
                paint.Color = lineColor.ToSkia();
                paint.StrokeJoin = SKStrokeJoin.Round;

                canvas.DrawPath(path, paint);
            }
        }
Exemplo n.º 14
0
		public static void Draw(CALayer target, IViewport viewport, IStyle style, IFeature feature)
		{
			const string styleKey = "laag";

			if(feature[styleKey] == null) feature[styleKey] = ToiOSBitmap(feature.Geometry);

			var bitmap = (UIImage)feature [styleKey];

			var dest = WorldToScreen(viewport, feature.Geometry.GetBoundingBox());
			dest = new BoundingBox(
				dest.MinX,
				dest.MinY,
				dest.MaxX,
				dest.MaxY);

			var destination = RoundToPixel(dest);

			var tile = new CALayer
			{
				Frame = destination,
				Contents = bitmap.CGImage,
			};
			
			target.AddSublayer(tile);
		}
Exemplo n.º 15
0
        public void Render(IViewport viewport, IEnumerable<ILayer> layers)
        {
#if !SILVERLIGHT &&  !NETFX_CORE
            target.BeginInit();
#endif
            target.Visibility = Visibility.Collapsed;
            foreach (var child in target.Children)
            {
                if (child is Canvas)
                {
                    (child as Canvas).Children.Clear();
                }
            }
            target.Children.Clear();

            foreach (var layer in layers)
            {
                if (layer.Enabled &&
                    layer.MinVisible <= viewport.Resolution &&
                    layer.MaxVisible >= viewport.Resolution)
                {
                    RenderLayer(target, viewport, layer);
                }
            }
            target.Arrange(new Rect(0, 0, viewport.Width, viewport.Height));
            target.Visibility = Visibility.Visible;
#if !SILVERLIGHT &&  !NETFX_CORE
            target.EndInit();
#endif
        }
Exemplo n.º 16
0
        public void Render(IViewport viewport, IEnumerable<ILayer> layers)
        {
            if (targetBitmap == null ||
                targetBitmap.PixelWidth != (int)target.ActualWidth ||
                targetBitmap.PixelHeight != (int)target.ActualHeight)
            {
                target.Arrange(new Rect(0, 0, viewport.Width, viewport.Height));
                if (target.ActualWidth <= 0 || target.ActualHeight <= 0) return; 
                target.Children.Clear();
                target.Children.Add(InitializeBitmap((int)target.ActualWidth, (int)target.ActualHeight));
            }

            targetBitmap.Clear(Colors.White);

            foreach (var layer in layers)
            {
                if (layer.Enabled &&
                    layer.MinVisible <= viewport.Resolution &&
                    layer.MaxVisible >= viewport.Resolution)
                {
                    RenderLayer(targetBitmap, viewport, layer);
                }
            }

            target.Arrange(new Rect(0, 0, viewport.Width, viewport.Height));
        }
Exemplo n.º 17
0
        public static void Draw(IViewport viewport, IStyle style, IFeature feature)
        {
            var lineString = ((Polygon)feature.Geometry).ExteriorRing.Vertices;

            float lineWidth = 1;
            var lineColor = Color.Black; // default
            // todo: var fillColor = Color.Gray; // default

            var vectorStyle = style as VectorStyle;

            if (vectorStyle != null)
            {
                lineWidth = (float)vectorStyle.Outline.Width;
                lineColor = vectorStyle.Outline.Color;
                // todo: fillColor = vectorStyle.Fill.Color;
            }

            float[] points = ToOpenTK(lineString);
            WorldToScreen(viewport, points);

            // Fill
            // Not implemented. It might be hard to draw a concave polygon with holes.

            // Outline
            GL.LineWidth(lineWidth);
            GL.Color4(lineColor.R, lineColor.G, lineColor.B, lineColor.A);
            GL.EnableClientState(All.VertexArray);
            GL.VertexPointer(2, All.Float, 0, points);
            GL.DrawArrays(All.LineLoop, 0, points.Length / 2);
            GL.DisableClientState(All.VertexArray);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Renders a label to the map.
        /// </summary>
        /// <param name="graphics">Graphics reference</param>
        /// <param name="labelPoint">Label placement</param>
        /// <param name="offset">Offset of label in screen coordinates</param>
        /// <param name="font">Font used for rendering</param>
        /// <param name="forecolor">Font forecolor</param>
        /// <param name="backcolor">Background color</param>
        /// <param name="halo">Color of halo</param>
        /// <param name="rotation">Text rotation in degrees</param>
        /// <param name="text">Text to render</param>
        /// <param name="viewport"></param>
        public static void DrawLabel(Graphics graphics, Point labelPoint, Offset offset, Styles.Font font, Styles.Color forecolor, Styles.Brush backcolor, Styles.Pen halo, double rotation, string text, IViewport viewport, StyleContext context)
        {
            SizeF fontSize = graphics.MeasureString(text, font.ToGdi(context)); //Calculate the size of the text
            labelPoint.X += offset.X; labelPoint.Y += offset.Y; //add label offset
            if (Math.Abs(rotation) > Constants.Epsilon && !double.IsNaN(rotation))
            {
                graphics.TranslateTransform((float)labelPoint.X, (float)labelPoint.Y);
                graphics.RotateTransform((float)rotation);
                graphics.TranslateTransform(-fontSize.Width / 2, -fontSize.Height / 2);
                if (backcolor != null && backcolor.ToGdi(context) != Brushes.Transparent)
                    graphics.FillRectangle(backcolor.ToGdi(context), 0, 0, fontSize.Width * 0.74f + 1f, fontSize.Height * 0.74f);
                var path = new GraphicsPath();
                path.AddString(text, new FontFamily(font.FontFamily), (int)font.ToGdi(context).Style, font.ToGdi(context).Size, new System.Drawing.Point(0, 0), null);
                if (halo != null)
                    graphics.DrawPath(halo.ToGdi(context), path);
                graphics.FillPath(new SolidBrush(forecolor.ToGdi()), path);
                //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), 0, 0);
            }
            else
            {
                if (backcolor != null && backcolor.ToGdi(context) != Brushes.Transparent)
                    graphics.FillRectangle(backcolor.ToGdi(context), (float)labelPoint.X, (float)labelPoint.Y, fontSize.Width * 0.74f + 1, fontSize.Height * 0.74f);

                var path = new GraphicsPath();

                //Arial hack
                path.AddString(text, new FontFamily("Arial"), (int)font.ToGdi(context).Style, (float)font.Size, new System.Drawing.Point((int)labelPoint.X, (int)labelPoint.Y), null);
                if (halo != null)
                    graphics.DrawPath(halo.ToGdi(context), path);
                graphics.FillPath(new SolidBrush(forecolor.ToGdi()), path);
                //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), LabelPoint.X, LabelPoint.Y);
            }
        }
Exemplo n.º 19
0
        public static UIElement RenderPoint(Point point, IStyle style, IViewport viewport)
        {
            UIElement symbol;
            var matrix = XamlMedia.Matrix.Identity;

            if (style is SymbolStyle)
            {
                var symbolStyle = style as SymbolStyle;

                if (symbolStyle.Symbol == null || symbolStyle.Symbol.Data == null)
                    symbol = CreateSymbolFromVectorStyle(symbolStyle, symbolStyle.Opacity, symbolStyle.SymbolType);
                else
                    symbol = CreateSymbolFromBitmap(symbolStyle.Symbol.Data, symbolStyle.Opacity);
                matrix = CreatePointSymbolMatrix(viewport.Resolution, symbolStyle);
            }
            else
            {
                symbol = CreateSymbolFromVectorStyle((style as VectorStyle) ?? new VectorStyle());
                MatrixHelper.ScaleAt(ref matrix, viewport.Resolution, viewport.Resolution);
            }

            MatrixHelper.Append(ref matrix, CreateTransformMatrix(point, viewport));

            symbol.RenderTransform = new XamlMedia.MatrixTransform { Matrix = matrix };

            symbol.IsHitTestVisible = false;

            return symbol;
        }
Exemplo n.º 20
0
		public void Render(IViewport viewport, Sprite sprite, Matrix view, Matrix projection, Matrix world, float xScale, float yScale, float rotation)
		{
			var buffer = BufferManager.Instance.Current;

			var image = sprite.CurrentFrame;

			
			var position = new Vector(0, 0, 0);
			var transformedPosition = Vector.Transform(position, world, view);
			var translatedPosition = Vector.Translate(transformedPosition, projection, viewport.Width, viewport.Height);
			var depthBufferAdjustedZ = -transformedPosition.Z / viewport.Camera.DepthDivisor;
			var positionOffset = (((int)translatedPosition.X)) + (((int)translatedPosition.Y) * buffer.FrameBuffer.Stride);

			var bufferSize = buffer.FrameBuffer.Stride*buffer.Height;
			var bufferZ = (UInt32)(depthBufferAdjustedZ * (float)UInt32.MaxValue);
			if( depthBufferAdjustedZ < 0f || depthBufferAdjustedZ >= 1f)
			{
				return;
			}
			
			if( xScale != 1f || yScale != 1f )
			{
				RenderScaled(buffer, positionOffset, sprite.CurrentFrame, translatedPosition, bufferSize, bufferZ, xScale, yScale);
				
			} else
			{
				RenderUnscaled(buffer,positionOffset,sprite.CurrentFrame,translatedPosition,bufferSize,bufferZ);
			}
		}
Exemplo n.º 21
0
        MemoryStream IRenderer.RenderToBitmapStream(IViewport viewport, IEnumerable<ILayer> layers, Color background)
        {
            UIImage image = null;
            var handle = new ManualResetEvent(false);

            var view = new UIView();
            view.InvokeOnMainThread(() =>
            {
                try
                {
                    view.Opaque = false;
                    view.BackgroundColor = new UIColor(background.R, background.G, background.B, background.A);
                    Render(view, viewport, layers, background);
                    image = ToImage(view, new CGRect(0, 0, (float)viewport.Width, (float)viewport.Height));
                }
                catch (Exception ex)
                {
                    Debug.WriteLine($"Exception in {nameof(IRenderer.RenderToBitmapStream)}: {ex}");
                }
                finally
                {
                    handle.Set();
                }
            });

            handle.WaitOne();
            using (var nsdata = image.AsPNG())
            {
                return new MemoryStream(nsdata.ToArray());
            }
        }
Exemplo n.º 22
0
        public static Canvas RenderLabelLayer(IViewport viewport, LabelLayer layer)
        {
            var canvas = new Canvas { Opacity = layer.Opacity };

            // todo: take into account the priority 
            var features = layer.GetFeaturesInView(viewport.Extent, viewport.Resolution).ToList();

            var layerStyles = BaseLayer.GetLayerStyles(layer);
            
            foreach (var layerStyle in layerStyles)
            {
                foreach (var feature in features)
                {
                    var style = (layerStyle is IThemeStyle) ? (layerStyle as IThemeStyle).GetStyle(feature) : layerStyle;

                    if ((style == null) || 
                        (style.Enabled == false) || 
                        (style.MinVisible > viewport.Resolution) || 
                        (style.MaxVisible < viewport.Resolution)) continue;

                    if (!(style is LabelStyle)) throw new Exception("Style of label is not a LabelStyle");
                    var labelStyle = style as LabelStyle;

                    labelStyle.Text = layer.GetLabelText(feature);

                    var postion = feature.Geometry.GetBoundingBox().GetCentroid();
                    var labelText = labelStyle.GetLabelText(feature);
                    canvas.Children.Add(SingleLabelRenderer.RenderLabel(postion, labelStyle, viewport, labelText));
                }
            }
            return canvas;
        }
Exemplo n.º 23
0
 public byte[] RenderMapAsByteArray(IViewport viewport, Map map)
 {
     Image image = RenderMapAsImage(viewport, map);
     var memoryStream = new MemoryStream();
     image.Save(memoryStream, ImageFormat.Bmp);
     return memoryStream.ToArray();
 }
Exemplo n.º 24
0
 public static void Render(Graphics graphics, IViewport viewport, Map map, AbortRenderDelegate abortRender)
 {
     foreach (var layer in map.Layers)
     {
         if (layer.Enabled &&
             layer.MinVisible <= viewport.Resolution &&
             layer.MaxVisible >= viewport.Resolution)
         {
             if (layer is LabelLayer)
             {
                 //!!!GdiLabelRenderer.Render(graphics, view, layer as LabelLayer);
             }
             else if (layer is ITileLayer)
             {
                 var tileLayer = (layer as ITileLayer);
                 GdiTileRenderer.Render(graphics, tileLayer.Schema, viewport, tileLayer.MemoryCache);
             }
             else
             {
                 RenderLayer(graphics, viewport, layer, abortRender);
             }
         }
         
         if (abortRender != null && abortRender()) return; 
     }
 }
Exemplo n.º 25
0
        public static void Draw(IViewport viewport, IStyle style, IFeature feature, IDictionary<object, TextureInfo> TextureCache, long currentIteration)
        {
            try
            {
                var raster = (IRaster)feature.Geometry;

                TextureInfo textureInfo;

                if (!TextureCache.Keys.Contains(raster))
                {
                    textureInfo = TextureHelper.LoadTexture(raster.Data);
                    TextureCache[raster] = textureInfo;
                }
                else
                {
                    textureInfo = TextureCache[raster];
                }

                textureInfo.IterationUsed = currentIteration;
                TextureCache[raster] = textureInfo;
                var destination = WorldToScreen(viewport, feature.Geometry.GetBoundingBox());
                TextureHelper.RenderTexture(textureInfo.TextureId, ToVertexArray(RoundToPixel(destination)));
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }
Exemplo n.º 26
0
		public static UIBezierPath ToUIKit(this IEnumerable<LinearRing> linearRings, IViewport viewport)
		{
			var pathGeometry = new UIBezierPath();
			foreach (var linearRing in linearRings)
				pathGeometry.AppendPath(CreatePathFigure(linearRing, viewport));
			return pathGeometry;
		}
Exemplo n.º 27
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        public void Draw(Map map, IViewport viewport, GameTime gameTime)
        {
            if (spriteBatch == null) spriteBatch = new SpriteBatch(game.GraphicsDevice);

            game.GraphicsDevice.Clear(Color.LightGray);
            spriteBatch.Begin();
            
            foreach (var layer in map.Layers)
            {
                foreach (var feature in layer.GetFeaturesInView(viewport.Extent, viewport.Resolution))
                {
                    if (feature.Geometry is IRaster)
                    {
                        var raster = (feature.Geometry as IRaster);
                        var destination = ToXna(RoundToPixel(WorldToScreen(viewport, raster.GetBoundingBox())));
                        var source = new Rectangle(0, 0, 256, 256);

                        raster.Data.Position = 0;
                        if (!feature.RenderedGeometry.Keys.Contains(new VectorStyle()))
                        {
                            feature.RenderedGeometry[new VectorStyle()] = Texture2D.FromStream(game.GraphicsDevice, raster.Data);
                        }
                        spriteBatch.Draw(feature.RenderedGeometry[new VectorStyle()] as Texture2D, destination, source, Color.White);
                    }
                }
            }
            spriteBatch.End();
        }
Exemplo n.º 28
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;
            }
        }
Exemplo n.º 29
0
		public static UIBezierPath ToUIKit(this MultiLineString multiLineString, IViewport viewport)
		{
			var group = new UIBezierPath();
			foreach (LineString lineString in multiLineString)
				group.AppendPath(ToUIKit(lineString, viewport));
			return group;
		}
Exemplo n.º 30
0
        public void RenderGeometry(MultiPolygon multiPolygon, IStyle style, IFeature feature, IViewport viewport)
        {
            if (_bgWorker == null)
                _bgWorker = new BackgroundWorker();
            /*
            while (_bgWorker.IsBusy) {
                Thread.Sleep (00001);
            }
            */
            _bgWorker.RunWorkerCompleted += (sender, e) =>
                {
                    var layer = e.Result as CALayer;

                    if (layer != null)
                    {
                        var styleKey = style.GetHashCode().ToString();
                        feature[styleKey] = layer;
                    }
                };

            _bgWorker.DoWork += delegate(object sender, DoWorkEventArgs e)
                {
                    var layer = RenderImage(multiPolygon, style, viewport);
                    e.Result = layer;
                };

            _bgWorker.RunWorkerAsync();
        }
Exemplo n.º 31
0
        public bool TryGetMap(IViewport viewport, ref IRaster raster)
        {
            int width;
            int height;

            try
            {
                width  = Convert.ToInt32(viewport.Width);
                height = Convert.ToInt32(viewport.Height);
            }
            catch (OverflowException)
            {
                Debug.WriteLine("Could not convert double to int (ExportMap size)");
                return(false);
            }

            var uri        = new Uri(GetRequestUrl(viewport.Extent, width, height));
            var webRequest = (HttpWebRequest)WebRequest.Create(uri);

            if (Credentials == null)
            {
                webRequest.UseDefaultCredentials = true;
            }
            else
            {
                webRequest.Credentials = Credentials;
            }

            try
            {
                var myWebResponse = webRequest.GetSyncResponse(_timeOut);

                using (var dataStream = myWebResponse.GetResponseStream())
                {
                    try
                    {
                        var bytes = BruTile.Utilities.ReadFully(dataStream);
                        raster = new Raster(new MemoryStream(bytes), viewport.Extent);
                    }
                    catch (Exception)
                    {
                        return(false);
                    }
                }
                return(true);
            }
            catch (WebException webEx)
            {
                if (!ContinueOnError)
                {
                    throw (new RenderException(
                               "There was a problem connecting to the ArcGISImage server",
                               webEx));
                }
                Debug.WriteLine("There was a problem connecting to the WMS server: " + webEx.Message);
            }
            catch (Exception ex)
            {
                if (!ContinueOnError)
                {
                    throw (new RenderException("There was a problem while attempting to request the WMS", ex));
                }
                Debug.WriteLine("There was a problem while attempting to request the WMS" + ex.Message);
            }
            return(false);
        }
Exemplo n.º 32
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();
        }
Exemplo n.º 33
0
        public static System.Windows.Shapes.Shape RenderPolygon(Polygon polygon, IStyle style, IViewport viewport, SymbolCache symbolCache)
        {
            if (!(style is VectorStyle))
            {
                throw new ArgumentException("Style is not of type VectorStyle");
            }
            var vectorStyle = style as VectorStyle;

            System.Windows.Shapes.Path path = CreatePolygonPath(vectorStyle, viewport.Resolution, symbolCache, (float)viewport.Rotation);
            path.Data = polygon.ToXaml();

            var matrixTransform = new System.Windows.Media.MatrixTransform {
                Matrix = GeometryRenderer.CreateTransformMatrix1(viewport)
            };

            path.RenderTransform = matrixTransform;

            if (path.Fill != null)
            {
                path.Fill.Transform = matrixTransform.Inverse as System.Windows.Media.MatrixTransform;
            }
            path.UseLayoutRounding = true;
            return(path);
        }
Exemplo n.º 34
0
 public void Render(RenderContext context, IViewport target, CommandList cl, IRenderable renderable, ILocation locationObject)
 {
     //
 }
Exemplo n.º 35
0
 public void SetupFrame(RenderContext context, IViewport target)
 {
     //
 }
Exemplo n.º 36
0
 public static void DrawLineString(Graphics graphics, LineString line, Pen pen, IViewport viewport)
 {
     if (line.Vertices.Count > 1)
     {
         var gp = new GraphicsPath();
         gp.AddLines(ConvertPoints(WorldToScreen(line, viewport)));
         graphics.DrawPath(pen, gp);
     }
 }
Exemplo n.º 37
0
 public static void DrawMultiLineString(Graphics graphics, MultiLineString lines, Pen pen, IViewport viewport)
 {
     foreach (LineString t in lines.LineStrings)
     {
         DrawLineString(graphics, t, pen, viewport);
     }
 }
Exemplo n.º 38
0
 public static void DrawMultiPoint(Graphics graphics, MultiPoint points, Styles.IStyle style, IViewport viewport)
 {
     foreach (Point point in points)
     {
         DrawPoint(graphics, point, style, viewport);
     }
 }
Exemplo n.º 39
0
 public static Point WorldToScreen(Point point, IViewport viewport)
 {
     return(viewport.WorldToScreen(point));
 }
Exemplo n.º 40
0
        /// <summary>
        /// Renders a label to the map.
        /// </summary>
        /// <param name="graphics">Graphics reference</param>
        /// <param name="labelPoint">Label placement</param>
        /// <param name="offset">Offset of label in screen coordinates</param>
        /// <param name="font">Font used for rendering</param>
        /// <param name="forecolor">Font forecolor</param>
        /// <param name="backcolor">Background color</param>
        /// <param name="halo">Color of halo</param>
        /// <param name="rotation">Text rotation in degrees</param>
        /// <param name="text">Text to render</param>
        /// <param name="viewport"></param>
        public static void DrawLabel(Graphics graphics, Point labelPoint, Styles.Offset offset, Styles.Font font, Styles.Color forecolor, Styles.Brush backcolor, Styles.Pen halo, double rotation, string text, IViewport viewport)
        {
            SizeF fontSize = graphics.MeasureString(text, font.ToBitmap()); //Calculate the size of the text

            labelPoint.X += offset.X; labelPoint.Y += offset.Y;             //add label offset
            if (rotation != 0 && !double.IsNaN(rotation))
            {
                graphics.TranslateTransform((float)labelPoint.X, (float)labelPoint.Y);
                graphics.RotateTransform((float)rotation);
                graphics.TranslateTransform(-fontSize.Width / 2, -fontSize.Height / 2);
                if (backcolor != null && backcolor.ToBitmap() != Brushes.Transparent)
                {
                    graphics.FillRectangle(backcolor.ToBitmap(), 0, 0, fontSize.Width * 0.74f + 1f, fontSize.Height * 0.74f);
                }
                var path = new GraphicsPath();
                path.AddString(text, new FontFamily(font.FontFamily), (int)font.ToBitmap().Style, font.ToBitmap().Size, new System.Drawing.Point(0, 0), null);
                if (halo != null)
                {
                    graphics.DrawPath(halo.ToBitmap(), path);
                }
                graphics.FillPath(new SolidBrush(forecolor.ToBitmap()), path);
                //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), 0, 0);
            }
            else
            {
                if (backcolor != null && backcolor.ToBitmap() != Brushes.Transparent)
                {
                    graphics.FillRectangle(backcolor.ToBitmap(), (float)labelPoint.X, (float)labelPoint.Y, fontSize.Width * 0.74f + 1, fontSize.Height * 0.74f);
                }

                var path = new GraphicsPath();

                //Arial hack
                path.AddString(text, new FontFamily("Arial"), (int)font.ToBitmap().Style, (float)font.Size, new System.Drawing.Point((int)labelPoint.X, (int)labelPoint.Y), null);
                if (halo != null)
                {
                    graphics.DrawPath(halo.ToBitmap(), path);
                }
                graphics.FillPath(new SolidBrush(forecolor.ToBitmap()), path);
                //g.DrawString(text, font, new System.Drawing.SolidBrush(forecolor), LabelPoint.X, LabelPoint.Y);
            }
        }
Exemplo n.º 41
0
 public static void DrawMultiPolygon(Graphics graphics, MultiPolygon pols, Brush brush, Pen pen, IViewport viewport)
 {
     foreach (Polygon t in pols.Polygons)
     {
         DrawPolygon(graphics, t, brush, pen, viewport);
     }
 }
Exemplo n.º 42
0
        public static void DrawPolygon(Graphics graphics, Polygon pol, Brush brush, Pen pen, IViewport viewport)
        {
            if (pol.ExteriorRing == null)
            {
                return;
            }
            if (pol.ExteriorRing.Vertices.Count > 2)
            {
                //Use a graphics path instead of DrawPolygon. DrawPolygon has a problem with several interior holes
                var gp = new GraphicsPath();

                //Add the exterior polygon
                gp.AddPolygon(ConvertPoints(WorldToScreen(pol.ExteriorRing, viewport)));
                //Add the interior polygons (holes)
                foreach (LinearRing linearRing in pol.InteriorRings)
                {
                    gp.AddPolygon(ConvertPoints(WorldToScreen(linearRing, viewport)));
                }

                // Only render inside of polygon if the brush isn't null or isn't transparent
                if (brush != null && brush != Brushes.Transparent)
                {
                    graphics.FillPath(brush, gp);
                }
                // Create an outline if a pen style is available
                if (pen != null)
                {
                    graphics.DrawPath(pen, gp);
                }
            }
        }
Exemplo n.º 43
0
 private double CalculateResolutionAtWhichMapFillsViewport(IViewport viewport, BoundingBox mapEnvelope)
 {
     return(Math.Min(mapEnvelope.Width / viewport.Width, mapEnvelope.Height / viewport.Height));
 }
Exemplo n.º 44
0
 public MemoryStream RenderToBitmapStream(IViewport viewport, IEnumerable <ILayer> layers)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 45
0
 public Boolean CollidesWith(Single x, Single y, IViewport viewport)
 {
     return(_colliderComponent.CollidesWith(x, y, viewport));
 }
Exemplo n.º 46
0
 public AGSBoundingBoxes GetBoundingBoxes(IViewport viewport)
 {
     return(_boundingBoxComponent.GetBoundingBoxes(viewport));
 }
Exemplo n.º 47
0
        private static Canvas RenderVectorLayer(IViewport viewport, ILayer layer, bool rasterizing = false)
        {
            // todo:
            // find solution for try catch. Sometimes this method will throw an exception
            // when clearing and adding features to a layer while rendering
            var canvas = new Canvas
            {
                Opacity          = layer.Opacity,
                IsHitTestVisible = false
            };

            try
            {
                var features    = layer.GetFeaturesInView(viewport.Extent, viewport.RenderResolution).ToList();
                var layerStyles = BaseLayer.GetLayerStyles(layer);
                var brushCache  = new BrushCache();

                foreach (var layerStyle in layerStyles)
                {
                    var style = layerStyle; // This is the default that could be overridden by an IThemeStyle

                    foreach (var feature in features)
                    {
                        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;
                        }

                        RenderFeature(viewport, canvas, feature, style, rasterizing, brushCache);
                    }
                }

                foreach (var feature in features)
                {
                    var styles = feature.Styles ?? Enumerable.Empty <IStyle>();
                    foreach (var style in styles)
                    {
                        if ((feature.Styles != null) && style.Enabled)
                        {
                            RenderFeature(viewport, canvas, feature, style, rasterizing, brushCache);
                        }
                    }
                }

                return(canvas);
            }
            catch (Exception ex)
            {
                Logger.LogDelegate(LogLevel.Error, "Unexpected error in renderer", ex);
                return(canvas);
                // If exception happens inside RenderFeature function after
                // at -least one child has been added to the canvas,
                // returning new canvas will leave the previously created (but
                // not yet added to parent canvas) canvas abandoned, that will
                // cause the exception when resuing RenderedGeometry object, because
                // at -least one RenderedGeometry was attached to that abandoned canvas.
                // returning the same canvas will solve this error, as it will
                // be clear this canvas childs on next render call.
                // return new Canvas { IsHitTestVisible = false };
            }
        }
Exemplo n.º 48
0
 public void Render(object target, IViewport viewport, IEnumerable <ILayer> layers, Color background)
 {
     Render((Canvas)target, viewport, layers, background, false);
 }
Exemplo n.º 49
0
        public static void PositionPoint(UIElement renderedGeometry, Point point, IStyle style, IViewport viewport)
        {
            var matrix      = XamlMedia.Matrix.Identity;
            var symbolStyle = style as SymbolStyle;

            if (symbolStyle != null)
            {
                matrix = CreatePointSymbolMatrix(viewport.Resolution, viewport.Rotation, symbolStyle);
            }
            else
            {
                MatrixHelper.ScaleAt(ref matrix, viewport.Resolution, viewport.Resolution);
            }
            MatrixHelper.Append(ref matrix, GeometryRenderer.CreateTransformMatrix(point, viewport));
            renderedGeometry.RenderTransform = new XamlMedia.MatrixTransform {
                Matrix = matrix
            };
        }
Exemplo n.º 50
0
        public static void Draw(SKCanvas canvas, IViewport viewport, IStyle style, IFeature feature, IGeometry geometry,
                                float opacity, SymbolCache symbolCache = null)
        {
            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     strokeJoin       = StrokeJoin.Miter;  // default
                var     strokeMiterLimit = 4f;                // default
                var     strokeStyle      = PenStyle.Solid;    // default
                float[] dashArray        = null;              // default

                var vectorStyle = style as VectorStyle;

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

                    fillColor = vectorStyle.Fill?.Color;
                }

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

                        // Is there a FillStyle?
                        if (vectorStyle.Fill?.FillStyle == FillStyle.Solid)
                        {
                            paint.StrokeWidth = lineWidth;
                            paint.Style       = SKPaintStyle.Fill;
                            paint.Color       = fillColor.ToSkia(opacity);
                            canvas.DrawPath(path, paint);
                        }
                        else
                        {
                            paint.StrokeWidth = 1;
                            paint.Style       = SKPaintStyle.Stroke;
                            paint.Color       = fillColor.ToSkia(opacity);
                            float    scale    = 10.0f;
                            SKPath   fillPath = new SKPath();
                            SKMatrix matrix   = SKMatrix.MakeScale(scale, scale);

                            switch (vectorStyle.Fill?.FillStyle)
                            {
                            case FillStyle.Cross:
                                fillPath.MoveTo(scale * 0.8f, scale * 0.8f);
                                fillPath.LineTo(0, 0);
                                fillPath.MoveTo(0, scale * 0.8f);
                                fillPath.LineTo(scale * 0.8f, 0);
                                paint.PathEffect = SKPathEffect.Create2DPath(matrix, fillPath);
                                break;

                            case FillStyle.DiagonalCross:
                                fillPath.MoveTo(scale, scale);
                                fillPath.LineTo(0, 0);
                                fillPath.MoveTo(0, scale);
                                fillPath.LineTo(scale, 0);
                                paint.PathEffect = SKPathEffect.Create2DPath(matrix, fillPath);
                                break;

                            case FillStyle.BackwardDiagonal:
                                fillPath.MoveTo(0, scale);
                                fillPath.LineTo(scale, 0);
                                paint.PathEffect = SKPathEffect.Create2DPath(matrix, fillPath);
                                break;

                            case FillStyle.ForwardDiagonal:
                                fillPath.MoveTo(scale, scale);
                                fillPath.LineTo(0, 0);
                                paint.PathEffect = SKPathEffect.Create2DPath(matrix, fillPath);
                                break;

                            case FillStyle.Dotted:
                                paint.Style = SKPaintStyle.StrokeAndFill;
                                fillPath.AddCircle(scale * 0.5f, scale * 0.5f, scale * 0.35f);
                                paint.PathEffect = SKPathEffect.Create2DPath(matrix, fillPath);
                                break;

                            case FillStyle.Horizontal:
                                fillPath.MoveTo(0, scale * 0.5f);
                                fillPath.LineTo(scale, scale * 0.5f);
                                paint.PathEffect = SKPathEffect.Create2DPath(matrix, fillPath);
                                break;

                            case FillStyle.Vertical:
                                fillPath.MoveTo(scale * 0.5f, 0);
                                fillPath.LineTo(scale * 0.5f, scale);
                                paint.PathEffect = SKPathEffect.Create2DPath(matrix, fillPath);
                                break;

                            case FillStyle.Bitmap:
                                paint.Style  = SKPaintStyle.Fill;
                                paint.Shader = symbolCache.GetOrCreate(vectorStyle.Fill.BitmapId).Bitmap.ToShader(SKShaderTileMode.Repeat, SKShaderTileMode.Repeat);
                                break;

                            case FillStyle.BitmapRotated:
                                paint.Style = SKPaintStyle.Fill;
                                SKImage bitmap = symbolCache.GetOrCreate(vectorStyle.Fill.BitmapId).Bitmap;
                                paint.Shader = bitmap.ToShader(SKShaderTileMode.Repeat,
                                                               SKShaderTileMode.Repeat,
                                                               SKMatrix.MakeRotation((float)(viewport.Rotation * System.Math.PI / 180.0f), bitmap.Width >> 1, bitmap.Height >> 1));
                                break;
                            }

                            // Do this, because if not, path isn't filled complete
                            using (new SKAutoCanvasRestore(canvas))
                            {
                                canvas.ClipPath(path);
                                var bounds = path.Bounds;
                                // Make sure, that the brush starts with the correct position
                                var inflate = ((int)path.Bounds.Width * 0.3f / scale) * scale;
                                bounds.Inflate(inflate, inflate);
                                // Draw rect with bigger size, which is clipped by path
                                canvas.DrawRect(bounds, paint);
                            }
                        }
                    }

                    using (var paint = new SKPaint())
                    {
                        paint.IsAntialias = true;
                        paint.Style       = SKPaintStyle.Stroke;
                        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);
                        }
                        canvas.DrawPath(path, paint);
                    }
                }
            }
        }
Exemplo n.º 51
0
        private static XamlMedia.Geometry ConvertSymbol(Point point, SymbolStyle style, IViewport viewport)
        {
            Point p = viewport.WorldToScreen(point);

            var rect = new XamlMedia.RectangleGeometry();

            if (style.BitmapId >= 0)
            {
                var bitmapImage = BitmapRegistry.Instance.Get(style.BitmapId).CreateBitmapImage();
                var width       = bitmapImage.PixelWidth * style.SymbolScale;
                var height      = bitmapImage.PixelHeight * style.SymbolScale;
                rect.Rect = new Rect(p.X - width * 0.5, p.Y - height * 0.5, width, height);
            }

            return(rect);
        }
Exemplo n.º 52
0
 public Navigator(Map map, IViewport viewport)
 {
     _map      = map;
     _viewport = viewport;
 }
Exemplo n.º 53
0
 public static Tween TweenAngle(this IViewport viewport, float toAngle, float timeInSeconds, Func <float, float> easing = null)
 {
     return(Tween.Run(viewport.Angle, toAngle, a => viewport.Angle = a, timeInSeconds, easing));
 }
 public void Render(IViewport viewport, OrthographicCamera camera, Vector3 worldMin, Vector3 worldMax, I2DRenderer im)
 {
     //
 }
Exemplo n.º 55
0
 private void Render(Canvas target, IViewport viewport, IEnumerable <ILayer> layers)
 {
     Render(target, viewport, layers, _symbolCache, false);
 }
Exemplo n.º 56
0
 public static Tween TweenX(this IViewport viewport, float toX, float timeInSeconds, Func <float, float> easing = null)
 {
     return(Tween.Run(viewport.X, toX, x => viewport.X = x, timeInSeconds, easing));
 }
Exemplo n.º 57
0
 private static XamlMedia.Matrix CreateTransformMatrix1(IViewport viewport)
 {
     return(CreateTransformMatrix(new Point(0, 0), viewport));
 }
Exemplo n.º 58
0
 public static Tween TweenScaleY(this IViewport viewport, float toScaleY, float timeInSeconds, Func <float, float> easing = null)
 {
     return(Tween.Run(viewport.ScaleY, toScaleY, y => viewport.ScaleY = y, timeInSeconds, easing));
 }
Exemplo n.º 59
0
        public static void PositionRaster(UIElement renderedGeometry, BoundingBox boundingBox, IViewport viewport)
        {
            UpdateRenderTransform(renderedGeometry, viewport);

            // since the render transform will take care of the rotation, calculate top-left using unrotated viewport
            var topLeft          = viewport.WorldToScreenUnrotated(boundingBox.TopLeft);
            var rectWidthPixels  = boundingBox.Width / viewport.Resolution;
            var rectHeightPixels = boundingBox.Height / viewport.Resolution;

            ((XamlMedia.RectangleGeometry)((XamlShapes.Path)renderedGeometry).Data).Rect =
                RoundToPixel(new Rect(topLeft.X, topLeft.Y, rectWidthPixels, rectHeightPixels));
        }
Exemplo n.º 60
0
 public static Canvas Render(IViewport viewport, LabelLayer layer)
 {
     throw new NotImplementedException();
 }