/// <summary> /// Return a image representing a map showing the start and ending points and an annotated line for /// the route between those points /// </summary> /// <param name="route">a Route</param> /// <param name="imageWidth">width of image used to display the map</param> /// <param name="imageHeight">height of the image used to display the map</param> /// <returns>Image</returns> public System.Drawing.Image GetRouteMap(Route route, int imageWidth, int imageHeight) { MapImage[] mapImage; System.Drawing.Bitmap theImage = null; try { if (route == null) { throw new System.ArgumentNullException("Route cannot be null"); } //if (location == null) //{ // throw new System.ArgumentNullException("Location cannot be null"); //} if (imageWidth <= 0) { throw new System.ArgumentNullException("Image width should be > then 0"); } if (imageHeight <= 0) { throw new System.ArgumentNullException("Image Height should be > then 0"); } // now get a map MapSpecification mapSpec = new MapSpecification(); ViewByHeightWidth[] myViews = new ViewByHeightWidth[1]; myViews[0] = route.Itinerary.View.ByHeightWidth; mapSpec.Views = myViews; mapSpec.DataSourceName = "MapPoint.NA"; mapSpec.Options = new MapOptions(); mapSpec.Options.Format = new ImageFormat(); mapSpec.Options.Format.Height = imageHeight; mapSpec.Options.Format.Width = imageWidth; // setup pushpin Pushpin[] ppArray = new Pushpin[2]; // set up start ppArray[0] = new Pushpin(); ppArray[0].IconDataSource = "MapPoint.Icons"; ppArray[0].IconName = "31"; ppArray[0].LatLong = route.Itinerary.Segments[0].Waypoint.Location.LatLong; ppArray[0].Label = "Start"; ppArray[0].ReturnsHotArea = true; // PinID ppArray[0].PinID = "Start"; // set up end ppArray[1] = new Pushpin(); ppArray[1].IconDataSource = "MapPoint.Icons"; ppArray[1].IconName = "29"; ppArray[1].LatLong = route.Itinerary.Segments[route.Itinerary.Segments.GetUpperBound(0)].Waypoint.Location.LatLong; ppArray[1].Label = "End"; ppArray[1].ReturnsHotArea = true; // PinID ppArray[1].PinID = "End"; mapSpec.Pushpins = ppArray; mapSpec.Route = route; mapImage = theMapPointRenderService.GetMap(mapSpec); // let sure an MapImage was returned if (mapImage != null && mapImage.Length > 0) { theImage = new System.Drawing.Bitmap(new System.IO.MemoryStream(mapImage[0].MimeData.Bits)); } else throw new System.Exception("Unable to build a map for this route"); } catch (ArgumentNullException e) { throw e; // rethrow for app to handle } catch (Exception e) { throw e; // rethrow for app to handle } return theImage; }
/// <summary> /// This method will return a image representing a map /// </summary> /// <param name="location">result from the FindLocation method</param> /// <param name="imageWidth">width of image used to display the map</param> /// <param name="imageHeight">height of the image used to display the map</param> /// <param name="zoom">floating point number > 0 respresent amount of zoom on the returned map</param> /// <returns>Address</returns> public System.Drawing.Image GetMap(Location location, int imageWidth, int imageHeight, double zoom) { MapImage[] mapImage; System.Drawing.Bitmap theImage = null; try { if (location == null) { throw new System.ArgumentNullException("Location cannot be null"); } if (imageWidth <= 0) { throw new System.ArgumentNullException("Image width should be > then 0"); } if (imageHeight <= 0) { throw new System.ArgumentNullException("Image Height should be > then 0"); } if (zoom <= 0) { throw new System.ArgumentNullException("Zoom should be great then 0"); } // now get a map MapSpecification mapSpec = new MapSpecification(); //ViewByScale[] myViews = new ViewByScale[1]; MapView[] myViews = new MapView[1]; myViews[0] = location.BestMapView.ByHeightWidth; mapSpec.Views = myViews; mapSpec.DataSourceName = "MapPoint.NA"; mapSpec.Options = new MapOptions(); mapSpec.Options.Format = new ImageFormat(); mapSpec.Options.Format.Height = imageHeight; mapSpec.Options.Format.Width = imageWidth; mapSpec.Options.Zoom = zoom; // setup pushpin Pushpin[] ppArray = new Pushpin[1]; // set up a sample push pin ppArray[0] = new Pushpin(); ppArray[0].IconDataSource = "MapPoint.Icons"; ppArray[0].IconName = "168"; ppArray[0].LatLong = location.LatLong; ppArray[0].Label = "You are here"; ppArray[0].ReturnsHotArea = true; // PinID contains the db key and the ADE NAME seperated by a tilde ppArray[0].PinID = "where I am now"; mapSpec.Pushpins = ppArray; mapImage = theMapPointRenderService.GetMap(mapSpec); // let sure an MapImage was returned if (mapImage != null && mapImage.Length > 0) { theImage = new System.Drawing.Bitmap(new System.IO.MemoryStream(mapImage[0].MimeData.Bits)); } else throw new System.Exception("Unable to build a map for this route"); } catch (ArgumentNullException e) { throw e; // rethrow for app to handle } catch (Exception e) { throw e; // rethrow for app to handle } return theImage; }