Esempio n. 1
0
        Stream IWebMapRenderer.Render(WebMapView mapView, out string mimeType)
        {
            MemoryStream ms = new MemoryStream();
            StreamWriter sw = new StreamWriter(ms);

            sw.Write(Render(mapView, out mimeType));
            sw.Flush();

            ms.Position = 0;
            return(ms);
        }
        protected virtual Stream RenderStreamInternal(WebMapView map, out string mimeType)
        {
            Image im = Render(map, out mimeType);

            if (im == null)
            {
                return(null);
            }

            MemoryStream ms = new MemoryStream();

            im.Save(ms, ImageCodec, EncoderParams);
            im.Dispose();
            ms.Seek(0, SeekOrigin.Begin);
            mimeType = ImageCodec.MimeType;
            return(ms);
        }
        public Image Render(WebMapView mapView, out string mimeType)
        {
            using (Surface s = CreateImageSurface())
            {
                Context c = new Context(s);
                c.FillRule  = FillRule.EvenOdd;
                c.Antialias = Antialias.Subpixel;
                if (!MapView.Presenter.IsRenderingSelection)
                {
                    SetColour(c, MapView.BackgroundColor);
                }
                else
                {
                    SetColour(c, new StyleColor(0, 0, 0, 0));
                }

                c.FillExtents();

                while (_renderQueue.Count > 0)
                {
                    RenderObject(_renderQueue.Dequeue(), c);
                }

                Bitmap bmp = new Bitmap(Width, Height, PixelFormat.Format32bppArgb);
                using (Graphics graphics = Graphics.FromImage(bmp))
                    using (Win32Surface winSurface = new Win32Surface(graphics.GetHdc()))
                        using (Context context = new Context(winSurface))
                        {
                            context.SetSourceRGBA(0, 0, 0, 0);
                            context.FillExtents();

                            context.SetSource(s);
                            context.Paint();
                        }

                mimeType = "image/bmp";
                return(bmp);
            }
        }
Esempio n. 4
0
        public Image Render(WebMapView mapView, out string mimeType)
        {
            Bitmap   bmp = new Bitmap(Width, Height, PixelFormat);
            Graphics g   = Graphics.FromImage(bmp);

            g.SmoothingMode = SmoothingMode.AntiAlias;

            //g.Transform = GetGdiViewTransform();
            if (!MapView.Presenter.IsRenderingSelection)
            {
                g.Clear(ViewConverter.Convert(MapView.BackgroundColor));
            }


            while (_renderQ.Count > 0)
            {
                RenderObject(_renderQ.Dequeue(), g);
            }

            g.Dispose();

            mimeType = "image/bmp";
            return(bmp);
        }
Esempio n. 5
0
        public string Render(WebMapView mapView, out string mimeType)
        {
            mimeType = "application/json";

            StringBuilder sb = new StringBuilder();

            sb.Append("{");
            sb.Append(JsonUtility.FormatJsonAttribute("type", "FeatureCollection"));
            sb.Append(",");

            sb.Append("\"features\":");
            sb.Append("[");
            while (_renderQueue.Count > 0)
            {
                sb.Append(_renderQueue.Dequeue().Json);
                if (_renderQueue.Count > 0)
                {
                    sb.Append(",");
                }
            }
            sb.Append("]");
            sb.Append("}");
            return(sb.ToString());
        }
 Stream IWebMapRenderer.Render(WebMapView mapView, out string mimeType)
 {
     return(RenderStreamInternal(mapView, out mimeType));
 }
Esempio n. 7
0
        protected override Stream RenderStreamInternal(WebMapView map, out string mimeType)
        {
            Stream stream = base.RenderStreamInternal(map, out mimeType);

            if (MapView.BackgroundColor == StyleColor.Transparent &&
                TransparentColorIndex.HasValue &&
                ImageCodec.Clsid == FindCodec("image/gif").Clsid)
            {
                Color trans = ViewConverter.Convert(MapView.BackgroundColor);

                using (Bitmap bmpSrc = new Bitmap(stream))
                {
                    using (Bitmap bmpTrgt = new Bitmap(bmpSrc.Width, bmpSrc.Height, PixelFormat.Format8bppIndexed))
                    {
                        ColorPalette cp  = bmpSrc.Palette;
                        ColorPalette ncp = bmpTrgt.Palette;

                        int n = 0;
                        foreach (Color c in cp.Entries)
                        {
                            ncp.Entries[n++] = Color.FromArgb(255, c);
                        }


                        ncp.Entries[TransparentColorIndex.Value] = Color.FromArgb(0, ncp.Entries[TransparentColorIndex.Value]);
                        bmpTrgt.Palette = ncp;


                        BitmapData src =
                            bmpSrc.LockBits(new Rectangle(0, 0, bmpSrc.Width, bmpSrc.Height),
                                            ImageLockMode.ReadOnly, bmpSrc.PixelFormat);

                        BitmapData dst =
                            bmpTrgt.LockBits(new Rectangle(0, 0, bmpTrgt.Width, bmpTrgt.Height), ImageLockMode.WriteOnly,
                                             bmpTrgt.PixelFormat);


                        unsafe
                        {
                            for (int y = 0; y < bmpSrc.Height; y++)
                            {
                                for (int x = 0; x < bmpSrc.Width; x++)
                                {
                                    ((byte *)dst.Scan0.ToPointer())[(dst.Stride * y) + x] =
                                        ((byte *)src.Scan0.ToPointer())[(src.Stride * y) + x];
                                }
                            }
                        }

                        bmpSrc.UnlockBits(src);
                        bmpTrgt.UnlockBits(dst);

                        MemoryStream ms = new MemoryStream();
                        bmpTrgt.Save(ms, ImageFormat.Gif);

                        return(ms);
                    }
                }
            }


            return(stream);
        }
Esempio n. 8
0
 public void ConfigureMapView()
 {
     MapView = new WebMapView(this);
     MapRequestConfig.ConfigureMapView(MapView);
 }