Display only outside border of active region.
Posted: Fri Feb 02, 2018 5:49 am
We have one use case of displaying the Active Region on Map. We provide geometry data to Map using SharpMap.Styles.VectorStyle.EnableOutline = true for display geometry for an Active Region.
We have used the ITiledProvider to convert binary geometry data into the Image. The code is as follows for ITiledProvider:
We have used the ITiledProvider to convert binary geometry data in the image of zip code, the code is as follows.
Issue :
Currently, we have border to each geometry shape present on the Active Region as shown below: But we want to display only the outside border of whole Active Region, as shown below: So is there any solution for the issue?
We have used the ITiledProvider to convert binary geometry data into the Image. The code is as follows for ITiledProvider:
We have used the ITiledProvider to convert binary geometry data in the image of zip code, the code is as follows.
Code: Select all
public Stream GetImageStream(int x, int y, int zoom)
{
try
{
// the map contains only one layer
var districts = new VectorLayer("Districts")
{
// set the sharpmap provider for shape files as data source
DataSource = <Sharp map Data source>,
// use a dynamic style for thematic mapping
// the lambda also takes the map instance into account (to scale the border width)
Theme = new SharpMap.Rendering.Thematics.CustomTheme(GetCountryStyle)
};
// create a transparent sharpmap map with a size of 256x256
using (var sharpMap = new SharpMap.Map(new Size(256, 256)) { BackColor = Color.Transparent })
{
// add the layer to the map
sharpMap.Layers.Add(districts);
// calculate the bbox for the tile key and zoom the map
sharpMap.ZoomToBox(TileToMercatorAtZoom(x, y, zoom));
// render the map image
using (var image = sharpMap.GetMap())
{
// stream the image to the client
var memoryStream = new MemoryStream();
image.Save(memoryStream, ImageFormat.Png);
memoryStream.Seek(0, SeekOrigin.Begin);
return memoryStream;
}
}
}
catch (Exception ex)
{
throw ex;
}
}
private SharpMap.Styles.VectorStyle GetCountryStyle(SharpMap.Data.FeatureDataRow featureDataRow)
{
// set a linear gradient brush for each country according to the bounding pixel rectangle
SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle();
// color code for active region
Color color = System.Drawing.ColorTranslator.FromHtml("#009EE3");
style.Fill = new SolidBrush(color);
// set the border width depending on the map scale
Pen pen = new Pen(Brushes.Black);
pen.LineJoin = LineJoin.Round;
style.Outline = pen;
// this flag is used to set the border to each zip code shape
style.EnableOutline = true;
return style;
} // GetCountryStyle
Currently, we have border to each geometry shape present on the Active Region as shown below: But we want to display only the outside border of whole Active Region, as shown below: So is there any solution for the issue?