how to set a label priority ?

Topics: SharpMap Project, SharpMap v0.9 / v1.x
Apr 29, 2009 at 10:29 AM
hi

i'm using sharpmap 0.9 for a few weeks, and find it great.
the basics are easy to understand and to use

but there's something i really can't understand : label layer, labels, collision detection, and priority

here is my problem :
i have a map containing a VectorLayer and a LabelLayer using the same data source
first i wanted to display labels associated to the features of the vectorlayer without displaying overlapping labels.
-> i set the collision detection to ThoroughCollisionDetection and enabled the CollisionDetection of the LabelLayer, and was happy to get a readable map at every zoom level

but i realised displayed labels seems to be chosen randomly, and i wanted the labels associated to big features to be chosen over those associated to small features in case of collision.
i started lurking the documentation, then the source code, and didn't find how to implement this behaviour.
here is what i understand : when a label layer is rendered, it first performs an intersection query with the current view bounding box, then creates a list of SharpMap.Rendering.Label according to the layer style and filter algorithm, and finally renders each label.
a SharpMap.Rendering.Label has a "Priority" property, which is used to choose which label to display when a collision occured.
perfect, but the problem is i can't find a way to set this property for each label of the layer. the value of the label priority is the value of the label layer priority. i don't understand how to use this : what's the point in setting the same priority value to all of the layer's labels ?
i looked for a delegate to set the priority value depending of a featuredatarow, but it seems there is no such property....

what am i doing wrong ?
Coordinator
Apr 29, 2009 at 12:20 PM
Hi barnapigeon, I don't think you are doing anything wrong - I think it is a bug.. should be easy to fix though.. remove the property LabelLayer.Priority and  create property  LabelStyle.Priority. Add priority as an argument to the LabelLayer.CreateLabel method and pass in the value obtained from the style object. Then you can use a theme to adjust the priority hth jd
Coordinator
Apr 29, 2009 at 12:22 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Apr 30, 2009 at 9:31 AM
Hi barnapigeon, FObermaier submitted a patch to add this functionality - different to my idea above though. His patch added a delegate to the LabelLayer to calculate the proirity or use a column in the attribute table to supply priority. The patch has been applied and is now in the trunk. hth jd
May 4, 2009 at 12:31 PM
thanks ! (you were very fast)
this should solve all my problems