ThinkGeo.com    |     Documentation    |     Premium Support

Overlapped labels

Hi, first of all congrats for the good work with v6, i'm facing an issue with the labeling in my proyect here's the code i'm using



ShapeFileFeatureLayer neivaLabelsLayer = new ShapeFileFeatureLayer(MapsDirectory + @"Huila\NEIVA_text.shp");
            ShapeFileFeatureLayer.BuildIndexFile(MapsDirectory + @"Huila\NEIVA_text.shp");
            ColumnBasedTextStyle objColumnBasedTextStyle = new ColumnBasedTextStyle("TEXTSTRING", "ANGLE");
            neivaLabelsLayer.ZoomLevelSet.ZoomLevel16.CustomStyles.Add(objColumnBasedTextStyle);
            neivaLabelsLayer.ZoomLevelSet.ZoomLevel16.DefaultTextStyle.SuppressPartialLabels = true;
            neivaLabelsLayer.ZoomLevelSet.ZoomLevel16.DefaultTextStyle.OverlappingRule = LabelOverlappingRule.NoOverlapping;
            neivaLabelsLayer.ZoomLevelSet.ZoomLevel16.DefaultTextStyle.GridSize = 1500;
            neivaLabelsLayer.ZoomLevelSet.ZoomLevel16.DefaultTextStyle.TextLineSegmentRatio = 0.2;
            neivaLabelsLayer.ZoomLevelSet.ZoomLevel16.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            neivaLabelsLayer.DrawingMarginPercentage = 1000;
            neivaLabelsLayer.ReadWriteMode = ShapeFileReadWriteMode.ReadOnly;
            neivaLabelsLayer.DrawingQuality = DrawingQuality.HighSpeed;
  And this how it's looking:



No matter what values i use for GridSize or TextLineRatio it looks the same, these properties must be set in the ColumnBasedTextStyle? (wich it's the sameone from your samplecodes with a little modifications, i've supressed the color and font properties).


Thanks for your attention.


P.S. i'm using the production dailybuilds v6.0.0.58 libraries.



Hi Fernando, 
  
 Sorry I haven’t reproduced your issue local. I am using 6.0.0.58 dlls, and test code like this: 
  
  
    ShapeFileFeatureLayer austinStreetsLabelLayer = new ShapeFileFeatureLayer(Server.MapPath(@"~\SampleData\USA\Austin\austinstreets.shp"));
                austinStreetsLabelLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.LocalRoad1(“FENAME”);
                austinStreetsLabelLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
                austinStreetsLabelLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle.GridSize = 1500;
                austinStreetsLabelLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle.TextLineSegmentRatio = 0.2;
                austinStreetsLabelLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle.SuppressPartialLabels = true;
                austinStreetsLabelLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle.OverlappingRule = LabelOverlappingRule.NoOverlapping;
                austinStreetsLabelLayer.DrawingMarginPercentage = 1000;
                austinStreetsLabelLayer.ReadWriteMode = ShapeFileReadWriteMode.ReadOnly;
                austinStreetsLabelLayer.DrawingQuality = DrawingQuality.HighSpeed;
 
  
 Everything looks correct in LabelNiceLookingRoads sample after modify code like this. 
  
 I think maybe that’s related with your ColumnBasedTextStyle. 
  
 Could you provide a simple sample for reproduce this issue? 
  
 That should be very helpful for solve this problem. 
  
 Regards, 
  
 Don

Hi Don, here's the ColumnBasedTextStyle class code, it comes from the ServicesEditionSample_LabelingBasedOnColumns_CS_090807, with a few modifcations to suit my needs(Basically i've stripped out the properties that aren't present in the shp. data, it only has an angle value, and the text value for the label of course).



 class ColumnBasedTextStyle : TextStyle
    {   
        //private string sizeColumnName;
        private string angleColumnName;
        //private string colorColumnName;
        //private string fontColumnName;

        public ColumnBasedTextStyle()
            : this(string.Empty, string.Empty)//, string.Empty, string.Empty, string.Empty
        { }

        public ColumnBasedTextStyle(string TextColumnName, string AngleColumnName)//string SizeColumnName, , string ColorColumnName, string FontColumnName
        {
            this.TextColumnName = TextColumnName;
            //this.sizeColumnName = SizeColumnName;
            this.angleColumnName = AngleColumnName;
            //this.colorColumnName = ColorColumnName;
            //this.fontColumnName = FontColumnName;
        }
        /*
        public string SizeColumnName
        {
            get { return sizeColumnName; }
            set { sizeColumnName = value; }
        }
        */
        public string AngleColumnName
        {
            get { return angleColumnName; }
            set { angleColumnName = value; }
        }
        /*
        public string ColorColumnName
        {
            get { return colorColumnName; }
            set { colorColumnName = value; }
        }
        
        public string FontColumnName
        {
            get { return fontColumnName; }
            set { fontColumnName = value; }
        }
        */
        protected override void DrawCore(IEnumerable<Feature> features, GeoCanvas canvas, Collection<SimpleCandidate> labelsInThisLayer, Collection<SimpleCandidate> labelsInAllLayers)
        {
            //Obtener los valores necesarios para el estilo de cada una de las características en la capa.
            foreach (Feature objFeature in features)
            {
                string Text = objFeature.ColumnValues[TextColumnName];
                float Angle = Convert.ToSingle(objFeature.ColumnValues[AngleColumnName]);
                float Size = Convert.ToSingle(8);
                //int Color = Convert.ToInt32(objFeature.ColumnValues[ColorColumnName]);
                string Font = "Arial";
                //Convertir de coordenadas geográficas a coordenadas de pantalla con la ubicación de la característica.
                ScreenPointF textScreenPoint = ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, objFeature, canvas.Width, canvas.Height);
                //Usar el método DrawText del lienzo(canvas) para etiquetar de acuerdo al os valores obtenidos.
                canvas.DrawText(Text, new GeoFont(Font, Size), new GeoSolidBrush(GeoColor.StandardColors.Black), null, new ScreenPointF[] {textScreenPoint}, DrawingLevel.LevelFour,0 ,0, Angle);
            }
            //base.DrawCore(features, canvas, labelsInThisLayer, labelsInAllLayers);
        }

        protected override Collection<string> GetRequiredColumnNamesCore()
        {
            Collection<string> columns = new Collection<string>();
            if (!columns.Contains(TextColumnName))
                columns.Add(TextColumnName);
            //if (!columns.Contains(sizeColumnName))
            //    columns.Add(sizeColumnName);
            if (!columns.Contains(angleColumnName))
                columns.Add(angleColumnName);
            //if (!columns.Contains(colorColumnName))
            //    columns.Add(colorColumnName);
            //if (!columns.Contains(fontColumnName))
            //    columns.Add(fontColumnName);
            return columns;
        }
    }

