예제 #1
0
        public static void Draw(SKCanvas canvas, ImageStyle symbolStyle, Point destination,
                                SymbolCache symbolCache, float opacity, double mapRotation)
        {
            if (symbolStyle.BitmapId < 0)
            {
                return;
            }

            var bitmap = symbolCache.GetOrCreate(symbolStyle.BitmapId);

            // Calc offset (relative or absolute)
            var offsetX = symbolStyle.SymbolOffset.IsRelative ? bitmap.Width * symbolStyle.SymbolOffset.X : symbolStyle.SymbolOffset.X;
            var offsetY = symbolStyle.SymbolOffset.IsRelative ? bitmap.Height * symbolStyle.SymbolOffset.Y : symbolStyle.SymbolOffset.Y;

            var rotation = (float)symbolStyle.SymbolRotation;

            if (symbolStyle.RotateWithMap)
            {
                rotation += (float)mapRotation;
            }

            switch (bitmap.Type)
            {
            case BitmapType.Bitmap:
                BitmapRenderer.Draw(canvas, bitmap.Bitmap,
                                    (float)destination.X, (float)destination.Y,
                                    rotation,
                                    (float)offsetX, (float)offsetY,
                                    opacity: opacity, scale: (float)symbolStyle.SymbolScale);
                break;

            case BitmapType.Svg:
                SvgRenderer.Draw(canvas, bitmap.Svg,
                                 (float)destination.X, (float)destination.Y,
                                 rotation,
                                 (float)offsetX, (float)offsetY,
                                 opacity: opacity, scale: (float)symbolStyle.SymbolScale);
                break;

            case BitmapType.Sprite:
                var sprite = bitmap.Sprite;
                if (sprite.Data == null)
                {
                    var bitmapAtlas = symbolCache.GetOrCreate(sprite.Atlas);
                    sprite.Data = bitmapAtlas.Bitmap.Subset(new SKRectI(sprite.X, sprite.Y, sprite.X + sprite.Width,
                                                                        sprite.Y + sprite.Height));
                }
                BitmapRenderer.Draw(canvas, (SKImage)sprite.Data,
                                    (float)destination.X, (float)destination.Y,
                                    rotation,
                                    (float)offsetX, (float)offsetY,
                                    opacity: opacity, scale: (float)symbolStyle.SymbolScale);
                break;
            }
        }
예제 #2
0
        public static void Draw(SKCanvas canvas, IReadOnlyViewport viewport, IStyle style, IFeature feature,
                                float opacity, IDictionary <object, BitmapInfo> tileCache, long currentIteration)
        {
            try
            {
                var raster = (IRaster)feature.Geometry;

                BitmapInfo bitmapInfo;

                if (!tileCache.Keys.Contains(raster))
                {
                    bitmapInfo        = BitmapHelper.LoadBitmap(raster.Data);
                    tileCache[raster] = bitmapInfo;
                }
                else
                {
                    bitmapInfo = tileCache[raster];
                }

                bitmapInfo.IterationUsed = currentIteration;
                tileCache[raster]        = bitmapInfo;

                var boundingBox = feature.Geometry.BoundingBox;

                if (viewport.IsRotated)
                {
                    var priorMatrix = canvas.TotalMatrix;

                    var matrix = CreateRotationMatrix(viewport, boundingBox, priorMatrix);

                    canvas.SetMatrix(matrix);

                    var destination = new BoundingBox(0.0, 0.0, boundingBox.Width, boundingBox.Height);

                    BitmapRenderer.Draw(canvas, bitmapInfo.Bitmap, destination.ToSkia(), opacity);

                    canvas.SetMatrix(priorMatrix);
                }
                else
                {
                    var destination = WorldToScreen(viewport, feature.Geometry.BoundingBox);
                    BitmapRenderer.Draw(canvas, bitmapInfo.Bitmap, RoundToPixel(destination).ToSkia(), opacity);
                }
            }
            catch (Exception ex)
            {
                Logger.Log(LogLevel.Error, ex.Message, ex);
            }
        }
