Hi,
I want to know two things
1) How OverlappingRule decide which feature to hide from two overlapping features?
2) Can we change or over right it?
Thanks & Regards,
Goral
OverlappingRule
Goral,
During we draw an overlay, we have a global variable to store the label’s information including the position. When drawing each layer in this overlay, the current feature label will compare with the global labels to decide whether need to draw on the map, if yes, then add the label into the global labels.
I think we can change the Overlapping rule by overwriting the CheckOverlappingCore method by defining a custom text style.
CheckOverlappingCore(LabelingCandidate labelingCandidate, GeoCanvas canvas, Collection<SimpleCandidate> labelsInThisLayer, Collection<SimpleCandidate> labelsInAllLayers)
In this method, the labelsInAllLayers means the global labels I mentioned above, the labelingCandidate is the current feature label, I also attached our current overlapping logic codes and hope it helps for overwriting:
protected virtual bool CheckOverlappingCore(LabelingCandidate labelingCandidate, GeoCanvas canvas, Collection<
SimpleCandidate
> labelsInThisLayer, Collection<
SimpleCandidate
> labelsInAllLayers)
{
Validators.CheckParameterIsNotNull(labelingCandidate, “labelingCandidate”);
return IsLabelOverlapping(labelsInAllLayers, labelingCandidate);
}
private static bool IsLabelOverlapping(Collection<
SimpleCandidate
> labelCandidates, LabelingCandidate currentLabelCandidate)
{
if (labelCandidates == null)
{
return false;
}
bool isOverlapping = false;
foreach (SimpleCandidate labelCandidate in labelCandidates)
{
//TODO: The following polygon is actually two Rectanlge, we can optimize without using the JTS one.
if (!IsDisjointed(currentLabelCandidate.ScreenArea, labelCandidate.SimplePolygonInScreenCoordinate))
{
isOverlapping = true;
break;
}
}
return isOverlapping;
}
Thanks,
Troy
Hi,
Thanks for reply. I have gone through the method written for overlapping rule. But I am not able to understand it.
Example. I have two features. One is at Lat lon- (23 73) and Second one is at (23.5 72). Now if I am zooming out, they will come nearby and one of them going to hide. How algorithm is deciding which feature to go off. In your post given method no specific condition I found. Please explain.
Thanks,
Goral
Hi Goral,
Just like the sample you mentioned, the two features with same priority, so when we check which one should be set hidden, we will do a loop for the label collection first, and I think the first label won’t be set hidden.
So you can try to override the GetLabelingCandidateCore for your textStyle, and try to adjust the order in the Collection<LabelingCandidate>.
Wish that’s helpful.
Regards,
Don
Hi,
Thanks for reply. I understood how its working. So my next question is can I re-order features after adding it to inmemoryfeaturelayer? Please suggest ways to reorder it.
Thanks,
Goral
Hi Goral,
Have you tried my suggestion for re-order it in GetLabelingCandidateCore?
Please let me know whether that works for you.
Regards,
Don
Hi,
No I am not getting that also. That’s why I asked if reordering is simple I will choose that.
Thanks,
Goral
Hi Goral,
Because we hadn’t met your problem before, so I just found this function should be helpful for that.
Regards,
Don
Hi,
Can you please suggest how to overwrite
GetLabelingCandidateCore method to reorder features in it?
Thanks,
Goral
Hi Goral,
I am sorry I think I made a mistake when I copy the function name. It should be DrawCorebut not GetLabelingCandidateCore.
Please see my attached code, I tested it and see it works well for your requirement.
protected override void DrawCore(System.Collections.Generic.IEnumerable<Feature> features, GeoCanvas canvas, System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInThisLayer, System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInAllLayers)
{
System.Collections.ObjectModel.Collection<Feature> fs = new System.Collections.ObjectModel.Collection<Feature>();
foreach (Feature f in features) // Reorder feature
{
fs.Insert(0, f);
}
//base.DrawCore(features, canvas, labelsInThisLayer, labelsInAllLayers);
base.DrawCore(fs, canvas, labelsInThisLayer, labelsInAllLayers);
}
Regards,
Don
Hi Goral,
I am sorry I think I made a mistake when I copy the function name. It should be DrawCorebut not GetLabelingCandidateCore.
Please see my attached code, I tested it and see it works well for your requirement.
public class customTextStyle : TextStyle
{
public customTextStyle(string textColumnName, GeoFont textFont, GeoSolidBrush textSolidBrush)
: base(textColumnName, textFont, textSolidBrush)
{
}
protected override void DrawCore(System.Collections.Generic.IEnumerable<Feature> features, GeoCanvas canvas, System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInThisLayer, System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInAllLayers)
{
System.Collections.ObjectModel.Collection<Feature> fs = new System.Collections.ObjectModel.Collection<Feature>();
foreach (Feature f in features) // Reorder feature
{
fs.Insert(0, f);
}
//base.DrawCore(features, canvas, labelsInThisLayer, labelsInAllLayers);
base.DrawCore(fs, canvas, labelsInThisLayer, labelsInAllLayers);
}
}
Regards,
Don
Hi,
Thanks for reply. Its working for me. Another way I found to achieve it is I have reordered rows in data table through which I am plotting features. Please tell if any one of these method has performance issue if large number of features are there?
Thanks,
Goral
Hi Goral,
Do you meant you will reorder the features in your data source?
I don’t think there are performance issue here, but if you want to avoid it, please directly adjust the order in original collection instead of create new one.
Regards,
Don
Hi,
Thanks for reply. Ya I am changing order of features in data source.
Thanks,
Goral
Hi Goral,
I wish that’s can solved your issue. Directly reorder in data source should get better performance.
Regards,
Don
Hi,
Thanks for reply.
Goral
Goral,
Please let us know if any other questions.
Troy