/// <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; } }
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); }