Map your Data – Part 7
In my last post, I mentioned the MapPoint Web Service SDK as one of the options for rendering maps for usage in applications that do client-side plotting. In case you’re not familiar with it, this is a web service with absolutely no client footprint. Many folks think that a client side install of the shrink wrapped MapPoint desktop product is required to use this SDK – that is not the case.
This SDK is great because it can render maps for download and deliver them to any platform capable of calling a SOAP-based web service. The method below shows how to call the MapPoint Web Service SDK to render a map image, download it, and assign it as the source of a WPF image.
private void RenderMapToImage(LatLong newCenterPoint, double newViewscale, Image image)
{
ViewByHeightWidth[] mapViews = new ViewByHeightWidth[] {
new ViewByHeightWidth { CenterPoint = newCenterPoint, Height = newViewscale, Width = newViewscale } };
MapSpecification mapSpec = new MapSpecification();
mapSpec.DataSourceName = “MapPoint.NA”; // or “MapPoint.EU”,etc.
mapSpec.Views = mapViews;
mapSpec.Options = new MapOptions();
mapSpec.Options.ReturnType = MapReturnType.ReturnImage;
mapSpec.Options.Format = new ImageFormat { Height = Convert.ToInt32(image.Height), Width = Convert.ToInt32(image.Width) };
try {
MapImage[] mapImages = mapRenderService.GetMap(mapSpec);
MemoryStream stream = new MemoryStream(mapImages[0].MimeData.Bits);
BitmapImage bi = new BitmapImage();
bi.BeginInit(); bi.StreamSource = stream; bi.EndInit();
image.Source = bi;
} catch (Exception) { /* do something better than this... */ }
return;
}
In order to call the SDK, you’ll need to get a developer credential. These are available for free up on https://mappoint-css.live.com/mwssignup/, and these do take a little time to go through the provisioning process, so please be patient.
Of course, the next step here would be to layer a transparent canvas over this image and to plot/style the data using the WPF or Silverlight shapes of your choosing. I’ll explore other options in my next post…