Select to view content in your preferred language

How to export a layer displayed consistently with the map display in Silverlight app.

736
1
12-02-2011 05:52 AM
SuiHuang
Frequent Contributor
Hi everybody:

    My Silverlight app is consuming and display a ArcGIS server map service and I want to allow a user to export what he sees in the map to an image.
    The method I tried is to get the map width, map height and map extent, and use them as input to the ArcGIS map service export. 96 was used for the DPI input.
    Following is the code I used
******************************************************
sURL = ServiceLayer.Url + "/export";
int iWidth = (int)_map.ActualWidth;
int iHeight = (int)_map.ActualHeight;
sData = "?f=image&dpi=96&transparent=true";
sData += "&size=" + iWidth.ToString() + "," + iHeight.ToString();
sData += "&bbox=" + _map.Extent.XMin.ToString();
sData += "," + _map.Extent.YMin.ToString();
sData += "," + _map.Extent.XMax.ToString();
sData += "," + _map.Extent.YMax.ToString();
Uri uri = new Uri(sURL + sData);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);              
req.BeginGetResponse(RespCallback, req);

private void RespCallback(IAsyncResult ar)
{
        HttpWebRequest req = (HttpWebRequest)ar.AsyncState;
        HttpWebResponse res = (HttpWebResponse)req.EndGetResponse(ar);
        if (res.StatusCode == HttpStatusCode.OK)
        {
              string sType = res.ContentType;
              int iLen = (int)res.ContentLength;
              Stream stream = res.GetResponseStream();
              _map.Dispatcher.BeginInvoke(() => StreamToBitmap(stream));
        }
}
******************************************************

However, I found that the export result is not always the same as what I see in the Silverlight App map. When my 19" screen have display resolution 1280 X 960, the exported image is always showing an extra layer comparing to the silverlight app, because the export image got a different scale. The maximum resolution of my screen is 1280 X 1024 and the export is ok at that time.

How can I make the map service export always exactly the same image as what I see in Silverlight app? If it is impossible, any idea what is the relationship between size/DPI parameters (to the map service) and the resolution/map size (in silverlight client)? knowing this can help me to decide what to do.

Thank you.
0 Kudos
1 Reply
DominiqueBroux
Esri Frequent Contributor
At first glance your code looks correct, but I probably miss something.

I suggest you use fiddler to look at the requests sent to the server.
Comparing the request sent by the layer and yours might give a clue.
0 Kudos