/// <summary>
        /// Helper method for setting the enable flag of a dedicated Feature Layer (specified by the corresponding theme).
        /// If the XML file contains some invalid content, the current value is not changed.
        /// </summary>
        /// <param name="themeId">Textual representation of the theme (id), which is directly used the XML snippet. </param>
        /// <param name="value">Enable/disable the corresponding Feature Layer, i.e. showing/hiding its content in the map and
        /// taking into consideration its attributes or not. </param>
        private void SetEnabled(string themeId, bool value)
        {
            try
            {
                FeatureLayerXElement.XPathSelectElements("./FeatureLayer/Themes/Theme")
                .First(theme => theme.Attribute("id").Value == themeId)
                .Attribute("enabled")
                .Value = value.ToString().ToLower();

                if (UseTrafficIncidents || UseTruckAttributes || UsePreferredRoutes || UseRestrictionZones || UseSpeedPatterns)
                {
                    if (map.Layers["Feature Layer routes"] == null)
                    {
                        shapeLayer = new ShapeLayer("Feature Layer routes");
                        map.Layers.InsertBefore(shapeLayer, "Labels");
                    }
                }
                else
                {
                    if (map.Layers["Feature Layer routes"] != null)
                    {
                        map.Layers.Remove(map.Layers["Feature Layer routes"]);
                        shapeLayer = null;
                    }
                }
            }
            catch { return; } // Something does not match the XML

            RefreshMap();
        }
 /// <summary>
 /// Helper method for getting the enable flag of a dedicated Feature Layer (specified by the corresponding theme).
 /// If the XML file contains some invalid content, the value 'false' is returned.
 /// </summary>
 /// <param name="themeId">Textual representation of the theme (id), which is directly used the XML snippet. </param>
 /// <returns>Returns the Enable/disable flag of the corresponding Feature Layer. </returns>
 private bool GetEnabled(string themeId)
 {
     try
     {
         return(Convert.ToBoolean(
                    FeatureLayerXElement.XPathSelectElements("./FeatureLayer/Themes/Theme")
                    .First(theme => theme.Attribute("id").Value == themeId)
                    .Attribute("enabled").Value));
     }
     catch { return(false); } // Something does not match the XML
 }
示例#3
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); }
        }
 private bool GetAvailable(string themeId)
 {
     try { return(FeatureLayerXElement.XPathSelectElements("./FeatureLayer/Themes/Theme").Any(theme => theme.Attribute("id")?.Value == themeId)); }
     catch { return(false); } // Something does not match the XML
 }