예제 #3
0
        public static void DrawAsBitmap(SKCanvas canvas, LabelStyle style, IFeature feature, float x, float y, float layerOpacity)
        {
            var text = style.GetLabelText(feature);

            var key = text + "_" + style.Font.FontFamily + "_" + style.Font.Size + "_" + (float)style.Font.Size + "_" +
                      style.BackColor + "_" + style.ForeColor;

            if (!LabelCache.Keys.Contains(key))
            {
                LabelCache[key] = new BitmapInfo {
                    Bitmap = CreateLabelAsBitmap(style, text, layerOpacity)
                }
            }
            ;

            var info    = LabelCache[key];
            var offsetX = style.Offset.IsRelative ? info.Width * style.Offset.X : style.Offset.X;
            var offsetY = style.Offset.IsRelative ? info.Height * style.Offset.Y : style.Offset.Y;

            BitmapRenderer.Draw(canvas, info.Bitmap, (int)Math.Round(x), (int)Math.Round(y),
                                offsetX: (float)offsetX, offsetY: (float)-offsetY,
                                horizontalAlignment: style.HorizontalAlignment, verticalAlignment: style.VerticalAlignment);
        }
예제 #4
0
        public static void Draw(SKCanvas canvas, IReadOnlyViewport viewport, IStyle style, IFeature feature, MRaster?raster, float opacity, IDictionary <object, BitmapInfo?> tileCache, long currentIteration)
        {
            try
            {
                if (raster == null)
                {
                    return;
                }

                BitmapInfo?bitmapInfo;

                if (!tileCache.Keys.Contains(raster))
                {
                    bitmapInfo        = BitmapHelper.LoadBitmap(raster.Data);
                    tileCache[raster] = bitmapInfo;
                }
                else
                {
                    bitmapInfo = tileCache[raster];
                }

                if (bitmapInfo == null)
                {
                    return;
                }

                bitmapInfo.IterationUsed = currentIteration;
                tileCache[raster]        = bitmapInfo;

                var extent = feature.Extent;

                if (extent == null)
                {
                    return;
                }

                if (bitmapInfo.Bitmap == null)
                {
                    return;
                }

                if (viewport.IsRotated)
                {
                    var priorMatrix = canvas.TotalMatrix;

                    var matrix = CreateRotationMatrix(viewport, extent, priorMatrix);

                    canvas.SetMatrix(matrix);

                    var destination = new SKRect(0.0f, 0.0f, (float)extent.Width, (float)extent.Height);

                    BitmapRenderer.Draw(canvas, bitmapInfo.Bitmap, destination, opacity);

                    canvas.SetMatrix(priorMatrix);
                }
                else
                {
                    var destination = WorldToScreen(viewport, extent);
                    BitmapRenderer.Draw(canvas, bitmapInfo.Bitmap, RoundToPixel(destination), opacity);
                }
            }
            catch (Exception ex)
            {
                Logger.Log(LogLevel.Error, ex.Message, ex);
            }
        }
예제 #5
0
        public bool Draw(SKCanvas canvas, IReadOnlyViewport viewport, ILayer layer, IFeature feature, IStyle style, ISymbolCache symbolCache, long currentIteration)
        {
            try
            {
                var rasterFeature = feature as RasterFeature;
                var raster        = rasterFeature?.Raster;

                var opacity = (float)(layer.Opacity * style.Opacity);

                if (raster == null)
                {
                    return(false);
                }

                if (!(style is RasterStyle rasterStyle))
                {
                    return(false);
                }

                rasterStyle.UpdateCache(currentIteration);

                BitmapInfo?bitmapInfo;

                if (!rasterStyle.TileCache.Keys.Contains(raster))
                {
                    bitmapInfo = BitmapHelper.LoadBitmap(raster.Data);
                    rasterStyle.TileCache[raster] = bitmapInfo;
                }
                else
                {
                    bitmapInfo = (BitmapInfo?)rasterStyle.TileCache[raster];
                }

                if (bitmapInfo == null || bitmapInfo.Bitmap == null)
                {
                    return(false);
                }

                bitmapInfo.IterationUsed      = currentIteration;
                rasterStyle.TileCache[raster] = bitmapInfo;

                var extent = feature.Extent;

                if (extent == null)
                {
                    return(false);
                }

                canvas.Save();

                if (viewport.IsRotated)
                {
                    var priorMatrix = canvas.TotalMatrix;

                    var matrix = CreateRotationMatrix(viewport, extent, priorMatrix);

                    canvas.SetMatrix(matrix);

                    var destination = new SKRect(0.0f, 0.0f, (float)extent.Width, (float)extent.Height);

                    BitmapRenderer.Draw(canvas, bitmapInfo.Bitmap, destination, opacity);

                    canvas.SetMatrix(priorMatrix);
                }
                else
                {
                    var destination = WorldToScreen(viewport, extent);
                    BitmapRenderer.Draw(canvas, bitmapInfo.Bitmap, RoundToPixel(destination), opacity);
                }

                canvas.Restore();
            }
            catch (Exception ex)
            {
                Logger.Log(LogLevel.Error, ex.Message, ex);
            }

            return(true);
        }
