Example #1
0
        public override IEnumerable <GdiRenderObject> RenderSymbols(IEnumerable <Point2D> locations, Symbol2D symbol,
                                                                    Symbol2D highlightSymbol, Symbol2D selectSymbol,
                                                                    RenderState renderState)
        {
            if (renderState == RenderState.Selected)
            {
                symbol = selectSymbol;
            }
            if (renderState == RenderState.Highlighted)
            {
                symbol = highlightSymbol;
            }

            foreach (Point2D location in locations)
            {
                Bitmap bitmapSymbol = getSymbol(symbol);
                if (bitmapSymbol.PixelFormat != PixelFormat.Undefined)
                {
                    System.Drawing.Drawing2D.Matrix    transform      = ViewConverter.Convert(symbol.AffineTransform);
                    System.Drawing.Imaging.ColorMatrix colorTransform = ViewConverter.Convert(symbol.ColorTransform);
                    RectangleF      bounds = new RectangleF(ViewConverter.Convert(location), bitmapSymbol.Size);
                    GdiRenderObject holder = new GdiRenderObject(bitmapSymbol, bounds, transform, colorTransform);
                    holder.State = renderState;
                    yield return(holder);
                }
                else
                {
                    Debug.WriteLine("Unkbown pixel format");
                }
            }
        }
Example #2
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            if (!_dragging && _mouseDownLocation != Point.Empty && e.Button == MouseButtons.Left)
            {
                _mouseRelativeLocation = new Point(e.X - _mouseDownLocation.X,
                                                   e.Y - _mouseDownLocation.Y);

                if (!withinDragTolerance(e.Location))
                {
                    _dragging = true;
                    _mousePreviousLocation = _mouseDownLocation;
                }
            }

            if (_dragging)
            {
                onMoveTo(ViewConverter.Convert(e.Location));
                _mousePreviousLocation = e.Location;
            }
            else
            {
                onHover(ViewConverter.Convert(e.Location));
            }

            base.OnMouseMove(e);
        }
Example #3
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            _mouseDownLocation = e.Location;

            if (e.Button == MouseButtons.Left) // dragging
            {
                onBeginAction(ViewConverter.Convert(e.Location));
            }

            base.OnMouseDown(e);
        }
Example #4
0
        private void onRequestZoomToViewBounds(Rectangle2D viewBounds)
        {
            EventHandler <MapViewPropertyChangeEventArgs <Rectangle2D> > e = ZoomToViewBoundsRequested;

            if (e != null)
            {
                MapViewPropertyChangeEventArgs <Rectangle2D> args =
                    new MapViewPropertyChangeEventArgs <Rectangle2D>(
                        ViewConverter.Convert(ClientRectangle), viewBounds);

                e(this, args);
            }
        }
Example #5
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);

            if (e.Button == MouseButtons.Left)
            {
                onEndAction(ViewConverter.Convert(e.Location));
            }

            _mouseDownLocation = Point.Empty;

            if (_dragging)
            {
                _dragging = false;
                _mouseRelativeLocation = Point.Empty;
                _mousePreviousLocation = Point.Empty;
            }
        }
Example #6
0
        /// <summary>
        ///  kbd4hire 20090318 Method no longer used!
        /// </summary>
        /// <returns></returns>
        private GdiMatrix getGdiViewTransform()
        {
            if (_gdiViewMatrix == null)
            {
                _gdiViewMatrix = ToViewTransform == null
                                     ? new GdiMatrix()
                                     : ViewConverter.Convert(ToViewTransform);

                return(_gdiViewMatrix);
            }

            Matrix2D viewMatrix = ToViewTransform ?? new Matrix2D();

            Single[] gdiElements = _gdiViewMatrix.Elements;

            if (gdiElements[0] != (Single)viewMatrix.M11 ||
                gdiElements[1] != (Single)viewMatrix.M12 ||
                gdiElements[2] != (Single)viewMatrix.M21 ||
                gdiElements[3] != (Single)viewMatrix.M22 ||
                gdiElements[4] != (Single)viewMatrix.OffsetX ||
                gdiElements[5] != (Single)viewMatrix.OffsetY)
            {
                Debug.WriteLine(
                    String.Format(
                        "Disposing GDI matrix on values: {0} : {1}; {2} : {3}; {4} : {5}; {6} : {7}; {8} : {9}; {10} : {11}",
                        gdiElements[0],
                        (Single)viewMatrix.M11,
                        gdiElements[1],
                        (Single)viewMatrix.M12,
                        gdiElements[2],
                        (Single)viewMatrix.M21,
                        gdiElements[3],
                        (Single)viewMatrix.M22,
                        gdiElements[4],
                        (Single)viewMatrix.OffsetX,
                        gdiElements[5],
                        (Single)viewMatrix.OffsetY));

                _gdiViewMatrix.Dispose();
                _gdiViewMatrix = ViewConverter.Convert(ToViewTransform);
            }

            return(_gdiViewMatrix);
        }
