Exemple #1
0
        /// <summary>
        /// Sending a request for all involved base layers, which provide some extension of their requests by a snippet mechanism.
        /// </summary>
        public void RefreshMap()
        {
            var snippet = FeatureLayerXElement.ToString();

            foreach (var refreshInfo in RefreshInfos())
            {
                refreshInfo.provider.CustomCallerContextProperties = new[] { new xserver.CallerContextProperty {
                                                                                 key = "ProfileXMLSnippet", value = snippet
                                                                             } };

                refreshInfo.provider.ReferenceTime = ReferenceTime;

                if (refreshInfo.layer.Name == "Labels")
                {
                    // The insertion of xServer.FeatureLayer objects into the CustomXMapLayers results in a providing of ObjectInfo objects in the return value
                    // of XMap.RenderMapBoundingBox(). Only by means of these objects, it is possible to retrieve information for tool tips.
                    var xServerLayers = new List <xserver.Layer>();
                    if (UseTrafficIncidents)
                    {
                        xServerLayers.Add(new xserver.FeatureLayer {
                            name = "PTV_TrafficIncidents", visible = true, objectInfos = xserver.ObjectInfoType.REFERENCEPOINT
                        });
                    }
                    if (UseTruckAttributes)
                    {
                        xServerLayers.Add(new xserver.FeatureLayer {
                            name = "PTV_TruckAttributes", visible = true, objectInfos = xserver.ObjectInfoType.REFERENCEPOINT
                        });
                    }
                    if (UsePreferredRoutes)
                    {
                        xServerLayers.Add(new xserver.FeatureLayer {
                            name = "PTV_PreferredRoutes", visible = true, objectInfos = xserver.ObjectInfoType.REFERENCEPOINT
                        });
                    }
                    if (UseRestrictionZones)
                    {
                        xServerLayers.Add(new xserver.FeatureLayer {
                            name = "PTV_RestrictionZones", visible = true, objectInfos = xserver.ObjectInfoType.REFERENCEPOINT
                        });
                    }
                    if (UseSpeedPatterns)
                    {
                        xServerLayers.Add(new xserver.FeatureLayer {
                            name = "PTV_SpeedPatterns", visible = true, objectInfos = xserver.ObjectInfoType.REFERENCEPOINT
                        });
                    }

                    refreshInfo.provider.CustomXMapLayers = xServerLayers;
                }
                refreshInfo.layer.Refresh();
            }
        }
        /// <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); }
        }