示例#1
0
        /// <summary>
        /// Raises the paint event.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaint(PaintEventArgs e)
        {
            if (this.Scene != null)
            { // only render when scene and view are set.
                var bitmap = new Bitmap((int)e.Graphics.VisibleClipBounds.Width,
                                        (int)e.Graphics.VisibleClipBounds.Height);
                Graphics g = Graphics.FromImage(bitmap);

                // create current view.
                View2D view = this.CreateCurrentView(g.VisibleClipBounds.Width,
                                                     g.VisibleClipBounds.Height);

                // initialize renderer.
                var graphicsRenderer2D = new GraphicsRenderer2D();

                // render the scene.
                graphicsRenderer2D.Render(g, this.Scene, view);

                e.Graphics.DrawImageUnscaled(bitmap, 0, 0);
            }
        }
示例#2
0
        /// <summary>
        /// Renders the given data onto a 100x100 image using bounds around null-island (1,1,-1,-1) and the MapCSS definition.
        /// </summary>
        /// <param name="dataSource"></param>
        /// <param name="mapCSS"></param>
        /// <returns></returns>
        private Bitmap Render(IDataSourceReadOnly dataSource, string mapCSS)
        {
            // create projection.
            WebMercator projection = new WebMercator();

            double[] topLeft     = projection.ToPixel(new Math.Geo.GeoCoordinate(1, 1));
            double[] bottomRight = projection.ToPixel(new Math.Geo.GeoCoordinate(-1, -1));

            // create view (this comes down to (1,1,-1,-1) for a size of 100x100).
            View2D view = View2D.CreateFromBounds(bottomRight[1], topLeft[0], topLeft[1], bottomRight[0]);
            //View2D view = View2D.CreateFrom(0, 0, 100, 100, 1.0 / 200.0, false, true);

            // create graphics
            Bitmap   rendering         = new Bitmap(100, 100);
            Graphics renderingGraphics = Graphics.FromImage(rendering);

            renderingGraphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
            renderingGraphics.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            renderingGraphics.PixelOffsetMode    = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
            renderingGraphics.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

            // create renderer.
            GraphicsRenderer2D     graphicsRenderer = new GraphicsRenderer2D();
            MapRenderer <Graphics> renderer         = new MapRenderer <Graphics>(graphicsRenderer);

            // create map.
            OsmSharp.UI.Map.Map map = new OsmSharp.UI.Map.Map();
            map.AddLayer(new LayerOsm(dataSource, new MapCSSInterpreter(mapCSS), projection));

            // notify the map that there was a view change!
            map.ViewChanged((float)view.CalculateZoom(100, 100), new Math.Geo.GeoCoordinate(0, 0), view);

            // ... and finally do the actual rendering.
            renderer.Render(Graphics.FromImage(rendering), map, view);

            //rendering.Save(@"c:\temp\rendering.bmp");

            return(rendering);
        }
示例#3
0
        /// <summary>
        /// Raises the paint event.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaint(PaintEventArgs e)
        {
            if (this.Scene != null)
            { // only render when scene and view are set.
                var bitmap = new Bitmap((int) e.Graphics.VisibleClipBounds.Width,
                                           (int) e.Graphics.VisibleClipBounds.Height);
                Graphics g = Graphics.FromImage(bitmap);

                // create current view.
                View2D view = this.CreateCurrentView(g.VisibleClipBounds.Width,
                                                     g.VisibleClipBounds.Height);

                // initialize renderer.
                var graphicsRenderer2D = new GraphicsRenderer2D();

                // render the scene.
                graphicsRenderer2D.Render(g, this.Scene, view);

                e.Graphics.DrawImageUnscaled(bitmap, 0, 0);
            }
        }
        /// <summary>
        /// Renders the given data onto a 100x100 image using bounds around null-island (1,1,-1,-1) and the MapCSS definition.
        /// </summary>
        /// <param name="dataSource"></param>
        /// <param name="mapCSS"></param>
        /// <returns></returns>
        private Bitmap Render(IDataSourceReadOnly dataSource, string mapCSS)
        {
            // create projection.
            WebMercator projection = new WebMercator();
            double[] topLeft = projection.ToPixel(new Math.Geo.GeoCoordinate(1, 1));
            double[] bottomRight = projection.ToPixel(new Math.Geo.GeoCoordinate(-1, -1));

            // create view (this comes down to (1,1,-1,-1) for a size of 100x100).
            View2D view = View2D.CreateFromBounds(bottomRight[1], topLeft[0], topLeft[1], bottomRight[0]);
            //View2D view = View2D.CreateFrom(0, 0, 100, 100, 1.0 / 200.0, false, true);

            // create graphics
            Bitmap rendering = new Bitmap(100, 100);
            Graphics renderingGraphics = Graphics.FromImage(rendering);
            renderingGraphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
            renderingGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            renderingGraphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
            renderingGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

            // create renderer.
            GraphicsRenderer2D graphicsRenderer = new GraphicsRenderer2D();
            MapRenderer<Graphics> renderer = new MapRenderer<Graphics>(graphicsRenderer);

            // create map.
            OsmSharp.UI.Map.Map map = new OsmSharp.UI.Map.Map();
            map.AddLayer(new LayerOsm(dataSource, new MapCSSInterpreter(mapCSS), projection));

            // notify the map that there was a view change!
            map.ViewChanged((float)view.CalculateZoom(100, 100), new Math.Geo.GeoCoordinate(0, 0), view);

            // ... and finally do the actual rendering.
            renderer.Render(Graphics.FromImage(rendering), map, view);

            //rendering.Save(@"c:\temp\rendering.bmp");

            return rendering;
        }