/// <summary> /// Factory for the of the xServer generated client class granting access to the xRoute server. /// If xServers are used on an Azure environment, authentication data has to be integrated when /// requests are made. /// </summary> /// <param name="xUrl">The xServer base url. </param> /// <returns></returns> public static XRouteWSClient CreateXRouteClient(string xUrl) { string completeXServerUrl = XServerUrl.Complete(xUrl, "XRoute"); var binding = new BasicHttpBinding { ReceiveTimeout = new TimeSpan(0, 0, 30), SendTimeout = new TimeSpan(0, 0, 30), OpenTimeout = new TimeSpan(0, 0, 30), CloseTimeout = new TimeSpan(0, 0, 30), MaxReceivedMessageSize = int.MaxValue }; var endpoint = new EndpointAddress(completeXServerUrl); var client = new XRouteWSClient(binding, endpoint); if (!XServerUrl.IsXServerInternet(completeXServerUrl)) { return(client); } binding.Security.Mode = BasicHttpSecurityMode.Transport; binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; client.ClientCredentials.SetConfiguredToken(); return(client); }
/// <summary> /// When accessing PTV xServer in the cloud, inject the default token /// when no user or password is provided through the configuration file. /// </summary> private static void SetDefaultPtvXServerInternetToken() { if (XServerUrl.IsXServerInternet(XServerUrl.Complete(Settings.Default.XUrl, "XMap")) && !String.IsNullOrEmpty(DefaultXServerInternetToken.Value) && String.IsNullOrEmpty(Settings.Default.XToken)) { Settings.Default["XToken"] = DefaultXServerInternetToken.Value; // overwrite settings with default access token } }
/// <summary> Initializes a new instance of the <see cref="RoutingUseCase"/> class. Adds two way points and calculates the route. </summary> /// <param name="wpfMap"> The map on which the route calculation is to be displayed. </param> public RoutingUseCase(WpfMap wpfMap) { InitializeComponent(); // save the map _wpfMap = wpfMap; #region doc:register mouse handler _wpfMap.MouseRightButtonDown += wpfMap_MapMouseRightButtonDown; ContextMenuService.SetContextMenu(_wpfMap, cm); #endregion //doc:register mouse handler #region doc:Add ShapeLayers routingLayer = new ShapeLayer("Routing") { SpatialReferenceId = "PTV_MERCATOR" }; wayPointLayer = new ShapeLayer("WayPoints") { SpatialReferenceId = "PTV_MERCATOR" }; wayPoints.CollectionChanged += points_CollectionChanged; // add before labels (if available) var idx = _wpfMap.Layers.IndexOf(_wpfMap.Layers["Labels"]); if (idx < 0) { _wpfMap.Layers.Add(routingLayer); _wpfMap.Layers.Add(wayPointLayer); } else { _wpfMap.Layers.Insert(idx, routingLayer); _wpfMap.Layers.Add(wayPointLayer); } #endregion //doc:Add ShapeLayers if (XServerUrl.IsDecartaBackend(XServerUrl.Complete(Properties.Settings.Default.XUrl, "XRoute"))) { return; } // insert way points of Karlsruhe-Berlin clickPoint = new PlainPoint { x = 934448.8, y = 6269219.7 }; SetStart_Click(null, null); clickPoint = new PlainPoint { x = 1491097.3, y = 6888163.5 }; SetEnd_Click(null, null); // calculate the route CalculateRoute(); }
/// <summary> /// Inserts the xMapServer base layers, i.e. the background layers for areas like forests, rivers, population areas, et al, /// and their corresponding labels. /// </summary> /// <param name="layers">The LayerCollection instance, used as an extension. </param> /// <param name="meta">Meta information for xMapServer, further details can be seen in the <see cref="XMapMetaInfo"/> description. </param> public static void InsertXMapBaseLayers(this LayerCollection layers, XMapMetaInfo meta) { var baseLayer = new TiledLayer(BackgroundLayerName) { TiledProvider = new XMapTiledProvider(meta.Url, meta.User, meta.Password, XMapMode.Background), Copyright = meta.CopyrightText, Caption = MapLocalizer.GetString(MapStringId.Background), IsBaseMapLayer = true, Icon = ResourceHelper.LoadBitmapFromResource("Ptv.XServer.Controls.Map;component/Resources/Background.png") }; if (BaseLayerSuccessor != null && layers[BaseLayerSuccessor] != null) { layers.Insert(layers.IndexOf(layers[BaseLayerSuccessor]), baseLayer); } else { // add tile layer layers.Add(baseLayer); BaseLayerSuccessor = null; } // don't add overlay layer for Decarta-powered maps (basemap is completely rendered on tiles) if (XServerUrl.IsDecartaBackend(meta.Url)) { return; } var labelLayer = new UntiledLayer(LabelsLayerName) { UntiledProvider = new XMapTiledProvider(meta.Url, meta.User, meta.Password, XMapMode.Town), MaxRequestSize = meta.MaxRequestSize, Caption = MapLocalizer.GetString(MapStringId.Labels), Icon = ResourceHelper.LoadBitmapFromResource("Ptv.XServer.Controls.Map;component/Resources/Labels.png") }; if (LabelLayerPredecessor != null && layers[LabelLayerPredecessor] != null && layers.IndexOf(layers[LabelLayerPredecessor]) < layers.Count) { layers.Insert(layers.IndexOf(layers[LabelLayerPredecessor]) + 1, labelLayer); } else { // add label layer layers.Add(labelLayer); LabelLayerPredecessor = null; } }
/// <summary> /// Factory for the of the xServer generated client class granting access to the xRoute server. /// If xServers are used on an Azure environment, authentication data has to be integrated when /// requests are made. /// </summary> /// <param name="xUrl">The xServer base url. </param> /// <param name="user"> User name. </param> /// <param name="password"> Password. </param> /// <returns> xRoute API based on Web Services. </returns> public static XRouteWSClient CreateXRouteClient(string xUrl, string user, string password) { var completeXServerUrl = XServerUrl.Complete(xUrl, "XRoute"); var binding = new BasicHttpBinding { ReceiveTimeout = new TimeSpan(0, 0, 30), SendTimeout = new TimeSpan(0, 0, 30), OpenTimeout = new TimeSpan(0, 0, 30), CloseTimeout = new TimeSpan(0, 0, 30), MaxReceivedMessageSize = int.MaxValue }; var endpoint = new EndpointAddress(completeXServerUrl); var client = new XRouteWSClient(binding, endpoint); if (!XServerUrl.IsXServerInternet(completeXServerUrl)) { return(client); } binding.Security.Mode = BasicHttpSecurityMode.Transport; binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; client.ClientCredentials.UserName.UserName = user; client.ClientCredentials.UserName.Password = password; // increase message size (client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = 4 << 20; (client.Endpoint.Binding as BasicHttpBinding).ReaderQuotas.MaxBytesPerRead = 4 << 20; // set timeouts client.Endpoint.Binding.SendTimeout = TimeSpan.FromMilliseconds(5000); client.Endpoint.Binding.ReceiveTimeout = TimeSpan.FromMilliseconds(10000); return(client); }
public string AdjustedUrl(string moduleName = "xmap") { return(XServerUrl.Complete(baseUrl, moduleName)); }
private bool ConfigureWPFMap(Map map) { #region doc:Static Map Control // Initialize map control with xMap layers, especially the URL of the xServer. // For layers provided on Azure xServers, an xToken has to be taken into consideration. This information is // managed in the Usecase base class, which is globally available for the application and all other use cases. if (!UseCase.ManagedAuthentication.IsOk) { return(false); } // Safe the layer order for realigning. var layerOrder = map.Layers.Select(layer => layer.Name).ToList(); // Remove only layers which are potentially inserted by this method. map.Layers.RemoveXMapBaseLayers(); map.Layers.Remove(map.Layers["Poi"]); if (map.Layers["Feature Layer routes"] != null) { map.Layers.Remove(map.Layers["Feature Layer routes"]); } map.Layers.InsertXMapBaseLayers(UseCase.ManagedAuthentication.XMapMetaInfo); // Feature Layer settings featureLayerUseCase = new FeatureLayerUseCase(map) { ScenarioChanged = (theme, isBegin) => { Cursor = isBegin ? Cursors.AppStarting : Cursors.Arrow; ComboBoxBy(theme).IsEnabled = CheckBoxBy(theme).IsEnabled = !isBegin; } }; InitFeatureLayer(featureLayerUseCase.AvailableTrafficIncidents, TrafficIncidentsComboBox, TrafficIncidentsCheckBox); InitFeatureLayer(featureLayerUseCase.AvailableTruckAttributes, TruckAttributesComboBox, TruckAttributesCheckBox); InitFeatureLayer(featureLayerUseCase.AvailableRestrictionZones, RestrictionZonesComboBox, RestrictionZonesCheckBox); InitFeatureLayer(featureLayerUseCase.AvailablePreferredRoutes, PreferredRoutesComboBox, PreferredRoutesCheckBox); InitFeatureLayer(featureLayerUseCase.AvailableSpeedPatterns, SpeedPatternsComboBox, SpeedPatternsCheckBox); // Triggers the MapProfile use case to change the maps profile. ProfileOKButton_OnClick(null, null); // add POI layer (if available) var url = UseCase.ManagedAuthentication.XMapMetaInfo.Url; if (!(XServerUrl.IsDecartaBackend(url) || XServerUrl.IsXServerInternet(url) && url.Contains("china"))) { #region doc:AdditionalLayerCreation map.InsertPoiLayer(UseCase.ManagedAuthentication.XMapMetaInfo, "Poi", "default.points-of-interest", "Points of interest"); #endregion } // recreate the old layer order if the set of layers has not changed if (map.Layers.All(layer => layerOrder.Contains(layer.Name))) { var layers = layerOrder .Where(name => map.Layers[name] != null) .Select((name, index) => new { newIndex = index, oldIndex = map.Layers.IndexOf(map.Layers[name]) }); foreach (var item in layers) { map.Layers.Move(item.oldIndex, item.newIndex); } } if (UseCase.ManagedAuthentication.XMapMetaInfo.GetRegion() == Region.eu) { map.SetMapLocation(new Point(8.4, 49), 10); // Center in Karlsruhe } else if (UseCase.ManagedAuthentication.XMapMetaInfo.GetRegion() == Region.na) { map.SetMapLocation(new Point(-74.11, 40.93), 10); // Center in New York } else if (UseCase.ManagedAuthentication.XMapMetaInfo.GetRegion() == Region.au) { map.SetMapLocation(new Point(149.16, -35.25), 10); // Center in Canberra } else { map.SetMapLocation(new Point(0, 33), 1.8); // Center on equator, meridian } #endregion return(true); }