ThinkGeo.com    |     Documentation    |     Premium Support

Label on a circle with lot of points

Hi ,

I am stuck with a simple issue and am struggling to get that to work for a few hours now . I am just trying to add a label to a circle that I drew on my map , the circle is drawn based on a centre point and its links to other points. Everything is working fine but adding a label on the circle doesn’t work using the same code…

layer is InMemoryFeatureLayer – I have other methods that return the layer and other variables like PointID , key etc… not declared below . . . this code is working perfectly

           layer.Columns.Add(new FeatureSourceColumn("Range"));
    	   PointShape DPoint = new PointShape(X,Y);
    
            double maxLenth = 0.0;
            double minLenth = 0.0;
            int count = 0;
    
            ValueStyle valueStyle = new ValueStyle();
            valueStyle.ColumnName = "Range";
            Random r = new Random();
    
            Feature centerPoint = new Feature(Latitude,Longitude, PointId);
            centerPoint.Tag = PointId;
            centerPoint.ColumnValues.Add("Range", key + "point");
            valueStyle.ValueItems.Add(new ValueItem(key + "point", PointStyles.CreateSimpleStarStyle(GeoColor.SimpleColors.Black, 10)));
            layer.InternalFeatures.Add(key + (count++).ToString(), centerPoint);
            
            for (int i = 0; i < Connections.Count(); i++)
            {
                var item = Connections[i];
    
                PointShape RPoint = new PointShape(item.Latitude,item.Longitude);
    
                Feature point = new Feature(Convert.ToDouble(item.Latitude), Convert.ToDouble(item.Longitude), item.CustomerId);
                point.ColumnValues.Add("Range", key + "point" + i.ToString());
                point.Tag =PointId;
                valueStyle.ValueItems.Add(new ValueItem(key + "point" + i.ToString(), PointStyles.CreateSimpleTriangleStyle(GeoColor.SimpleColors.Black, 10)));
                layer.InternalFeatures.Add(key + (count++).ToString(), point);
                
                LineShape lshape = new LineShape();
                lshape.Vertices.Add(new Vertex(DPoint));
                lshape.Vertices.Add(new Vertex(RPoint));
    
                double rlenth = DPoint.GetDistanceTo(RPoint, GeographyUnit.Feet, DistanceUnit.Mile);
                if (rlenth == 0)
                    continue;
                if (maxLenth < rlenth)
                    maxLenth = rlenth;
                if (minLenth != 0 && minLenth > rlenth)
                    minLenth = rlenth;
    
                
    
                GeoColor rdbrandomColor = getColor(item);
                Feature lineShape = new Feature(lshape);
                lineShape.ColumnValues.Add("Range", key + i.ToString());
                
              
                    valueStyle.ValueItems.Add(new ValueItem(key + i.ToString(), LineStyles.CreateSimpleLineStyle(rdbrandomColor, 2, true)));
                
                lineShape.Tag = PointId;
                layer.InternalFeatures.Add(key + (count++).ToString(), lineShape);                
            }
            EllipseShape centerShape = new EllipseShape(DPoint, maxLenth, GeographyUnit.Feet, DistanceUnit.Mile);
            wagonWheelInformation.areaCovered = centerShape.GetArea(GeographyUnit.Feet,AreaUnit.Acres);
            wagonWheelInformation.maxdistance = maxLenth;
            wagonWheelInformation.mindistance = minLenth;
            var centerCircle = new Feature(centerShape);
            centerCircle.ColumnValues.Add("Range", key + "Circle");
            valueStyle.ValueItems.Add(new ValueItem(key + "Circle", new AreaStyle(new GeoPen(GeoColor.SimpleColors.DarkBlue), new GeoSolidBrush(new GeoColor(50, GeoColor.GeographicColors.Ice)))));
            centerCircle.Tag = wagon.Center.CustomerId;
            layer.InternalFeatures.Add(key + (count++).ToString(), centerCircle); 
layer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(valueStyle);

//On top of the Circle(attached to it outside) I want a label with a custom-style , text in a box…

I do not want to create another layer ; I tried using one of the solutions provided in the discussions but somehow it didnt work ; it was on creating a label on the circle’s perimeter.

Need a simple solution that can be added to this code above.

Thanks in advance.

Kreez .

Hi Kreez,

I don’t quite understand that “but adding a label on the circle doesn’t work using the same code…” if there is a code as well as below?

valueStyle.ValueItems.Add(new ValueItem("Value", new TextStyle("TextColumnName", new GeoFont("Arial", 10), new GeoSolidBrush(GeoColors.Black))));

