Exemple #1
0
 private static void Render(Canvas canvas, IViewport viewport, IEnumerable <ILayer> layers, bool showDebugInfoInMap)
 {
     layers = layers.ToList();
     VisibleFeatureIterator.IterateLayers(viewport, layers, (v, s, f) => RenderFeature(canvas, v, s, f));
     if (showDebugInfoInMap)
     {
         DrawDebugInfo(canvas, layers);
     }
 }
Exemple #2
0
        public void Render(IViewport viewport, IEnumerable <ILayer> layers)
        {
            layers = layers.ToList();

            SetAllTextureInfosToUnused();

            VisibleFeatureIterator.IterateLayers(viewport, layers, RenderFeature);

            RemoveUnusedTextureInfos();
        }
Exemple #3
0
        private void Render(SKCanvas canvas, IViewport viewport, IEnumerable <ILayer> layers)
        {
            layers = layers.ToList();

            VisibleFeatureIterator.IterateLayers(viewport, layers, (v, l, s) => { RenderFeature(canvas, v, l, s); });

            RemovedUnusedBitmapsFromCache();

            _currentIteration++;
        }
Exemple #4
0
        public void Render(object target, IViewport viewport, IEnumerable <ILayer> layers, Color background = null)
        {
            layers = layers.ToList();

            SetAllTextureInfosToUnused();

            VisibleFeatureIterator.IterateLayers(viewport, layers, RenderFeature);

            RemoveUnusedTextureInfos();

            _currentIteration++;
        }
Exemple #5
0
        private void Render(SKCanvas canvas, IViewport viewport, IEnumerable <ILayer> layers, Color background)
        {
            if (background != null)
            {
                canvas.Clear(background.ToSkia());
            }

            layers = layers.ToList();

            VisibleFeatureIterator.IterateLayers(viewport, layers, (v, l, s) => { RenderFeature(canvas, v, l, s); });

            RemovedUnusedBitmapsFromCache();

            _currentIteration++;
        }
Exemple #6
0
        private void Render(SKCanvas canvas, IReadOnlyViewport viewport, IEnumerable <ILayer> layers)
        {
            try
            {
                VisibleFeatureIterator.IterateLayers(viewport, layers, (v, l, s, o) => { RenderFeature(canvas, v, l, s, o); });

                RemovedUnusedBitmapsFromCache();

                _currentIteration++;
            }
            catch (Exception exception)
            {
                Logger.Log(LogLevel.Error, "Unexpected error in skia renderer", exception);
            }
        }
Exemple #7
0
        private void Render(SKCanvas canvas, IReadOnlyViewport viewport, IEnumerable <ILayer> layers)
        {
            try
            {
                layers = layers.ToList();

                VisibleFeatureIterator.IterateLayers(viewport, layers, _currentIteration, (v, l, s, f, o, i) => { RenderFeature(canvas, v, l, s, f, o, i); });

                _currentIteration++;
            }
            catch (Exception exception)
            {
                Logger.Log(LogLevel.Error, "Unexpected error in skia renderer", exception);
            }
        }
Exemple #8
0
        private void Render(SKCanvas canvas, IViewport viewport, IEnumerable <ILayer> layers)
        {
            canvas.Clear(new SKColor(255, 255, 255));
            layers = layers.ToList();

            SetAllTextureInfosToUnused();

            VisibleFeatureIterator.IterateLayers(viewport, layers, (v, l, s) =>
            {
                RenderFeature(canvas, v, l, s);
            });

            RemoveUnusedTextureInfos();

            _currentIteration++;
        }
