First, I'm new to SharpMap.
I'm adding in labels for a vector layer, but for some reason the labels are not showing up.
My PostGIS data is in Geographic NAD 83 and the UI is OpenLayers so am converting it to Google's CRS.
This is what my tile request looks like:
http://lh/customwms/wms.ashx?LAYERS=uscounties&SERVICE=WMS&VERSION=1.3.0&FORMAT=image%2Fpng&TRANSPARENT=TRUE&FILTER=state%20%3D%20'FL'&EXCEPTIONS=INIMAGE&REQUEST=GetMap&STYLES=&MAP_TYPE=PGS&CRS=EPSG%3A900913&BBOX=-9179495,2913453,-8940360,3152589&WIDTH=256&HEIGHT=256
This is what I'm doing to get my Map object.
public static Map CreateMap(List layerRequests)
{
var map = new Map(new Size(1, 1));
foreach (var layerRequest in layerRequests)
{
var vectorLayer = CreateVectorLayer(layerRequest);
var labelLayer = CreateLabelLayer(vectorLayer, layerRequest);
map.Layers.Add(vectorLayer);
map.Layers.Add(labelLayer);
}
return map;
}
private static LabelLayer CreateLabelLayer(VectorLayer vectorLayer, VectorLayerRequest layerRequest)
{
return new LabelLayer("Labels:" + vectorLayer.LayerName)
{
DataSource = vectorLayer.DataSource,
Enabled = true,
LabelColumn = GetLabelColumnName(layerRequest),
SRID = vectorLayer.SRID,
TargetSRID = vectorLayer.TargetSRID,
CoordinateTransformation = vectorLayer.CoordinateTransformation,
Style = new LabelStyle
{
ForeColor = Color.Black,
Font = new Font(FontFamily.GenericSerif, 11),
HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Center,
VerticalAlignment = LabelStyle.VerticalAlignmentEnum.Middle,
Offset = new PointF(3, 3),
Halo = new Pen(Color.Yellow, 2)
},
TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias,
SmoothingMode = SmoothingMode.AntiAlias
};
}
private static string GetLabelColumnName(VectorLayerRequest layerRequest)
{
switch (layerRequest.Table.ToLower())
{
case "uscounties":
case "states":
return "name";
default:
return "district";
}
}
private static VectorLayer CreateVectorLayer(VectorLayerRequest layerRequest)
{
//var cacheKey = String.Format("{0}_{1}_{2}:{3}",
// layerRequest.Schema,
// layerRequest.Table,
// layerRequest.SRID,
// layerRequest.Filter == null ? "" : layerRequest.Filter.Replace(" ", ""));
//return VectorLayersCache.GetOrPut(cacheKey, () =>
//{
int? originalSrid = null;
if (layerRequest.SRID != GeographicNad1983Srid)
{
originalSrid = layerRequest.SRID;
layerRequest.SRID = GeographicNad1983Srid;
}
var dataSource = new PostGIS(ConnectionString, layerRequest.Table, GeometryColumnName, SpatialTableIdColumnName)
{
Schema = layerRequest.Schema,
SRID = layerRequest.SRID,
DefinitionQuery = layerRequest.Filter
};
return new VectorLayer(layerRequest.Table, dataSource)
{
SRID = GeographicNad1983Srid,
TargetSRID = originalSrid.HasValue ? originalSrid.Value : layerRequest.SRID,
CoordinateTransformation = ProjHelper.LatLonToGoogle(),
Style = layerRequest.Style,
SmoothingMode = SmoothingMode.AntiAlias,
LayerName = layerRequest.Table,
Enabled = true,
IsQueryEnabled = true
};
//});
}
When the do the above directly through an MVC controller and zoom to map extents, I get the labels layer to show up. However since the calls from my client (using OpenLayers) are discrete, I suspect that the bales are not being shown.
So how do we show labels when using SharpMap WMS?