Example #7
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);
        }
Example #8
0
        private static Stream RandomIcon(out Size2D sz)
        {
            sz = RandomSymbolSize();
            Bitmap b = new Bitmap((int)sz.Width, (int)sz.Height);

            Graphics g = Graphics.FromImage(b);

            g.Clear(Color.Transparent);

            int rnd = random.Next(6);

            switch (rnd)
            {
            case 0:
            {
                StylePen p = RandomPen();
                g.DrawEllipse(ViewConverter.Convert(p), (int)Math.Ceiling(p.Width / 2),
                              (int)Math.Ceiling(p.Width / 2), b.Width - (int)p.Width,
                              b.Height - (int)p.Width);
                break;
            }

            case 1:
            {
                g.FillEllipse(ViewConverter.Convert(RandomBrush()), 0, 0, b.Width, b.Height);
                break;
            }

            case 2:
            {
                StylePen p = RandomPen();
                g.DrawRectangle(ViewConverter.Convert(p), (int)Math.Ceiling(p.Width / 2),
                                (int)Math.Ceiling(p.Width / 2), b.Width - (int)p.Width,
                                b.Height - (int)p.Width);
                break;
            }

            case 3:
                g.FillRectangle(ViewConverter.Convert(RandomBrush()), 0, 0, b.Width, b.Height);
                break;

            case 4:
            {
                StylePen p = RandomPen();
                g.FillEllipse(ViewConverter.Convert(RandomBrush()), 0, 0, b.Width, b.Height);
                g.DrawEllipse(ViewConverter.Convert(p), (int)Math.Ceiling(p.Width / 2),
                              (int)Math.Ceiling(p.Width / 2), b.Width - (int)p.Width,
                              b.Height - (int)p.Width);
                break;
            }

            case 5:
            {
                StylePen p = RandomPen();
                g.FillRectangle(ViewConverter.Convert(RandomBrush()), 0, 0, b.Width, b.Height);
                g.DrawRectangle(ViewConverter.Convert(p), (int)Math.Ceiling(p.Width / 2),
                                (int)Math.Ceiling(p.Width / 2), b.Width - (int)p.Width,
                                b.Height - (int)p.Width);
                break;
            }
            }

            MemoryStream ms = new MemoryStream();

            b.Save(ms, ImageFormat.Png);
            return(ms);
        }
