Hi,
I am trying to display labels outside Polygon, But not able to sort it out.
Some lables fall inside the polygon. Please guide me how to achive this.
For reference Here I am attaching Hand drawn image.
I am using Web Developer 7.0 Edition.
Lable Outside Polygon
Hi Djay,
Seems like the attached image is missed in the post, would you upload it again?
Before pasting the reply here, I have a question here? How many labels you would like to display outside of the polygon, just some specific features or all of the features? If just some specific features, I guess you can try the property of TextStyle: LabelPositions. If all features, I guess you need to create a customized TextStyle and overwrite the DrawCore method, there you can modify the geometry of the Feature whose center point (center point of biggest feature) will be used for showing labels.
Thanks,
Johnny
Hello Johnny,
I have added the image.
Please go through it.
Waiting for you reply.
Thanks N Regards
Djay
Hi Djay,
You can write your own text style, calculate the new label position and draw it follow your requirement.
As below is a simple sample, which only adjust the vertex order and haven’t implemented the algorithm for calculate rotate angle, wish that’s helpful.
Regards,
Don
12534.zip (1.69 KB)
Thanks for the reply.
How to indentify that Label is inside polygon or outside?
Accordingly we will apply the offset & Rotation angle.
Hi Djay,
In my sample, the vertex order is anticlockwise so I just did a simple logic for it to make sure it’s outside.
If you want to calculate that, you can don’t use offset, but directly calculate the PointF of label based on polygon center point and current line shape, that’s a little complex I think.
Regards,
Don
Hello,
Here I am attaching image. which will explain what we want.
Please guide us to get it.
Thanks in adavnce…
Hi djay,
Here is an option for you, please check it.
Scenario: given there are 2 polygons (No.2 and No.3), and take No.2 as the one we are considering, the No.3 is the adjacent polygon of No.2. In that case, there should be 2 labels/numbers shown on the polygon No.2, just shown as below:
Solution:
- Scale up the No.2
with a bigger ratio, possibly bigger than 5. - Get the intersection
M1 between NO.3 and scaled-up polygon in #1. - Scale up the No.2
with a small ratio, possible smaller than the value given in #1. - Get the intersection
M2 between No.3 and the scaled-up polygon in #3. - Loop the vertices in
M1 and M2 intersection to generated the vertices which are not shared by M1 and
M2. - Create a Line shape
with the vertices generated from #5. - Get the center point
of the created Line shape generated in #6. - Show labels with Map
Suite styles.
Demo Code:
Map1.MapUnit =
GeographyUnit.DecimalDegree;
Map1.CurrentExtent = new
RectangleShape(-155.733, 95.60, 104.42, -81.9);
InMemoryFeatureLayer layer = new
InMemoryFeatureLayer();
LayerOverlay overlay = new
LayerOverlay();
MultipolygonShape p3 = new
MultipolygonShape(“MULTIPOLYGON(((-110.501994832584
42.924075924481,-117.457883942506 47.8548327618941,-111.646634812697
54.7226726425764,-104.514647244296 48.3831281373312,-110.501994832584
42.924075924481)))”);
MultipolygonShape p2 = new
MultipolygonShape(“MULTIPOLYGON(((-117.435871632689
47.9208696814366,-121.133939259749 53.203823434379,-118.668560841709
58.5308018019293,-111.668647119061 54.7006603310461,-117.435871632689
47.8328204522209,-117.435871632689 47.9208696814366)))”);
MultipolygonShape px = p3.CloneDeep()
as MultipolygonShape;
px.ScaleUp(5.0);
MultipolygonShape px1 =
p3.CloneDeep() as MultipolygonShape;
px1.ScaleUp(2.5);
MultipolygonShape pxP2 =
px.GetIntersection(p2);
MultipolygonShape px1P2 =
px1.GetIntersection(p2);
Collection<vertex>
vertices = new Collection<vertex>();</vertex></vertex>
foreach (Vertex vertex in
pxP2.Polygons[0].OuterRing.Vertices)
{
bool
isContains = false;
foreach (var
item in px1P2.Polygons[0].OuterRing.Vertices)
{
if (item.X == vertex.X && item.Y == vertex.Y)
{
isContains = true;
break;
}
}
if
(!isContains)
{
vertices.Add(vertex);
}
}
vertices.RemoveAt(vertices.Count
- 1);
LineShape line = new
LineShape(vertices);
PointShape point2 =
line.GetCenterPoint();
Dictionary<string,>
dictionary = new Dictionary<string,>();</string,></string,>
dictionary.Add(“id”,
“2”);
Feature pointFeature = new
Feature(point2, dictionary);
layer.Open();
layer.Columns.Add(new
FeatureSourceColumn(“id”));
Feature f3 = new Feature(p3);
layer.InternalFeatures.Add(f3);
layer.InternalFeatures.Add(pointFeature);
layer.InternalFeatures.Add(new
Feature(line));
layer.InternalFeatures.Add(new
Feature(p3));
layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle
= AreaStyles.Country1;
layer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle
= new TextStyle(“id”, new GeoFont(“Arial”, 10.0f), new
GeoSolidBrush(GeoColor.SimpleColors.Black));
layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel
= ApplyUntilZoomLevel.Level20;
overlay.Layers.Add(layer);
Map1.CurrentExtent = p3.GetBoundingBox();
Map1.Overlays.Add(overlay);
Map1.Refresh();
Thanks,
Casper
Hello Casper,
Thanks for your reply and solution. We have implemented it.
There are few problems…
1. Its working for one side of the polygon.
2. Second scale is not effective in any case.
3. Text are not aligned to Line.
4. We tried lot many combination of scale and its different for diffrent size of the polygon.
We are still not achiving what we want.
We have develope one solution which displays adjacent labels on line. But we are not able to move those lables outside of the polygon.
Is there any solution to problem?
Thanks in adavnce
Djay
Hi djay,
Please check the attached sample and have a try. Maybe there are some places which are not good enough, but I think it’s easy to do the changes based on code we show in the demo. Anyway, please have a try.
Thanks,
Johnny
post12534.zip (10.5 KB)