This project has moved and is read-only. For the latest updates, please go here.

Is it possible to render only the labels that are completely within the map image?

Mar 25, 2010 at 3:26 PM

I'm testing SharpMap as WMS and I want to show a label layer. The client of the WMS is Openlayers and the map is therefore tiled (I know I could set OL to Untiled to solve it). This tiling causes labels to be displayed only half, because the're on the edge of the tile.

Mapserver offers the possibility to only display the labels that are completely within the map image and that are not intersecting other labels, which is what I want.

I already found  how to deal with intersecting labels, but I couldn't work out how labels which intersect with the edge of the map image can be excluded from rendering.

Is there a  possibility to render only the labels that are completely within the map image?


I'm using the latest changeset (64449) . Below the relevant code (VB) of my SharpMap WMS:

Dim myMap = New SharpMap.Map(New Size(512, 512))
Dim punt_mdb_label = New SharpMap.Layers.LabelLayer("punt_mdb_label")
        punt_mdb_label.DataSource = New SharpMap.Data.Providers.ShapeFile("D:\Software\SharpMapWMS\App_Data\maps\places_s_RD.shp", True)
        Dim labelstyle As New SharpMap.Styles.LabelStyle()
        labelstyle.CollisionBuffer = New System.Drawing.SizeF(0, 0)
        labelstyle.ForeColor = Color.Green
        labelstyle.BackColor = Brushes.Aqua
        labelstyle.Font = New Font(FontFamily.GenericSansSerif, 11)
        labelstyle.HorizontalAlignment = SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Left
        labelstyle.VerticalAlignment = SharpMap.Styles.LabelStyle.VerticalAlignmentEnum.Bottom
        labelstyle.Offset = New PointF(3, 3)
        labelstyle.Halo = New Pen(Color.Yellow, 2)
        labelstyle.CollisionDetection = True
        punt_mdb_label.PriorityColumn = "population"
        punt_mdb_label.LabelFilter = AddressOf LabelCollisionDetection.ThoroughCollisionDetection
        punt_mdb_label.SRID = 28992
        punt_mdb_label.Enabled = True
        punt_mdb_label.LabelColumn = "name"
        punt_mdb_label.Style = labelstyle
        punt_mdb_label.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias
        punt_mdb_label.SmoothingMode = SmoothingMode.AntiAlias
SharpMap.Web.Wms.WmsServer.ParseQueryString(myMap, description)