/// <summary> /// Calculates a route and displays the calculated polygons in the map. /// </summary> /// <param name="scenario">Scenario which defines the route to calculate.</param> /// <param name="calculateWithFeatureLayer">Option if the currently selected Feature Layer theme should be used.</param> private void CalculateRoute(Scenario scenario, bool calculateWithFeatureLayer) { XRouteWS xRoute = XServerClientFactory.CreateXRouteClient(Settings.Default.XUrl); try { var now = DateTime.Now; var nowString = $"{now.Year}-{now.Month}-{now.Day}T{now.Hour}:{now.Minute}:{now.Second}+00:00"; var response = xRoute.calculateRoute(new calculateRouteRequest { ArrayOfWaypointDesc_1 = scenario.wayPoints.Select(p => new WaypointDesc { wrappedCoords = new[] { new Point { point = p } }, linkType = LinkType.NEXT_SEGMENT, fuzzyRadius = 10000 }).ToArray(), ResultListOptions_4 = new ResultListOptions { dynamicInfo = calculateWithFeatureLayer, polygon = true }, ArrayOfRoutingOption_2 = new[] { new RoutingOption { parameter = RoutingParameter.START_TIME, value = nowString } }, CallerContext_5 = new CallerContext { wrappedProperties = new[] { new CallerContextProperty { key = "CoordFormat", value = "OG_GEODECIMAL" }, new CallerContextProperty { key = "Profile", value = "truckfast" }, new CallerContextProperty { key = "ProfileXMLSnippet", value = calculateWithFeatureLayer ? FeatureLayerXElement.ToString() : DeactivatedXElement.ToString() } } } }); map.Dispatcher.BeginInvoke(new Action <Route>(DisplayRouteInMap), response.result); } catch (EntryPointNotFoundException) { System.Windows.MessageBox.Show(Properties.Resources.ErrorRouteCalculationDefault); } catch (System.ServiceModel.FaultException <XRouteException> faultException) { var s = faultException.Detail.stackElement; System.Windows.MessageBox.Show((s.errorKey == null || s.errorKey == "2530") ? Properties.Resources.ErrorRouteCalculationDefault : s.message); } catch { System.Windows.MessageBox.Show(Properties.Resources.ErrorRouteCalculationDefault); } }
/// <summary> Calculates the route between the given way points. </summary> private void CalculateRoute() { switch (wayPoints.Count) { case 0: Dispatcher.BeginInvoke(new Action <string>(DisplayError), Properties.Resources.ErrorNoWaypointsSet); return; case 1: Dispatcher.BeginInvoke(new Action <string>(DisplayError), Properties.Resources.ErrorNoDestWayPoint); return; } // reset context menu ContextMenuService.SetContextMenu(_wpfMap, null); #region doc:call xroute // build xServer wayPoints array from wayPoints var selectedWayPoints = wayPoints.Select(p => new WaypointDesc { wrappedCoords = new[] { new XrouteService.Point { point = p } }, linkType = LinkType.NEXT_SEGMENT, fuzzyRadius = 10000 }).ToArray(); Dispatcher.Invoke(delegate { Mouse.OverrideCursor = Cursors.Wait; }); XRouteWS xRoute = XServerClientFactory.CreateXRouteClient(Properties.Settings.Default.XUrl); try { xRoute.BegincalculateRoute(new calculateRouteRequest { ArrayOfWaypointDesc_1 = selectedWayPoints, ResultListOptions_4 = new ResultListOptions { polygon = true } }, Invoke, xRoute); } catch (EntryPointNotFoundException) { Dispatcher.BeginInvoke(new Action <string>(DisplayError), Properties.Resources.ErrorRouteEndpointNotFound); } #endregion //doc:call xroute }
/// <summary> /// Sends a route request to xRoute /// </summary> /// <param name="param">The parameter, must be a request data object</param> public void SendRequest(object param) { // associated data object var data = param as RequestData; lock (routeClientLock) { // abort any previous request that might be active xroute?.Abort(); // create xRoute web service client xroute = XServerClientFactory.CreateXRouteClient(Demo.Properties.Settings.Default.XUrl); // increase message size (xroute.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = 4 << 20; (xroute.Endpoint.Binding as BasicHttpBinding).ReaderQuotas.MaxBytesPerRead = 4 << 20; // set timeouts xroute.Endpoint.Binding.SendTimeout = TimeSpan.FromMilliseconds(5000); xroute.Endpoint.Binding.ReceiveTimeout = TimeSpan.FromMilliseconds(10000); // finally trigger an asynchronous route calculation with the specified request data xroute.BegincalculateRoute(data?.RequestWaypoints, null, null, new Demo.XrouteService.ResultListOptions { polygon = true }, new Demo.XrouteService.CallerContext { wrappedProperties = new[] { new Demo.XrouteService.CallerContextProperty { key = "CoordFormat", value = "PTV_SMARTUNITS" }, new Demo.XrouteService.CallerContextProperty { key = "ResponseGeometry", value = "WKB" } } }, RouteCalculated, data); } }