Hi Gautier,
At first glance, we have the same idea that we should take advantage of “SentWebRequest” event, and change the HttpWebResponse . But seems that it runs into complex, we just can get the stream from HttpWebResponse, but unable to do the changes. So please try the code below, and pay more attention to the “Todo” comments:
public partial class LoadAWmsOverlay : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.StandardColors.Transparent);
Map1.CurrentExtent = new RectangleShape(-131.22, 55.05, -54.03, 16.91);
Map1.MapUnit = GeographyUnit.DecimalDegree;
CustomWmsRasterSource imageSource = new CustomWmsRasterSource(new Uri("wmssamples.thinkgeo.com/WmsServer.aspx"));
CustomWmsRasterLayer wmsRasterLayer = new CustomWmsRasterLayer(imageSource);
wmsRasterLayer.UpperThreshold = double.MaxValue;
wmsRasterLayer.LowerThreshold = 0;
wmsRasterLayer.Open();
foreach (string layerName in wmsRasterLayer.GetServerLayerNames())
{
wmsRasterLayer.ActiveLayerNames.Add(layerName);
}
wmsRasterLayer.Close();
LayerOverlay wms = new LayerOverlay();
wms.Layers.Add(wmsRasterLayer);
Map1.CustomOverlays.Add(wms);
}
}
}
public class CustomWmsRasterLayer : WmsRasterLayer
{
public CustomWmsRasterLayer(WmsRasterSource rasterSource)
{
this.ImageSource = rasterSource;
}
}
public class CustomWmsRasterSource : WmsRasterSource
{
public CustomWmsRasterSource(Uri url)
: base(url)
{
}
protected override GeoImage GetImageCore(RectangleShape worldExtent, int canvasWidth, int canvasHeight)
{
GeoImage image = base.GetImageCore(worldExtent, canvasWidth, canvasHeight);
Stream stream = image.GetImageStream(new GdiPlusGeoCanvas());
// todo: please modify the stream of the bitmap here, maybe you need loop the pixel in it and make sure it's transparent.
// .........your code......
return new GeoImage(stream);
}
}
Regards!
Johnny