Please modify the value of ‘Value’ and ‘TextColumnName’ according to actual situation and add it to your codes, and try it again.

For the label with a custom-style, I want to know if the following image is what you want to achieve.

And I think you can create a custom class that inherits from TextStyle, and override the ‘DrowCore’.
You can invoke the canvas’s method ‘DrawArea’ to draw the box.
How to create a custom TextStyle please refer to
http://wiki.thinkgeo.com/wiki/_media/file/ServicesEditionSample_ScalingTextStyle_CS_090918.zip

If something I misunderstood here. please provide more information.

Hope it’s helpful,

Thanks,
Emil

Hi Emil,

Thanks for the solution . But this is exactly what I had done (Add a new value item with text style) which did not work for me . Not sure what I have been doing wrong . I am going to try again and see .
The code doesn’t throw any error but the text wont appear on the map/circle.

And for the image …you have hit the bulls eye. I need to create something similar.

Sorry if my post was any confusing.

Thanks
Kreez

Hi Kreez,

As you said, the code doesn’t throw any error but the text won’t appear, I think there are two possibilities here:

  1. The value of ValueItem is incorrect, there is no feature match to the text style. But I think the odds of this case are slim.
  2. The label has been filtered. There are some properties in TextStyle, they are combined with the really data will filter some text,
    For properties: DuplicateRule, SuppressPartialLabels, PointPlacement, ect;
    For really data: the width of the label and the target feature, ect.

I don’t know the value of ‘Latitude’, ‘Longitude’, ‘Connections’, could you please upload a runnable project with data that duplicates the problem on a consistent basis.
For security and privacy, you can upload them to forumsupport@thinkgeo.com, (Sending Data to Support)

For the ‘custom’ TextStyle, I’m sorry for my mistake, I viewed our source code, found we have been able to achieve that, please refer to the following code snippet:

layer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = new PointStyle(PointSymbolType.Circle, new GeoSolidBrush(GeoColors.Black), 50);
layer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = new TextStyle("Range", new GeoFont("Arail", 9, DrawingFontStyles.Bold), new GeoSolidBrush(GeoColor.SimpleColors.Black));
layer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle.HaloPen = new GeoPen(GeoColor.StandardColors.White, 2);
layer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle.Mask = new AreaStyle(new GeoPen(GeoColors.Blue, 2), new GeoSolidBrush(new GeoColor(0,0,0,0)), PenBrushDrawingOrder.PenFirst);
layer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle.XOffsetInPixel = 0;
layer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle.YOffsetInPixel = 25;// radius :50/2=25
layer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle.PointPlacement = PointPlacement.UpperCenter;
layer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle.OverlappingRule = LabelOverlappingRule.NoOverlapping;
// Set DrawingMarginPercentage to a proper value to avoid some labels are cut-off
layer.DrawingMarginPercentage = 100;

For Development, the codes work in version 9.0.448.0(Development) or above,
For Production, any version is OK.

Thanks,
Emil

Hey Emil ,

Sorry for the delayed response ; unfortunately I cannot post any code because of some privacy concerns . To brief you about the parameters and the logic -

Lets take a hypothetical situation where you want to plot friends network on facebook on a map using their geo locations (assume that the geolocation (latitude and longitude) of all users is available).My logic puts a marker for the logged-in person at the centre and plots all other friends around it and joins them using a line.Then a circle is drawn with the distance between the centre person’s point and the farthest friend as the radius . The connections collection holds the information of all the lat/long coordinates of the friends.All this is done but if I want to add the name of the centre point as a label to the circle in the format we have discussed above ; its not working.

BTW this code was originally built a few years back on version 7.0 . I cant upgrade the version now.

Thanks,
Kreez

Hi Kreez,

It looks Emil had posted the code in last reply, which should works for what you want.

I think this label don’t shows should because some property had been set correct.

We don’t have a test sample, so we cannot help you debug the code, please just try to reset the properties of DefaultTextStyle to make the label shows, you can ask us for detail about any property you want know more detail.

Regards,

Don

Hi Don ,

Thanks for the reply but if you look at my code I have added the value style as a custom-style ;you can’t add both a custom-style and a default-style, right ! also I tried adding some of these to a text-style added as a value-item but it dint work.

Thanks,
Kreez.

Hi Kreez,

Your custom style is a valuestyle, you can go on add a textstyle after that.

Emil’s code shows how to set the properties of textstyle, you don’t need set it to your default style.

Regards,

Don