Hi,
I’m trying to download a image from a custom map server which returns me a PNG of administrative borders. I made a class derived from GoogleMapsOverlay where i simply set the url to be used. The problem is that the returned image is “shifted”.
In instance, when I check an adress with a browser I get a correct image (see todo.png). However when I use the exact same url with my class I get a strange result (see done.png). It seems that my final result is shifted to the right.
Any idea why?
Here is the code below is this can help.
namespace
ImageGeneration.Business
{
using
System.IO;
using
System.Net;
using
ThinkGeo.MapSuite.Core;
using
ThinkGeo.MapSuite.WpfDesktopEdition;
using
System.Globalization;
using
System.Text;
using
ImageGeneration.Properties;
public
class
AdminUnitOverlay : GoogleMapsOverlay
{
public
AdminUnitOverlay(
double
? opacity,
string
layerName, RectangleShape rec,
double
width,
double
height)
{
Opacity = opacity;
LayerName = layerName;
TileType = TileType.SingleTile;
Url = GetImgUri(Settings.Default.DatastoreUrl, rec, width, height);
this
.SendingWebRequest += CustomGoogleMapsOverlay_SendingWebRequest;
this
.SentWebRequest += CustomGoogleMapsOverlay_SentWebRequest;
}
public
double
? Opacity {
get
;
private
set
; }
public
string
LayerName {
get
;
private
set
; }
public
string
Url {
get
;
private
set
; }
void
CustomGoogleMapsOverlay_SentWebRequest(
object
sender, SentWebRequestEventArgs e)
{
//App.Calls++;
//File.AppendAllText(@“c:\calls.txt”,“Calls: “+App.Calls.ToString()+”\r\n”);
}
void
CustomGoogleMapsOverlay_SendingWebRequest(
object
sender, SendingWebRequestEventArgs e)
{
e.WebRequest = WebRequest.Create(Url);
}
private
string
GetImgUri(
string
serverUrl, RectangleShape tileExtent,
double
tileWidth,
double
tileHeight)
{
var uriBuilder =
new
StringBuilder();
uriBuilder.Append(
string
.Format(
“{0}?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&EXCEPTIONS=application/vnd.ogc.se_inimage&SRS={1}&FORMAT={2}&BBOX={3},{4},{5},{6}&WIDTH={7}&HEIGHT={8}”
,
serverUrl,
“EPSG:900913”
,
“png32”
,
tileExtent.LowerLeftPoint.X.ToString(CultureInfo.InvariantCulture),
tileExtent.LowerLeftPoint.Y.ToString(CultureInfo.InvariantCulture),
tileExtent.UpperRightPoint.X.ToString(CultureInfo.InvariantCulture),
tileExtent.UpperRightPoint.Y.ToString(CultureInfo.InvariantCulture),
tileWidth,
tileHeight));
uriBuilder.Append(
string
.Concat(
"&layers="
, LayerName));
return
uriBuilder.ToString();
}
}
}