Esempio n. 1
0
        private static Label CreateLabel(Geometry feature, string text, float rotation, int priority, LabelStyle style, Map map,
                                         Graphics g)
        {
            //SizeF size = g.MeasureString(text, style.Font);

            SizeF size = VectorRenderer.SizeOfString(g, text, style.Font);
            //PointF position = map.WorldToImage(feature.GetBoundingBox().GetCentroid());
            PointF position = Transform.WorldtoMap(feature.GetBoundingBox().GetCentroid(), map);

            position.X = position.X - size.Width * (short)style.HorizontalAlignment * 0.5f;
            position.Y = position.Y - size.Height * (short)(2 - (int)style.VerticalAlignment) * 0.5f;
            if (position.X - size.Width > map.Size.Width || position.X + size.Width < 0 ||
                position.Y - size.Height > map.Size.Height || position.Y + size.Height < 0)
            {
                return(null);
            }

            Label lbl;

            if (!style.CollisionDetection)
            {
                lbl = new Label(text, position, rotation, priority, null, style);
            }
            else
            {
                //Collision detection is enabled so we need to measure the size of the string
                lbl = new Label(text, position, rotation, priority,
                                new LabelBox(position.X - size.Width * 0.5f - style.CollisionBuffer.Width,
                                             position.Y + size.Height * 0.5f + style.CollisionBuffer.Height,
                                             size.Width + 2f * style.CollisionBuffer.Width,
                                             size.Height + style.CollisionBuffer.Height * 2f), style);
            }
            if (feature is LineString)
            {
                LineString 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);
        }
        /// <summary>
        /// Method to compute the item size
        /// </summary>
        /// <param name="g"></param>
        /// <param name="map"></param>
        /// <returns></returns>
        public Size ComputeItemSize(Graphics g)
        {
            var width  = 0;
            var height = 0;

            if (Symbol != null)
            {
                height = Math.Max(height, Symbol.Size.Height);
                width += Symbol.Size.Width + Padding.Width;
            }

            if (!string.IsNullOrEmpty(Label))
            {
                var labelSize = Size.Ceiling(VectorRenderer.SizeOfString(g, Label, LabelFont));
                height = Math.Max(height, labelSize.Height);
                width += labelSize.Width + Padding.Width;
            }

            return(new Size(width > 0 ? width - Padding.Width : 0, height));
        }
Esempio n. 3
0
        private void RenderDisclaimer(Graphics g)
        {
            StringFormat sf;

            //Disclaimer
            if (!String.IsNullOrEmpty(_disclaimer))
            {
                SizeF size = VectorRenderer.SizeOfString(g, _disclaimer, _disclaimerFont);
                size.Width  = (Single)Math.Ceiling(size.Width);
                size.Height = (Single)Math.Ceiling(size.Height);
                switch (DisclaimerLocation)
                {
                case 0:     //Right-Bottom
                    sf           = new StringFormat();
                    sf.Alignment = StringAlignment.Far;
                    g.DrawString(Disclaimer, DisclaimerFont, Brushes.Black,
                                 g.VisibleClipBounds.Width,
                                 g.VisibleClipBounds.Height - size.Height - 2, sf);
                    break;

                case 1:     //Right-Top
                    sf           = new StringFormat();
                    sf.Alignment = StringAlignment.Far;
                    g.DrawString(Disclaimer, DisclaimerFont, Brushes.Black,
                                 g.VisibleClipBounds.Width, 0f, sf);
                    break;

                case 2:     //Left-Top
                    g.DrawString(Disclaimer, DisclaimerFont, Brushes.Black, 0f, 0f);
                    break;

                case 3:    //Left-Bottom
                    g.DrawString(Disclaimer, DisclaimerFont, Brushes.Black, 0f,
                                 g.VisibleClipBounds.Height - size.Height - 2);
                    break;
                }
            }
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        private static BaseLabel CreateLabel(Geometry feature, string text, float rotation, int priority, LabelStyle style, Map map,
                                             Graphics g)
        {
            BaseLabel lbl = null;

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

            if (feature is ILineal)
            {
                var line = feature as LineString;
                if (line != null)
                {
                    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);
                    }
                }
                return(lbl);
            }

            PointF position = Transform.WorldtoMap(feature.GetBoundingBox().GetCentroid(), map);

            position.X = position.X - size.Width * (short)style.HorizontalAlignment * 0.5f;
            position.Y = position.Y - size.Height * (short)(2 - (int)style.VerticalAlignment) * 0.5f;
            if (position.X - size.Width > map.Size.Width || position.X + size.Width < 0 ||
                position.Y - size.Height > map.Size.Height || position.Y + size.Height < 0)
            {
                return(null);
            }

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

            /*
             * 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);
        }
Esempio n. 6
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);
        }