static void HandleMapNewTileAvaliable(MapViewport map, Graphics g, Envelope box, Bitmap bm, int sourceWidth, int sourceHeight, ImageAttributes imageAttributes)
        {
            try
            {
                var min = map.WorldToImage(box.Min());
                var max = map.WorldToImage(box.Max());

                min = new PointF((float)Math.Round(min.X), (float)Math.Round(min.Y));
                max = new PointF((float)Math.Round(max.X), (float)Math.Round(max.Y));

                g.DrawImage(bm,
                            new Rectangle((int)min.X, (int)max.Y, (int)(max.X - min.X), (int)(min.Y - max.Y)),
                            0, 0,
                            sourceWidth, sourceHeight,
                            GraphicsUnit.Pixel,
                            imageAttributes);

                // g.Dispose();
            }
            catch (Exception ex)
            {
                Logger.Warn(ex.Message, ex);
                //this can be a GDI+ Hell Exception...
            }
        }
        /// <summary>
        /// Renders the layer
        /// </summary>
        /// <param name="g">Graphics object reference</param>
        /// <param name="map">Map which is rendered</param>
        public override void Render(Graphics g, MapViewport map)
        {
            if (map.Center == null)
            {
                throw (new ApplicationException("Cannot render map. View center not specified"));
            }

            if (_image == null)
            {
                throw new Exception("Image not set");
            }


            // View to render
            var mapView = map.Envelope;

            // Layer view
            var lyrView = _envelope;

            // Get the view intersection
            var vi = mapView.Intersection(lyrView);

            if (!vi.IsNull)
            {
                // Image part
// ReSharper disable InconsistentNaming
                var imgLT   = Clip(_worldFile.ToRaster(new Coordinate(vi.MinX, vi.MaxY)));
                var imgRB   = Clip(_worldFile.ToRaster(new Coordinate(vi.MaxX, vi.MinY)));
                var imgRect = new Rectangle(imgLT, PointDiff(imgLT, imgRB, 1));

                // Map Part
                var mapLT   = Point.Truncate(map.WorldToImage(new Coordinate(vi.MinX, vi.MaxY)));
                var mapRB   = Point.Ceiling(map.WorldToImage(new Coordinate(vi.MaxX, vi.MinY)));
                var mapRect = new Rectangle(mapLT, PointDiff(mapLT, mapRB, 1));
// ReSharper restore InconsistentNaming

                // Set the interpolation mode
                var tmpInterpolationMode = g.InterpolationMode;
                g.InterpolationMode = InterpolationMode;

                // Render the image
                using (var ia = new ImageAttributes())
                {
                    ia.SetColorMatrix(new ColorMatrix {
                        Matrix44 = 1 - Transparency
                    },
                                      ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

                    g.DrawImage(_image, mapRect, imgRect.X, imgRect.Y, imgRect.Width, imgRect.Height,
                                GraphicsUnit.Pixel, ia);
                }

                // reset the interpolation mode
                g.InterpolationMode = tmpInterpolationMode;
            }

            // Obsolete (and will cause infinite loop)
            //base.Render(g, map);
        }
Exemple #3
0
        /// <summary>
        /// Very basic test to check for positive direction of Linestring, taking into account map rotation
        /// </summary>
        /// <param name="start">start of text</param>
        /// <param name="end">end of text</param>
        /// <param name="isRightToLeft"></param>
        /// <param name="map"></param>
        /// <returns></returns>
        private static bool LineNeedsReversing(Coordinate start, Coordinate end, bool isRightToLeft, MapViewport map)
        {
            double startX, endX;

            if (map.MapTransform.IsIdentity)
            {
                startX = start.X;
                endX   = end.X;
            }
            else
            {
                var pts = map.WorldToImage(new[] { start, end }, true);
                startX = pts[0].X;
                endX   = pts[1].X;
            }

            var dx = endX - startX;

            if (isRightToLeft && dx < 0)
            {
                return(false);
            }

            return(isRightToLeft || !(dx >= 0));
        }
Exemple #4
0
        private void DrawPoints(MapViewport map, IEnumerable <DataRow> features, Bitmap dot, Bitmap image)
        {
            var size = new Size(dot.Width, dot.Height);

            foreach (FeatureDataRow row in features)
            {
                var heatValue = HeatValueComputer(row);
                if (heatValue <= 0)
                {
                    continue;
                }
                if (heatValue >= 1f)
                {
                    heatValue = 1;
                }

                var c = row.Geometry.PointOnSurface.Coordinate;
                if (CoordinateTransformation != null)
                {
                    c = GeometryTransform.TransformCoordinate(c, CoordinateTransformation.MathTransform);
                }
                var posF = map.WorldToImage(c);
                var pos  = Point.Round(posF);
                //var pos = Point.Round(PointF.Subtract(posF, halfSize));

                using (var tmpDot = ApplyHeatValueToImage(dot, heatValue))
                {
                    ImageBlender.BlendImages(image, pos.X, pos.Y, size.Width, size.Height,
                                             tmpDot, 0, 0, BlendOperation.BlendMultiply);
                }
            }
        }
        public override void RenderAlarm(Graphics g, MapViewport map, bool flag)
        {
            if (!alarm)
            {
                return;
            }
            //忽略不在当前视图范围内的点位
            if (p.X > map.Envelope.MaxX || p.X < map.Envelope.MinX || p.Y > map.Envelope.MaxY || p.Y < map.Envelope.MinY)
            {
                return;
            }
            //世界坐标转换为屏幕坐标
            var _p = map.WorldToImage(p);

            if (Angle == 0)
            {
                g.DrawImage(flag ? iconSet.icon : iconSet.alarm, (int)_p.X - LayerElement.ICON_RADIUS, (int)_p.Y - LayerElement.ICON_RADIUS, LayerElement.ICON_RADIUS * 2, LayerElement.ICON_RADIUS * 2);
            }
            else
            {
                PointF ulCorner = new PointF(_p.X - LayerElement.ICON_RADIUS, _p.Y - LayerElement.ICON_RADIUS);
                PointF a        = MathUtil.GetPointByAngle(ulCorner, _p, Angle);
                PointF b        = MathUtil.GetPointByAngle(ulCorner, _p, Angle + 90);
                PointF c        = MathUtil.GetPointByAngle(ulCorner, _p, Angle + 270);
                g.DrawImage(flag ? iconSet.icon : iconSet.alarm, new PointF[] { a, b, c });
            }
        }
        public override void Render(Graphics g, MapViewport map)
        {
            //忽略不在当前视图范围内的点位
            if (p.X > map.Envelope.MaxX || p.X < map.Envelope.MinX || p.Y > map.Envelope.MaxY || p.Y < map.Envelope.MinY)
            {
                return;
            }

            //世界坐标转换为屏幕坐标
            var _p = map.WorldToImage(p);
            //绘制点
            Bitmap _icon = status == ICON_STATUS.CHECKED ? iconSet.selected : iconSet.icon;

            if (Angle == 0)
            {
                g.DrawImage(_icon, (int)_p.X - ICON_RADIUS, (int)_p.Y - ICON_RADIUS, ICON_RADIUS * 2, ICON_RADIUS * 2);
            }
            else
            {
                PointF ulCorner = new PointF(_p.X - ICON_RADIUS, _p.Y - ICON_RADIUS);
                PointF a        = MathUtil.GetPointByAngle(ulCorner, _p, Angle);
                PointF b        = MathUtil.GetPointByAngle(ulCorner, _p, Angle + 90);
                PointF c        = MathUtil.GetPointByAngle(ulCorner, _p, Angle + 270);
                g.DrawImage(_icon, new PointF[] { a, b, c });
            }
        }
        /// <summary>
        /// Function to render the symbol
        /// </summary>
        /// <param name="map">The map</param>
        /// <param name="point">The point to symbolize</param>
        /// <param name="g">The graphics object</param>
        protected void RenderPoint(MapViewport map, Coordinate point, Graphics g)
        {
            if (point == null)
            {
                return;
            }


            PointF pp = map.WorldToImage(point);

            pp = PointF.Add(pp, GetOffset());

            if (Rotation != 0f && !Single.IsNaN(Rotation))
            {
                Matrix startingTransform = g.Transform.Clone();

                Matrix transform      = g.Transform;
                PointF rotationCenter = pp;
                transform.RotateAt(Rotation, rotationCenter);

                g.Transform = transform;

                OnRenderInternal(pp, g);

                g.Transform = startingTransform;
            }
            else
            {
                OnRenderInternal(pp, g);
            }
        }
        /// <summary>
        /// Function to render the symbol
        /// </summary>
        /// <param name="map">The map</param>
        /// <param name="point">The point to symbolize</param>
        /// <param name="g">The graphics object</param>
        protected void RenderPoint(MapViewport map, Coordinate point, Graphics g)
        {
            if (point == null)
            {
                return;
            }


            PointF pp = map.WorldToImage(point);

            if (Rotation != 0f && !Single.IsNaN(Rotation))
            {
                SizeF offset = GetOffset();

                Matrix startingTransform = g.Transform.Clone();

                Matrix transform = g.Transform;
                transform.Translate(offset.Width + 1, offset.Height + 1);
                PointF rotationCenter = pp;
                transform.RotateAt(Rotation, rotationCenter, MatrixOrder.Append);

                g.Transform = transform;

                OnRenderInternal(pp, g);

                g.Transform = startingTransform;
            }
            else
            {
                pp = PointF.Add(pp, GetOffset());
                OnRenderInternal(pp, g);
            }
        }
        /// <summary>
        /// Transforms an array of <see cref="Coordinate"/>s to an array of <see cref="PointF"/>s.
        /// </summary>
        /// <param name="vertices">The array of coordinates</param>
        /// <param name="map">The map that defines the affine coordinate transformation</param>
        /// <returns>The array of <see cref="PointF"/>s</returns>
        private static PointF[] TransformToImage(Coordinate[] vertices, MapViewport map)
        {
            var v = new PointF[vertices.Length];

            for (var i = 0; i < vertices.Length; i++)
            {
                v[i] = map.WorldToImage(vertices[i]);
            }
            return(v);
        }
 public override bool IsMouseIn(PointF c, MapViewport map)
 {
     foreach (PointF p in Ext.points)
     {
         PointF target = map.WorldToImage(new Coordinate(p.X, p.Y));
         if (LayerElement.IsPoint(target, c) <= LayerElement.ICON_RADIUS)
         {
             return(true);
         }
     }
     return(false);
 }
        public void RenderAlarm(Graphics g, MapViewport map, bool flag, bool alarmMode)
        {
            if (alarmMode && !this.alarm)
            {
                return;
            }
            bool render = false;

            foreach (PointF p in Ext.points)
            {
                if (p.X <= map.Envelope.MaxX && p.X >= map.Envelope.MinX && p.Y <= map.Envelope.MaxY && p.Y >= map.Envelope.MinY)
                {
                    render = true;
                    break;
                }
            }
            //如果当前没有点位在视野里,则取消渲染
            if (!render)
            {
                return;
            }
            //画线
            PointF[] linePoints = new PointF[Ext.points.Length];
            for (int i = 0; i < linePoints.Length; i++)
            {
                linePoints[i] = map.WorldToImage(new Coordinate(Ext.points[i].X, Ext.points[i].Y));
            }

            Color penColor = (this.alarm && flag) || status == ICON_STATUS.CHECKED ? Color.Red : Color.Green;
            Pen   pen      = new Pen(penColor, 13);

            pen.DashStyle   = System.Drawing.Drawing2D.DashStyle.Custom;
            pen.DashPattern = new float[] { 1, 1 };
            g.DrawLines(pen, linePoints);

            //画图标
            for (int i = 0; i < linePoints.Length; i++)
            {
                if (i != 0 && i < linePoints.Length - 1)
                {
                    continue;
                }
                PointF _p = linePoints[i];
                //绘制点图标,报警图标》是否选中》默认图标
                Bitmap renderImage = this.alarm && flag ? iconSet.alarm : (this.status == ICON_STATUS.CHECKED ? iconSet.selected:iconSet.icon);

                if (renderImage != null)
                {
                    g.DrawImage(renderImage, (int)_p.X - LayerElement.ICON_RADIUS, (int)_p.Y - LayerElement.ICON_RADIUS, LayerElement.ICON_RADIUS * 2, LayerElement.ICON_RADIUS * 2);
                }
            }
        }
        public override bool IsMouseIn(PointF c, MapViewport map)
        {
            PointF target  = map.WorldToImage(p);
            double _width  = 0;
            double _height = 0;

            GetSize(out _width, out _height, map);

            PointF a = MathUtil.GetPointByAngle(c, target, -Angle);

            return(a.X >= target.X - _width / 2 && a.X <= target.X + _width / 2 && a.Y >= target.Y - _height / 2 && a.Y <= target.Y + _height / 2);
            //return c.X >= target.X - _width / 2 && c.X <= target.X + _width / 2 && c.Y >= target.Y - _height / 2 && c.Y <= target.Y + _height / 2;
        }
Exemple #13
0
        public static void DrawPoint(Graphics g, IPoint point, Brush b, float size, PointF offset, MapViewport map)
        {
            if (point == null)
            {
                return;
            }

            var pp = map.WorldToImage(point.Coordinate);
            //var startingTransform = g.Transform;

            var width  = size;
            var height = size;

            g.FillEllipse(b, (int)pp.X - width / 2 + offset.X,
                          (int)pp.Y - height / 2 + offset.Y, width, height);
        }
        public static RectangleF DrawPointEx(Graphics g, IPoint point, Brush b, float size, PointF offset, MapViewport map)
        {
            if (point == null)
            {
                return(RectangleF.Empty);
            }

            var pp = map.WorldToImage(point.Coordinate);

            var width  = size;
            var height = size;

            float minX = (int)pp.X - width / 2 + offset.X;
            float minY = (int)pp.Y - height / 2 + offset.Y;

            g.FillEllipse(b, minX, minY, width, height);

            return(new RectangleF(minX, minY, width, height));
        }
        /// <summary>
        /// Function to render the symbol
        /// </summary>
        /// <param name="map">The map</param>
        /// <param name="point">The point to symbolize</param>
        /// <param name="g">The graphics object</param>
        protected void RenderPoint(MapViewport map, Coordinate point, Graphics g)
        {
            if (point == null)
            {
                return;
            }

            PointF pp = map.WorldToImage(point);

            if (Rotation != 0f && !Single.IsNaN(Rotation))
            {
                SizeF  offset         = GetOffset();
                PointF rotationCenter = pp;

                using (var origTrans = g.Transform.Clone())
                    using (var t = g.Transform)
                    {
                        t.RotateAt(Rotation, rotationCenter);
                        t.Translate(offset.Width + 1, offset.Height + 1);
                        g.Transform = t;

                        OnRenderInternal(pp, g);

                        g.Transform = origTrans;
                    }

                using (var symTrans = new Matrix())
                {
                    symTrans.RotateAt(Rotation, rotationCenter);
                    symTrans.Translate(offset.Width + 1, offset.Height + 1);
                    var pts = CanvasArea.ToPointArray();
                    symTrans.TransformPoints(pts);
                    CanvasArea = pts.ToRectangleF();
                }
            }
            else
            {
                pp = PointF.Add(pp, GetOffset());
                OnRenderInternal(pp, g);
            }
        }
        public override void Render(Graphics g, MapViewport map)
        {
            //世界坐标转换为屏幕坐标
            var    _p      = map.WorldToImage(p);
            double _width  = 0;
            double _height = 0;

            GetSize(out _width, out _height, map);

            //绘制点
            if (Angle == 0)
            {
                g.DrawImage(iconSet.icon, (float)(_p.X - _width / 2), (float)(_p.Y - _height / 2), (float)_width, (float)_height);
                if (status == ICON_STATUS.CHECKED)
                {
                    Pen pen = new Pen(Color.Blue);
                    g.DrawRectangle(pen, (float)(_p.X - _width / 2), (float)(_p.Y - _height / 2), (float)_width, (float)_height);
                }
            }
            else
            {
                PointF ulCorner = new PointF((float)(_p.X - _width / 2), (float)(_p.Y - _height / 2));
                PointF a        = MathUtil.GetPointByAngle(ulCorner, _p, Angle);
                ulCorner = new PointF((float)(_p.X + _width / 2), (float)(_p.Y - _height / 2));
                PointF b = MathUtil.GetPointByAngle(ulCorner, _p, Angle);
                ulCorner = new PointF((float)(_p.X - _width / 2), (float)(_p.Y + _height / 2));
                PointF c = MathUtil.GetPointByAngle(ulCorner, _p, Angle);
                g.DrawImage(iconSet.icon, new PointF[] { a, b, c });
                if (status == ICON_STATUS.CHECKED)
                {
                    ulCorner = new PointF((float)(_p.X + _width / 2), (float)(_p.Y + _height / 2));
                    PointF d   = MathUtil.GetPointByAngle(ulCorner, _p, Angle);
                    Pen    pen = new Pen(Color.Blue);
                    g.DrawLines(pen, new PointF[] { a, b, d, c, a });
                }
            }
        }
Exemple #17
0
        private static BaseLabel CreateLabelDefinition(FeatureDataRow fdr, IGeometry geom, string text, float rotation,
                                                       int priority, LabelStyle style, MapViewport map, Graphics g, GetLocationMethod getLocationMethod)
        {
            //ONLY atomic geometries
            Debug.Assert(!(geom is IGeometryCollection));

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

            BaseLabel lbl;
            var       font = style.GetFontForGraphics(g);

            var size = VectorRenderer.SizeOfString(g, text, font);

            if (geom is ILineString ls)
            {
                return(CreatePathLabel(ls, text, size, priority, style, map));
            }

            var worldPosition = getLocationMethod == null
                ? geom.EnvelopeInternal.Centre
                : getLocationMethod(fdr);

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

            var position = map.WorldToImage(worldPosition);

            var location = new PointF(
                position.X - size.Width * (short)style.HorizontalAlignment * 0.5f,
                position.Y - size.Height * (short)(2 - (int)style.VerticalAlignment) * 0.5f);

            if (location.X - size.Width > map.Size.Width || location.X + size.Width < 0 ||
                location.Y - size.Height > map.Size.Height || location.Y + size.Height < 0)
            {
                return(null);
            }

            if (!style.CollisionDetection)
            {
                lbl = new Label(text, location, rotation, priority, null, style)
                {
                    LabelPoint = position
                }
            }
            ;
            else
            {
                //Collision detection is enabled so we need to measure the size of the string
                lbl = new Label(text, location, rotation, priority,
                                new LabelBox(location.X - style.CollisionBuffer.Width,
                                             location.Y - style.CollisionBuffer.Height,
                                             size.Width + 2f * style.CollisionBuffer.Width,
                                             size.Height + 2f * style.CollisionBuffer.Height), style)
                {
                    LabelPoint = position
                };
            }

            return(lbl);
        }
Exemple #18
0
        /// <summary>
        /// Renders the layer
        /// </summary>
        /// <param name="graphics">Graphics object reference</param>
        /// <param name="map">Map which is rendered</param>
        public override void Render(Graphics graphics, MapViewport map)
        {
            if (!map.Size.IsEmpty && map.Size.Width > 0 && map.Size.Height > 0)
            {
                var bmp = new Bitmap(map.Size.Width, map.Size.Height, PixelFormat.Format32bppArgb);

                using (var g = Graphics.FromImage(bmp))
                {
                    g.InterpolationMode = InterpolationMode;
                    g.Transform         = graphics.Transform.Clone();

                    var extent = new Extent(map.Envelope.MinX, map.Envelope.MinY,
                                            map.Envelope.MaxX, map.Envelope.MaxY);
                    var level      = BruTile.Utilities.GetNearestLevel(_source.Schema.Resolutions, Math.Max(map.PixelWidth, map.PixelHeight));
                    var tiles      = new List <TileInfo>(_source.Schema.GetTileInfos(extent, level));
                    var tileWidth  = _source.Schema.GetTileWidth(level);
                    var tileHeight = _source.Schema.GetTileWidth(level);

                    IList <WaitHandle> waitHandles = new List <WaitHandle>();
                    var toRender       = new System.Collections.Concurrent.ConcurrentDictionary <TileIndex, Bitmap>();
                    var takenFromCache = new System.Collections.Concurrent.ConcurrentDictionary <TileIndex, bool>();
                    foreach (TileInfo info in tiles)
                    {
                        var image = _bitmaps.Find(info.Index);
                        if (image != null)
                        {
                            toRender.TryAdd(info.Index, image);
                            takenFromCache.TryAdd(info.Index, true);
                            continue;
                        }
                        if (_fileCache != null && _fileCache.Exists(info.Index))
                        {
                            var tileBitmap = GetImageFromFileCache(info) as Bitmap;
                            _bitmaps.Add(info.Index, tileBitmap);
                            toRender.TryAdd(info.Index, tileBitmap);
                            takenFromCache.TryAdd(info.Index, true);
                            continue;
                        }

                        var waitHandle = new AutoResetEvent(false);
                        waitHandles.Add(waitHandle);
                        ThreadPool.QueueUserWorkItem(GetTileOnThread,
                                                     new object[] { _source, info, toRender, waitHandle, true, takenFromCache });
                    }

                    foreach (var handle in waitHandles)
                    {
                        handle.WaitOne();
                    }

                    using (var ia = new ImageAttributes())
                    {
                        if (!_transparentColor.IsEmpty)
                        {
                            ia.SetColorKey(_transparentColor, _transparentColor);
                        }
#if !PocketPC
                        ia.SetWrapMode(WrapMode.TileFlipXY);
#endif

                        foreach (var info in tiles)
                        {
                            if (!toRender.ContainsKey(info.Index))
                            {
                                continue;
                            }

                            var bitmap = toRender[info.Index];//_bitmaps.Find(info.Index);
                            if (bitmap == null)
                            {
                                continue;
                            }

                            var min = map.WorldToImage(new Coordinate(info.Extent.MinX, info.Extent.MinY));
                            var max = map.WorldToImage(new Coordinate(info.Extent.MaxX, info.Extent.MaxY));

                            min = new PointF((float)Math.Round(min.X), (float)Math.Round(min.Y));
                            max = new PointF((float)Math.Round(max.X), (float)Math.Round(max.Y));

                            try
                            {
                                g.DrawImage(bitmap,
                                            new Rectangle((int)min.X, (int)max.Y, (int)(max.X - min.X),
                                                          (int)(min.Y - max.Y)),
                                            0, 0, tileWidth, tileHeight,
                                            GraphicsUnit.Pixel,
                                            ia);
                            }
                            catch (Exception ee)
                            {
                                Logger.Error(ee.Message);
                            }
                        }
                    }

                    //Add rendered tiles to cache
                    foreach (var kvp in toRender)
                    {
                        if (takenFromCache.ContainsKey(kvp.Key) && !takenFromCache[kvp.Key])
                        {
                            _bitmaps.Add(kvp.Key, kvp.Value);
                        }
                    }

                    graphics.Transform = new Matrix();
                    graphics.DrawImageUnscaled(bmp, 0, 0);
                    graphics.Transform = g.Transform;
                }
            }
        }
Exemple #19
0
        // <summary>

        #region ILayer Members

        /// <summary>
        /// Renders the layer
        /// </summary>
        /// <param name="g">Graphics object reference</param>
        /// <param name="map">Map which is rendered</param>
        public override void Render(Graphics g, MapViewport map)
        {
            Bitmap bitmap = null;

            try
            {
                foreach (string key in _TileSetsActive)
                {
                    TileSet tileSet = _TileSets[key];

                    tileSet.Verify();

                    List <Envelope> tileExtents = TileExtents.GetTileExtents(tileSet, map.Envelope, Math.Max(map.PixelWidth, map.PixelHeight));

                    if (logger.IsDebugEnabled)
                    {
                        logger.DebugFormat("TileCount: {0}", tileExtents.Count);
                    }

                    //TODO: Retrieve several tiles at the same time asynchronously to improve performance. PDD.
                    foreach (Envelope tileExtent in tileExtents)
                    {
                        if (bitmap != null)
                        {
                            bitmap.Dispose();
                        }

                        if ((tileSet.TileCache != null) && (tileSet.TileCache.ContainsTile(tileExtent)))
                        {
                            bitmap = tileSet.TileCache.GetTile(tileExtent);
                        }
                        else
                        {
                            bitmap = WmsGetMap(tileExtent, tileSet);
                            if ((tileSet.TileCache != null) && (bitmap != null))
                            {
                                tileSet.TileCache.AddTile(tileExtent, bitmap);
                            }
                        }

                        if (bitmap != null)
                        {
                            PointF destMin = map.WorldToImage(tileExtent.Min());
                            PointF destMax = map.WorldToImage(tileExtent.Max());

                            double minX = (int)Math.Round(destMin.X);
                            double minY = (int)Math.Round(destMax.Y);
                            double maxX = (int)Math.Round(destMax.X);
                            double maxY = (int)Math.Round(destMin.Y);

                            g.DrawImage(bitmap,
                                        new Rectangle((int)minX, (int)minY, (int)(maxX - minX), (int)(maxY - minY)),
                                        0, 0, tileSet.Width, tileSet.Height,
                                        GraphicsUnit.Pixel, _ImageAttributes);
                        }
                    }
                }
            }
            finally
            {
                if (bitmap != null)
                {
                    bitmap.Dispose();
                }
            }
        }
        public override bool IsMouseIn(PointF c, MapViewport map)
        {
            PointF target = map.WorldToImage(p);

            return(IsPoint(target, c) <= LayerElement.ICON_RADIUS);
        }
Exemple #21
0
        private static void CalculateLabelAroundOnLineString(ILineString line, ref BaseLabel label, MapViewport map, System.Drawing.Graphics g, System.Drawing.SizeF textSize)
        {
            var sPoints = line.Coordinates;

            // only get point in enverlop of map
            var colPoint      = new Collection <PointF>();
            var bCheckStarted = false;

            //var testEnvelope = map.Envelope.Grow(map.PixelSize*10);
            for (var j = 0; j < sPoints.Length; j++)
            {
                if (map.Envelope.Contains(sPoints[j]))
                {
                    //points[j] = map.WorldToImage(sPoints[j]);
                    colPoint.Add(map.WorldToImage(sPoints[j]));
                    bCheckStarted = true;
                }
                else if (bCheckStarted)
                {
                    // fix bug curved line out of map in center segment of line
                    break;
                }
            }

            if (colPoint.Count > 1)
            {
                label.TextOnPathLabel = new TextOnPath();
                switch (label.Style.HorizontalAlignment)
                {
                case LabelStyle.HorizontalAlignmentEnum.Left:
                    label.TextOnPathLabel.TextPathAlignTop = TextPathAlign.Left;
                    break;

                case LabelStyle.HorizontalAlignmentEnum.Right:
                    label.TextOnPathLabel.TextPathAlignTop = TextPathAlign.Right;
                    break;

                case LabelStyle.HorizontalAlignmentEnum.Center:
                    label.TextOnPathLabel.TextPathAlignTop = TextPathAlign.Center;
                    break;

                default:
                    label.TextOnPathLabel.TextPathAlignTop = TextPathAlign.Center;
                    break;
                }
                switch (label.Style.VerticalAlignment)
                {
                case LabelStyle.VerticalAlignmentEnum.Bottom:
                    label.TextOnPathLabel.TextPathPathPosition = TextPathPosition.UnderPath;
                    break;

                case LabelStyle.VerticalAlignmentEnum.Top:
                    label.TextOnPathLabel.TextPathPathPosition = TextPathPosition.OverPath;
                    break;

                case LabelStyle.VerticalAlignmentEnum.Middle:
                    label.TextOnPathLabel.TextPathPathPosition = TextPathPosition.CenterPath;
                    break;

                default:
                    label.TextOnPathLabel.TextPathPathPosition = TextPathPosition.CenterPath;
                    break;
                }

                var idxStartPath = 0;
                var numberPoint  = colPoint.Count;
                // start Optimzes Path points

                var step = 100;
                if (colPoint.Count >= step * 2)
                {
                    numberPoint = step * 2;;
                    switch (label.Style.HorizontalAlignment)
                    {
                    case LabelStyle.HorizontalAlignmentEnum.Left:
                        //label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Left;
                        idxStartPath = 0;
                        break;

                    case LabelStyle.HorizontalAlignmentEnum.Right:
                        //label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Right;
                        idxStartPath = colPoint.Count - step;
                        break;

                    case LabelStyle.HorizontalAlignmentEnum.Center:
                        //label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Center;
                        idxStartPath = (int)colPoint.Count / 2 - step;
                        break;

                    default:
                        //label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Center;
                        idxStartPath = (int)colPoint.Count / 2 - step;
                        break;
                    }
                }
                // end optimize path point
                var points = new PointF[numberPoint];
                var count  = 0;
                if (colPoint[0].X <= colPoint[colPoint.Count - 1].X)
                {
                    for (var l = idxStartPath; l < numberPoint + idxStartPath; l++)
                    {
                        points[count] = colPoint[l];
                        count++;
                    }
                }
                else
                {
                    //reverse the path
                    for (var k = numberPoint - 1 + idxStartPath; k >= idxStartPath; k--)
                    {
                        points[count] = colPoint[k];
                        count++;
                    }
                }

                /*
                 * //get text size in page units ie pixels
                 * float textheight = label.Style.Font.Size;
                 * switch (label.Style.Font.Unit)
                 * {
                 *  case GraphicsUnit.Display:
                 *      textheight = textheight * g.DpiY / 75;
                 *      break;
                 *  case GraphicsUnit.Document:
                 *      textheight = textheight * g.DpiY / 300;
                 *      break;
                 *  case GraphicsUnit.Inch:
                 *      textheight = textheight * g.DpiY;
                 *      break;
                 *  case GraphicsUnit.Millimeter:
                 *      textheight = (float)(textheight / 25.4 * g.DpiY);
                 *      break;
                 *  case GraphicsUnit.Pixel:
                 *      //do nothing
                 *      break;
                 *  case GraphicsUnit.Point:
                 *      textheight = textheight * g.DpiY / 72;
                 *      break;
                 * }
                 * var topFont = new Font(label.Style.Font.FontFamily, textheight, label.Style.Font.Style, GraphicsUnit.Pixel);
                 */
                var topFont = label.Style.GetFontForGraphics(g);
                //
                var path = new GraphicsPath();
                path.AddLines(points);

                label.TextOnPathLabel.PathColorTop          = System.Drawing.Color.Transparent;
                label.TextOnPathLabel.Text                  = label.Text;
                label.TextOnPathLabel.LetterSpacePercentage = 90;
                label.TextOnPathLabel.FillColorTop          = new System.Drawing.SolidBrush(label.Style.ForeColor);
                label.TextOnPathLabel.Font                  = topFont;
                label.TextOnPathLabel.PathDataTop           = path.PathData;
                label.TextOnPathLabel.Graphics              = g;
                //label.TextOnPathLabel.ShowPath=true;
                //label.TextOnPathLabel.PathColorTop = System.Drawing.Color.YellowGreen;
                if (label.Style.Halo != null)
                {
                    label.TextOnPathLabel.ColorHalo = label.Style.Halo;
                }
                else
                {
                    label.TextOnPathLabel.ColorHalo = null;// new System.Drawing.Pen(label.Style.ForeColor, (float)0.5);
                }
                path.Dispose();

                // MeasureString to get region
                label.TextOnPathLabel.MeasureString = true;
                label.TextOnPathLabel.DrawTextOnPath();
                label.TextOnPathLabel.MeasureString = false;
                // Get Region label for CollissionDetection here.
                var pathRegion = new GraphicsPath();

                if (label.TextOnPathLabel.RegionList.Count > 0)
                {
                    //int idxCenter = (int)label.TextOnPathLabel.PointsText.Count / 2;
                    //System.Drawing.Drawing2D.Matrix rotationMatrix = g.Transform.Clone();// new Matrix();
                    //rotationMatrix.RotateAt(label.TextOnPathLabel.Angles[idxCenter], label.TextOnPathLabel.PointsText[idxCenter]);
                    //if (label.TextOnPathLabel.PointsTextUp.Count > 0)
                    //{
                    //    for (int up = label.TextOnPathLabel.PointsTextUp.Count - 1; up >= 0; up--)
                    //    {
                    //        label.TextOnPathLabel.PointsText.Add(label.TextOnPathLabel.PointsTextUp[up]);
                    //    }

                    //}
                    pathRegion.AddRectangles(label.TextOnPathLabel.RegionList.ToArray());

                    // get box for detect colission here
                    label.Box = new LabelBox(pathRegion.GetBounds());
                    //g.FillRectangle(System.Drawing.Brushes.YellowGreen, label.Box);
                }
                pathRegion.Dispose();
            }
        }
Exemple #22
0
        private static BaseLabel CreateLabel(FeatureDataRow fdr, IGeometry feature, string text, float rotation, int priority, LabelStyle style, MapViewport map, Graphics g, GetLocationMethod _getLocationMethod)
        {
            if (feature == null)
            {
                return(null);
            }

            BaseLabel lbl  = null;
            var       font = style.GetFontForGraphics(g);

            SizeF size = VectorRenderer.SizeOfString(g, text, font);

            if (feature is ILineal)
            {
                var line = feature as ILineString;
                if (line != null)
                {
                    if (style.IsTextOnPath == false)
                    {
                        if (size.Width < 0.95 * line.Length / map.PixelWidth || style.IgnoreLength)
                        {
                            var positiveLineString = PositiveLineString(line, false);
                            var lineStringPath     = LineStringToPath(positiveLineString, map /*, false*/);
                            var rect = lineStringPath.GetBounds();

                            if (style.CollisionDetection && !style.CollisionBuffer.IsEmpty)
                            {
                                var cbx = style.CollisionBuffer.Width;
                                var cby = style.CollisionBuffer.Height;
                                rect.Inflate(2 * cbx, 2 * cby);
                                rect.Offset(-cbx, -cby);
                            }
                            var labelBox = new LabelBox(rect);

                            lbl = new PathLabel(text, lineStringPath, 0, priority, labelBox, style);
                        }
                    }
                    else
                    {
                        //get centriod
                        System.Drawing.PointF position2 = map.WorldToImage(feature.EnvelopeInternal.Centre);
                        lbl = new Label(text, position2, rotation, priority, style);
                        if (size.Width < 0.95 * line.Length / map.PixelWidth || !style.IgnoreLength)
                        {
                            CalculateLabelAroundOnLineString(line, ref lbl, map, g, size);
                        }
                    }
                }
                return(lbl);
            }

            var worldPosition = _getLocationMethod == null
                ? feature.EnvelopeInternal.Centre
                : _getLocationMethod(fdr);

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

            var position = map.WorldToImage(worldPosition);

            var location = new PointF(
                position.X - size.Width * (short)style.HorizontalAlignment * 0.5f,
                position.Y - size.Height * (short)(2 - (int)style.VerticalAlignment) * 0.5f);

            if (location.X - size.Width > map.Size.Width || location.X + size.Width < 0 ||
                location.Y - size.Height > map.Size.Height || location.Y + size.Height < 0)
            {
                return(null);
            }

            if (!style.CollisionDetection)
            {
                lbl = new Label(text, location, rotation, priority, null, style)
                {
                    LabelPoint = position
                }
            }
            ;
            else
            {
                //Collision detection is enabled so we need to measure the size of the string
                lbl = new Label(text, location, rotation, priority,
                                new LabelBox(location.X - style.CollisionBuffer.Width,
                                             location.Y - style.CollisionBuffer.Height,
                                             size.Width + 2f * style.CollisionBuffer.Width,
                                             size.Height + 2f * style.CollisionBuffer.Height), style)
                {
                    LabelPoint = position
                };
            }

            /*
             * if (feature is LineString)
             * {
             *  var line = feature as LineString;
             *
             *  //Only label feature if it is long enough, or it is definately wanted
             *  if (line.Length / map.PixelSize > size.Width || style.IgnoreLength)
             *  {
             *      CalculateLabelOnLinestring(line, ref lbl, map);
             *  }
             *  else
             *      return null;
             * }
             */
            return(lbl);
        }
Exemple #23
0
        public static void DrawPoint(Graphics g, IPoint point, Image symbol, float symbolscale, PointF offset,
                                     float rotation, MapViewport map)
        {
            if (point == null)
            {
                return;
            }

            if (symbol == null) //We have no point style - Use a default symbol
            {
                symbol = Defaultsymbol;
            }


            var pp = map.WorldToImage(point.Coordinate);

            lock (symbol)
            {
                if (rotation != 0 && !Single.IsNaN(rotation))
                {
                    var startingTransform = g.Transform.Clone();

                    var transform      = g.Transform;
                    var rotationCenter = pp;
                    transform.RotateAt(rotation, rotationCenter);
                    g.Transform = transform;

                    //if (symbolscale == 1f)
                    //{
                    //    g.DrawImage(symbol,  (pp.X - symbol.Width/2f + offset.X),
                    //                                (pp.Y - symbol.Height/2f + offset.Y));
                    //}
                    //else
                    //{
                    //    var width = symbol.Width*symbolscale;
                    //    var height = symbol.Height*symbolscale;
                    //    g.DrawImage(symbol, (int) pp.X - width/2 + offset.X*symbolscale,
                    //                        (int) pp.Y - height/2 + offset.Y*symbolscale, width, height);
                    //}
                    var width  = symbol.Width * symbolscale;
                    var height = symbol.Height * symbolscale;
                    g.DrawImage(symbol, pp.X - width / 2 + offset.X * symbolscale,
                                pp.Y - height / 2 + offset.Y * symbolscale, width, height);
                    g.Transform = startingTransform;
                }
                else
                {
                    //if (symbolscale == 1f)
                    //{
                    //    g.DrawImageUnscaled(symbol, (int) (pp.X - symbol.Width/2f + offset.X),
                    //                                (int) (pp.Y - symbol.Height/2f + offset.Y));
                    //}
                    //else
                    //{
                    //    var width = symbol.Width*symbolscale;
                    //    var height = symbol.Height*symbolscale;
                    //    g.DrawImage(symbol, (int) pp.X - width/2 + offset.X*symbolscale,
                    //                        (int) pp.Y - height/2 + offset.Y*symbolscale, width, height);
                    //}
                    var width  = symbol.Width * symbolscale;
                    var height = symbol.Height * symbolscale;
                    g.DrawImage(symbol, pp.X - width / 2 + offset.X * symbolscale,
                                pp.Y - height / 2 + offset.Y * symbolscale, width, height);
                }
            }
        }
        public static RectangleF DrawPointEx(Graphics g, IPoint point, Image symbol, float symbolScale, PointF offset,
                                             float rotation, MapViewport map)
        {
            if (point == null)
            {
                return(RectangleF.Empty);
            }

            if (symbol == null) //We have no point style - Use a default symbol
            {
                symbol = _defaultSymbol;
            }

            var pp = map.WorldToImage(point.Coordinate);

            float width  = symbol.Width * symbolScale;
            float height = symbol.Height * symbolScale;
            float left   = pp.X - width / 2 + offset.X * symbolScale;
            float top    = pp.Y - height / 2 + offset.Y * symbolScale;

            Matrix symTrans  = null;
            Matrix origTrans = null;

            if (rotation != 0 && !Single.IsNaN(rotation))
            {
                origTrans = g.Transform.Clone();

                using (var t = g.Transform.Clone())
                {
                    t.RotateAt(rotation, pp);
                    g.Transform = t;
                }

                symTrans = new Matrix();
                symTrans.RotateAt(rotation, pp);
            }

            lock (symbol)
            {
                g.DrawImage(symbol, left, top, width, height);
            }

            if (origTrans != null)
            {
                g.Transform = origTrans;
                origTrans.Dispose();
            }

            if (symTrans == null)
            {
                return(new RectangleF(left, top, width, height));
            }

            var pts = new[]
            {
                new PointF(left, top),
                new PointF(left + width, top),
                new PointF(left + width, top + height),
                new PointF(left, top + height)
            };

            symTrans.TransformPoints(pts);
            symTrans.Dispose();
            return(pts.ToRectangleF());
        }