Exemple #9
0
        public MapInfo GetMapInfo(double x, double y, IReadOnlyViewport viewport, IEnumerable <ILayer> layers, int margin = 0)
        {
            // todo: use margin to increase the pixel area
            // todo: We will need to select on style instead of layer

            layers = layers
                     .Select(l => (l is RasterizingLayer rl) ? rl.ChildLayer : l)
                     .Where(l => l.IsMapInfoLayer);

            var list   = new List <MapInfoRecord>();
            var result = new MapInfo()
            {
                ScreenPosition = new Point(x, y),
                WorldPosition  = viewport.ScreenToWorld(x, y),
                Resolution     = viewport.Resolution
            };

            try
            {
                var width  = (int)viewport.Width;
                var height = (int)viewport.Height;

                var imageInfo = new SKImageInfo(width, height, SKImageInfo.PlatformColorType, SKAlphaType.Unpremul);

                var intX = (int)x;
                var intY = (int)y;

                using (var surface = SKSurface.Create(imageInfo))
                {
                    if (surface == null)
                    {
                        return(null);
                    }

                    surface.Canvas.ClipRect(new SKRect((float)(x - 1), (float)(y - 1), (float)(x + 1), (float)(y + 1)));
                    surface.Canvas.Clear(SKColors.Transparent);

                    var pixmap = surface.PeekPixels();
                    var color  = pixmap.GetPixelColor(intX, intY);

                    VisibleFeatureIterator.IterateLayers(viewport, layers, (v, layer, style, feature, opacity) => {
                        surface.Canvas.Save();
                        // 1) Clear the entire bitmap
                        surface.Canvas.Clear(SKColors.Transparent);
                        // 2) Render the feature to the clean canvas
                        RenderFeature(surface.Canvas, v, layer, style, feature, opacity);
                        // 3) Check if the pixel has changed.
                        if (color != pixmap.GetPixelColor(intX, intY))
                        {
                            // 4) Add feature and style to result
                            list.Add(new MapInfoRecord(feature, style, layer));
                        }
                        surface.Canvas.Restore();
                    });
                }

                if (list.Count == 0)
                {
                    return(result);
                }

                list.Reverse();
                var itemDrawnOnTop = list.First();

                result.Feature        = itemDrawnOnTop.Feature;
                result.Style          = itemDrawnOnTop.Style;
                result.Layer          = itemDrawnOnTop.Layer;
                result.MapInfoRecords = list;
            }
            catch (Exception exception)
            {
                Logger.Log(LogLevel.Error, "Unexpected error in skia renderer", exception);
            }

            return(result);
        }
Exemple #10
0
 private static void Render(CALayer target, IViewport viewport, IEnumerable <ILayer> layers)
 {
     layers = layers.ToList();
     VisibleFeatureIterator.IterateLayers(viewport, layers, (v, s, f) => RenderGeometry(target, v, s, f));
 }
Exemple #11
0
        public MapInfo?GetMapInfo(double x, double y, IReadOnlyViewport viewport, IEnumerable <ILayer> layers, int margin = 0)
        {
            // todo: use margin to increase the pixel area
            // todo: We will need to select on style instead of layer

            layers = layers
                     .Select(l => (l is ISourceLayer sl) ? sl.SourceLayer : l)
                     .Where(l => l.IsMapInfoLayer);

            var list   = new List <MapInfoRecord>();
            var result = new MapInfo
            {
                ScreenPosition = new MPoint(x, y),
                WorldPosition  = viewport.ScreenToWorld(x, y),
                Resolution     = viewport.Resolution
            };

            if (!viewport.Extent?.Contains(viewport.ScreenToWorld(result.ScreenPosition)) ?? false)
            {
                return(result);
            }

            try
            {
                var width  = (int)viewport.Width;
                var height = (int)viewport.Height;

                var imageInfo = new SKImageInfo(width, height, SKImageInfo.PlatformColorType, SKAlphaType.Unpremul);

                var intX = (int)x;
                var intY = (int)y;

                if (intX >= width || intY >= height)
                {
                    return(result);
                }

                using (var surface = SKSurface.Create(imageInfo))
                {
                    if (surface == null)
                    {
                        return(null);
                    }

                    surface.Canvas.ClipRect(new SKRect((float)(x - 1), (float)(y - 1), (float)(x + 1), (float)(y + 1)));
                    surface.Canvas.Clear(SKColors.Transparent);

                    using var pixmap = surface.PeekPixels();
                    var color = pixmap.GetPixelColor(intX, intY);


                    VisibleFeatureIterator.IterateLayers(viewport, layers, 0, (v, layer, style, feature, opacity, iteration) => {
                        // ReSharper disable AccessToDisposedClosure // There is no delayed fetch. After IterateLayers returns all is done. I do not see a problem.
                        surface.Canvas.Save();
                        // 1) Clear the entire bitmap
                        surface.Canvas.Clear(SKColors.Transparent);
                        // 2) Render the feature to the clean canvas
                        RenderFeature(surface.Canvas, v, layer, style, feature, opacity, 0);
                        // 3) Check if the pixel has changed.
                        if (color != pixmap.GetPixelColor(intX, intY))
                        {
                            // 4) Add feature and style to result
                            list.Add(new MapInfoRecord(feature, style, layer));
                        }
                        surface.Canvas.Restore();
                        // ReSharper restore AccessToDisposedClosure
                    });
                }

                if (list.Count == 0)
                {
                    return(result);
                }

                list.Reverse();
                var itemDrawnOnTop = list.First();

                result.Feature        = itemDrawnOnTop.Feature;
                result.Style          = itemDrawnOnTop.Style;
                result.Layer          = itemDrawnOnTop.Layer;
                result.MapInfoRecords = list;
            }
            catch (Exception exception)
            {
                Logger.Log(LogLevel.Error, "Unexpected error in skia renderer", exception);
            }

            return(result);
        }