ArcGIS Silverlight API outputs map to save to image

Source: Internet
Author: User

You can use the ArcGIS Silverlight API to output a map to an image by sending an HTTP request to the server or directly using the writeablebitmap class on the client.

The HTTP Request Method sent to the server can output maps within the specified rectangle range, set the control reference, and support PNG, JPG, BMP, and other image formats, however, this method can only be used for a single map service at a time. In other words, when we add multiple map services, we cannot output all the map services in the output area together; this method does not support graphiclayer layer output.

Select map output area

Images returned by the server

 

Private
Void exportimage (ESRI. ArcGIS. Client. Geometry. Geometry extent)

{

Try

{

Envelope SENV = extent. extent;

Stringbuilder Surl =
New stringbuilder ();

Surl. append ("http: // Lingy/ArcGIS/rest/services/dxmap/mapserver ");

Surl. append ("/export? ");

Surl. append ("F = JSON ");

Surl. append (string. format ("& bBox = {0}, {1}, {2}, {3}", SENV. xmin, SENV. ymin, SENV. xmax, SENV. ymax ));

Surl. append ("& format = ");

Surl. append ("PNG ");

Httpwebrequest request = (httpwebrequest) httpwebrequest. Create (sburl. tostring ());

Request. begingetresponse (New
Asynccallback (exportcall), request );

}

Catch (exception ex)

{

MessageBox. Show ("image export failed:" + ex. tostring ());

}

}

Private
Void exportcall (iasyncresult asynchronousresult)

{

This. Dispatcher. begininvoke (delegate ()

{

Try

{

Httpwebrequest request = (httpwebrequest) asynchronousresult. asyncstate;

Httpwebresponse response = (httpwebresponse) request. endgetresponse (asynchronousresult );

Stream stream = response. getresponsestream ();

Streamreader reader =
New streamreader (Stream );

String result = reader. readtoend ();

String href = result. Split (New
Char [] {'"'}) [3];

Linkimageresult. navigateuri =
New uri (href,
Urikind. Absolute );

}

Catch (exception ex)

{

MessageBox. Show ("image export failed:" + ex. tostring ());

}

});

}

 

Writeablebitmap can be directly saved to the map control on the client. The saved image format must be encoded by yourself.

 

Use writeablebitmap source code:

Private
Void button#click (Object sender,
Routedeventargs E)

{

Try

{

Cmapexporttoimage imageexporter =
New cmapexporttoimage ();

Bool bresult = imageexporter. exportpng (mainmap
As uielement );

String strresult = bresult?
"Successful! ":
"Failed! ";

MessageBox. Show ("image export" + strresult );

}

Catch (exception per)

{

String MSG = per. message;

}

}

 

For more information about cmapexporttoimage and cpngencoder. CS files, see the attachment below.

Cmapexporttoimage.txt (2.67 KB)

Cpngencoder.txt (8.36 KB)

Go to: http://www.gisall.com/html/72/124272-5867.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.