Example #9
0
        public virtual WmsMapRequestConfig CreateConfig(HttpContext context)
        {
            WmsMapRequestConfig config = new WmsMapRequestConfig();

            config.ServiceDescription = Description;

            config.CacheKey = CreateCacheKey(context);


            bool ignorecase = true;

            if (context.Request.Params["REQUEST"] == null)
            {
                WmsException.ThrowWmsException("Required parameter REQUEST not specified");
            }

            //Check if version is supported
            if (context.Request.Params["VERSION"] != null)
            {
                if (String.Compare(context.Request.Params["VERSION"], "1.3.0", ignorecase) != 0)
                {
                    WmsException.ThrowWmsException("Only version 1.3.0 supported");
                }
            }
            else
            //Version is mandatory if REQUEST!=GetCapabilities. Check if this is a capabilities request, since VERSION is null
            {
                if (String.Compare(context.Request.Params["REQUEST"], "GetCapabilities", ignorecase) != 0)
                {
                    WmsException.ThrowWmsException("VERSION parameter not supplied");
                }
            }


            if (String.Compare(context.Request.Params["REQUEST"], "GetCapabilities", ignorecase) == 0)
            {
                //Service parameter is mandatory for GetCapabilities request
                if (context.Request.Params["SERVICE"] == null)
                {
                    WmsException.ThrowWmsException("Required parameter SERVICE not specified");
                }

                if (String.Compare(context.Request.Params["SERVICE"], "WMS") != 0)
                {
                    WmsException.ThrowWmsException(
                        "Invalid service for GetCapabilities Request. Service parameter must be 'WMS'");
                }

                config.WmsMode  = WmsMode.Capabilites;
                config.MimeType = "text/xml";
                return(config);
            }

            if (String.Compare(context.Request.Params["REQUEST"], "GetMap", ignorecase) != 0)
            {
                WmsException.ThrowWmsException("Invalid REQUEST parameter");
            }

            config.WmsMode = WmsMode.Map;


            //Check for required parameters
            if (context.Request.Params["LAYERS"] == null)
            {
                WmsException.ThrowWmsException("Required parameter LAYERS not specified");
            }
            config.EnabledLayerNames = new List <string>(context.Request.Params["LAYERS"].Split(','));

            if (context.Request.Params["STYLES"] == null)
            {
                WmsException.ThrowWmsException("Required parameter STYLES not specified");
            }

            if (context.Request.Params["CRS"] == null)
            {
                WmsException.ThrowWmsException("Required parameter CRS not specified");
            }
            config.Crs      = context.Request.Params["CRS"];
            config.BaseSrid = config.Crs;

            if (context.Request.Params["BBOX"] == null)
            {
                WmsException.ThrowWmsException(WmsExceptionCode.InvalidDimensionValue,
                                               "Required parameter BBOX not specified");
            }

            if (context.Request.Params["WIDTH"] == null)
            {
                WmsException.ThrowWmsException(WmsExceptionCode.InvalidDimensionValue,
                                               "Required parameter WIDTH not specified");
            }

            if (context.Request.Params["HEIGHT"] == null)
            {
                WmsException.ThrowWmsException(WmsExceptionCode.InvalidDimensionValue,
                                               "Required parameter HEIGHT not specified");
            }

            if (context.Request.Params["FORMAT"] == null)
            {
                WmsException.ThrowWmsException("Required parameter FORMAT not specified");
            }

            Color bkgnd = Color.White;

            //Set background color of map
            if (String.Compare(context.Request.Params["TRANSPARENT"], "TRUE", ignorecase) == 0)
            {
                bkgnd = Color.Transparent;
            }
            else if (context.Request.Params["BGCOLOR"] != null)
            {
                try
                {
                    bkgnd = ColorTranslator.FromHtml(context.Request.Params["BGCOLOR"]);
                }
                catch
                {
                    WmsException.ThrowWmsException("Invalid parameter BGCOLOR");
                }
                ;
            }


            config.BackgroundColor = ViewConverter.Convert(bkgnd);
            config.MimeType        = context.Request.Params["FORMAT"];

            //Parse map size
            int width  = 0;
            int height = 0;

            if (!int.TryParse(context.Request.Params["WIDTH"], out width))
            {
                WmsException.ThrowWmsException(WmsExceptionCode.InvalidDimensionValue, "Invalid parameter WIDTH");
            }
            else if (Description.MaxWidth > 0 && width > Description.MaxWidth)
            {
                WmsException.ThrowWmsException(WmsExceptionCode.OperationNotSupported, "Parameter WIDTH too large");
            }

            if (!int.TryParse(context.Request.Params["HEIGHT"], out height))
            {
                WmsException.ThrowWmsException(WmsExceptionCode.InvalidDimensionValue, "Invalid parameter HEIGHT");
            }
            else if (Description.MaxHeight > 0 && height > Description.MaxHeight)
            {
                WmsException.ThrowWmsException(WmsExceptionCode.OperationNotSupported, "Parameter HEIGHT too large");
            }


            config.OutputSize = new Size2D(width, height);

            if (context.Request.Params["BBOX"] == null)
            {
                WmsException.ThrowWmsException("Invalid parameter BBOX");
            }

            config.RealWorldBounds = UrlUtility.ParseExtents(new GeometryServices()[config.Crs],
                                                             context.Request.Params["BBOX"]);


            return(config);
        }
Example #10
0
 protected override void OnBackColorChanged(EventArgs e)
 {
     base.OnBackColorChanged(e);
     BackgroundColor = ViewConverter.Convert(BackColor);
 }
Example #11
0
 protected override void SetViewBackgroundColor(StyleColor fromColor, StyleColor toColor)
 {
     ViewControl.BackColor = ViewConverter.Convert(toColor);
 }
Example #12
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);
        }