So is in this class where i must set the  GridSize and TextLineRatio?Because in some post i read that those are related with the number of labels shown in the map control, or did i missundertood that?



 Fernando,



 In Map Suite Custom Style overwhelms Default style, which means if the custom Style is set, Default Style will not take any effect. So in your case you need to use custom styles collection only. Also, if you are overriding the” DrawCore” method, you should consider all the properties like “GridSize”, “OverlappingRule” etc in the overridden method, otherwise they will not take any effect while drawing,  or just call the base.DrawCore() method and everything will work properly. Here we created a sample for you, please have a look.



protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"));
                Map1.MapUnit = GeographyUnit.DecimalDegree;

                ShapeFileFeatureLayer austinStreetsLabelLayer = new ShapeFileFeatureLayer(@"");
                ColumnBasedTextStyle objColumnBasedTextStyle = new ColumnBasedTextStyle("", "ANGLE");
                austinStreetsLabelLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(objColumnBasedTextStyle);
                objColumnBasedTextStyle.SuppressPartialLabels = true;
                objColumnBasedTextStyle.OverlappingRule = LabelOverlappingRule.NoOverlapping;
                objColumnBasedTextStyle.GridSize = 100;
                objColumnBasedTextStyle.TextLineSegmentRatio = 0.2;
                objColumnBasedTextStyle.TextSolidBrush = new GeoSolidBrush(GeoColor.SimpleColors.Black);
                austinStreetsLabelLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
                austinStreetsLabelLayer.DrawingMarginPercentage = 1000;
                austinStreetsLabelLayer.ReadWriteMode = ShapeFileReadWriteMode.ReadOnly;
                austinStreetsLabelLayer.DrawingQuality = DrawingQuality.HighSpeed;

                austinStreetsLabelLayer.Open();
                Map1.CurrentExtent = austinStreetsLabelLayer.GetBoundingBox();
                LayerOverlay overlay = new LayerOverlay();
                overlay.Layers.Add(austinStreetsLabelLayer);
                Map1.CustomOverlays.Add(overlay);
            }
        }


//--------------------

 class ColumnBasedTextStyle : TextStyle
    {
        private string angleColumnName;

        public ColumnBasedTextStyle()
            : this(string.Empty, string.Empty)
        { }

        public ColumnBasedTextStyle(string TextColumnName, string AngleColumnName)//string SizeColumnName, , string ColorColumnName, string FontColumnName
        {
            this.TextColumnName = TextColumnName;
            this.angleColumnName = AngleColumnName;
        }
       
        public string AngleColumnName
        {
            get { return angleColumnName; }
            set { angleColumnName = value; }
        }
      
        protected override void DrawCore(IEnumerable<Feature> features, GeoCanvas canvas, Collection<SimpleCandidate> labelsInThisLayer, Collection<SimpleCandidate> labelsInAllLayers)
        {
            foreach (Feature objFeature in features)
            {
                // this angle can be set according to your columnname value.
                this.RotationAngle = 30;
                base.DrawCore(new Feature[]{objFeature}, canvas, labelsInThisLayer, labelsInAllLayers);
            }
        }

        protected override Collection<string> GetRequiredColumnNamesCore()
        {
            Collection<string> columns = new Collection<string>();
            if (!columns.Contains(TextColumnName))
                columns.Add(TextColumnName);
            if (!columns.Contains(angleColumnName))
                columns.Add(angleColumnName);
            return columns;
        }
    }

Ben