예제 #6
0
        private static bool DrawImage(SKCanvas canvas, IReadOnlyViewport viewport, ILayer layer, double x, double y, SymbolStyle symbolStyle, ISymbolCache symbolCache)
        {
            var opacity = (float)(layer.Opacity * symbolStyle.Opacity);

            var(destX, destY) = viewport.WorldToScreenXY(x, y);

            if (symbolStyle.BitmapId < 0)
            {
                return(false);
            }

            var bitmap = (BitmapInfo)symbolCache.GetOrCreate(symbolStyle.BitmapId);

            if (bitmap == null)
            {
                return(false);
            }

            // Calc offset (relative or absolute)
            var offsetX = symbolStyle.SymbolOffset.IsRelative ? bitmap.Width * symbolStyle.SymbolOffset.X : symbolStyle.SymbolOffset.X;
            var offsetY = symbolStyle.SymbolOffset.IsRelative ? bitmap.Height * symbolStyle.SymbolOffset.Y : symbolStyle.SymbolOffset.Y;

            var rotation = (float)symbolStyle.SymbolRotation;

            if (symbolStyle.RotateWithMap)
            {
                rotation += (float)viewport.Rotation;
            }

            switch (bitmap.Type)
            {
            case BitmapType.Bitmap:
                if (bitmap.Bitmap == null)
                {
                    return(false);
                }

                BitmapRenderer.Draw(canvas, bitmap.Bitmap,
                                    (float)destX, (float)destY,
                                    rotation,
                                    (float)offsetX, (float)offsetY,
                                    opacity: opacity, scale: (float)symbolStyle.SymbolScale);
                break;

            case BitmapType.Picture:
                if (bitmap.Picture == null)
                {
                    return(false);
                }

                PictureRenderer.Draw(canvas, bitmap.Picture,
                                     (float)destX, (float)destY,
                                     rotation,
                                     (float)offsetX, (float)offsetY,
                                     opacity: opacity, scale: (float)symbolStyle.SymbolScale, blendModeColor: symbolStyle.BlendModeColor);
                break;

            case BitmapType.Svg:
                // Todo: Perhaps remove BitmapType.Svg and SvgRenderer?
                // It looks like Bitmaptype.Svg is not use at all the the momement.
                if (bitmap.Svg == null)
                {
                    return(false);
                }

                SvgRenderer.Draw(canvas, bitmap.Svg,
                                 (float)destX, (float)destY,
                                 rotation,
                                 (float)offsetX, (float)offsetY,
                                 opacity: opacity, scale: (float)symbolStyle.SymbolScale);
                break;

            case BitmapType.Sprite:
                if (bitmap.Sprite == null)
                {
                    return(false);
                }

                var sprite = bitmap.Sprite;
                if (sprite.Data == null)
                {
                    var bitmapAtlas = (BitmapInfo)symbolCache.GetOrCreate(sprite.Atlas);
                    sprite.Data = bitmapAtlas?.Bitmap?.Subset(new SKRectI(sprite.X, sprite.Y, sprite.X + sprite.Width,
                                                                          sprite.Y + sprite.Height));
                }
                if (sprite.Data is SKImage skImage)
                {
                    BitmapRenderer.Draw(canvas, skImage,
                                        (float)destX, (float)destY,
                                        rotation,
                                        (float)offsetX, (float)offsetY,
                                        opacity: opacity, scale: (float)symbolStyle.SymbolScale);
                }
                break;
            }

            return(true);
        }