/// <summary> /// Return the Traffic Incidents along a given route /// </summary> /// <param name="route">a route</param> /// <param name="distance">a double representing the distance from the route for which /// you want incidents reports</param> /// <returns>FindResults</returns> public FindResults GetTrafficIncident(Route route, Double distance) { FindResults foundResults; try { if (route == null) { throw new System.ArgumentNullException("End location cannot be null"); } FindFilter ff = new FindFilter(); ff.EntityTypeName = "TrafficIncident"; FindNearRouteSpecification spec = new FindNearRouteSpecification(); spec.DataSourceName = "MapPointTravel.TrafficIncidents"; spec.Distance = distance; //show all incidents within 1 mile of the route spec.Route = route; //arg passed in spec.Filter = ff; foundResults = new FindResults(); foundResults = theMapPointFindService.FindNearRoute(spec); } catch (ArgumentNullException e) { throw e; // rethrow for app to handle } catch (Exception e) { throw e; // rethrow for app to handle } return foundResults; }
/// <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; }