public void ShowDimaInDynMap(dynamic idList, dynamic locationsList, dynamic violatedLocationsList) { var dimaPointsLayer = new List <System.Windows.Point>(); reachablePointsLayer = new ShapeLayer("Reachable") { SpatialReferenceId = "EPSG:4326" }; int i = 0; foreach (var reachWaypoint in locationsList) { i++; System.Windows.Point reachableDimaPoint; var markerBlue = new Ptv.XServer.Controls.Map.Symbols.Ball { Color = System.Windows.Media.Colors.Blue }; reachableDimaPoint = new System.Windows.Point(reachWaypoint.coordinate.x, reachWaypoint.coordinate.y); ShapeCanvas.SetLocation(markerBlue, reachableDimaPoint); markerBlue.Width = markerBlue.Height = 20; markerBlue.ToolTip = i + " - " + idList[i - 1]; reachablePointsLayer.Shapes.Add(markerBlue); reachablePointsLayer.Refresh(); dimaPointsLayer.Add(reachableDimaPoint); } violatedPointsLayer = new ShapeLayer("Violated") { SpatialReferenceId = "EPSG:4326" }; int j = 0; foreach (var reachWaypoint in violatedLocationsList) { j++; System.Windows.Point reachableDimaPoint; var markerBlue = new Ptv.XServer.Controls.Map.Symbols.Ball { Color = System.Windows.Media.Colors.Red }; reachableDimaPoint = new System.Windows.Point(reachWaypoint.coordinate.x, reachWaypoint.coordinate.y); ShapeCanvas.SetLocation(markerBlue, reachableDimaPoint); markerBlue.Width = markerBlue.Height = 13; //markerBlue.ToolTip = i + " - " + idList[i - 1]; reachablePointsLayer.Shapes.Add(markerBlue); reachablePointsLayer.Refresh(); dimaPointsLayer.Add(reachableDimaPoint); } dynMap.Layers.Add(reachablePointsLayer); dynMap.Layers.Add(violatedPointsLayer); reachablePointsLayer.Refresh(); violatedPointsLayer.Refresh(); dynMap.SetEnvelope(new Ptv.XServer.Controls.Map.MapRectangle(dimaPointsLayer).Inflate(1.1, 1.1), "EPSG:4326"); dynMap.Focus(); }
/*/public void CalcDima(RootObject daveRequestJson) * { * List<xDimaWSService.RouteLocation> dimaWayPointList = new List<xDimaWSService.RouteLocation>(); * xDimaWSService.RouteLocation[] dipw = null; * * var violatedLocationsList = new List<xDimaWSService.OnRoadRouteLocation>(); * violatedIdList = new List<string>(); * idList = new List<string>(); * * var drr = new xDimaWSService.CreateAndGetDistanceMatrixRequest * { * coordinateFormat = "EPSG:4326", * storedProfile = cbxStoredProfile.Text * }; * * var dimaTaTheme = new xDimaWSService.Theme * { * id = "PTV_TruckAttributes", * enabledSpecified = true * }; * * dimaTaTheme.enabled = false; * * if (cbxFLTruckAttributes.Checked == true) * { * dimaTaTheme.enabled = true; * } * * drr.requestProfile = new xDimaWSService.RequestProfile() * { * featureLayerProfile = new xDimaWSService.FeatureLayerProfile() * { * themes = new xDimaWSService.Theme[] * { * dimaTaTheme * }, * }, * }; * * if (daveRequestJson.stops.Count >= 2) * { * foreach (var stop in daveRequestJson.stops) * { * var wpt = new xDimaWSService.OnRoadRouteLocation() * { * coordinate = new xDimaWSService.Coordinate() * { * x = stop.coordinate.locationX, * y = stop.coordinate.locationY * } * }; * dimaWayPointList.Add(wpt); * } * } * else * { * MessageBox.Show("Not enough waypoints!"); * return; * } * * foreach (var scemId in daveRequestJson.stops) * { * idList.Add(scemId.scemid.ToString()); * } * * dipw = dimaWayPointList.ToArray(); * drr.startLocations = dipw; * var locationsList = dipw.OfType<xDimaWSService.OnRoadRouteLocation>().ToList(); * drr.resultFields = new xDimaWSService.DistanceMatrixContentsResultFields() * { * distances = true, * distancesSpecified = true, * violated = true, * violatedSpecified = true, * estimatedByDirectDistance = true, * estimatedByDirectDistanceSpecified = true * }; * * try * { * dimaResponse = xDimaClient.createDistanceMatrix(drr); * } * catch (System.Web.Services.Protocols.SoapException soapException) * { * System.Windows.Forms.MessageBox.Show(soapException.Detail.InnerXml.Replace(">", ">\r\n")); * return; * } * catch (System.ServiceModel.FaultException faultException) * { * System.Windows.Forms.MessageBox.Show("Error when trying to calculate the dima" + "\r\n" + faultException.Message); * return; * } * catch (Exception ex) * { * MessageBox.Show(ex.Message); * return; * } * * waypointCount = dimaResponse.summary.numberOfStartLocations; * distanceMatrixResponseContents = dimaResponse.contents as xDimaWSService.DistanceMatrixContentsArrays; * * for (int i = 0; i < dimaResponse.summary.numberOfStartLocations; i++) * { * var numberOfViolations = 0; * for (int j = 0; j < dimaResponse.summary.numberOfStartLocations; j++) * { * if (distanceMatrixResponseContents.violated[i * dimaResponse.summary.numberOfStartLocations + j]) * { * numberOfViolations++; * } * } * if (numberOfViolations >= waypointCount - 1) * { * violatedLocationsList.Add(locationsList[i]); * } * } * * ShowDimaInDynMap(idList, locationsList, violatedLocationsList); * waypointCount = 0; * } * /*/ public void ShowRouteInDynMap() { var mapCoordFormat = ""; if (cbxCoordFormat.Text == "EPSG:76131") { routingLayer = new ShapeLayer("Route") { SpatialReferenceId = "PTV_MERCATOR" }; mapCoordFormat = "PTV_MERCATOR"; } else if (cbxCoordFormat.Text == "EPSG:4326") { routingLayer = new ShapeLayer("Route") { SpatialReferenceId = "EPSG:4326" }; mapCoordFormat = "EPSG:4326"; } else if (cbxCoordFormat.Text == "EPSG:3857") { routingLayer = new ShapeLayer("Route") { SpatialReferenceId = "EPSG:3857" }; mapCoordFormat = "EPSG:3857"; } if (routeResponse.polyline != null) { var routePoly = routeResponse.polyline.plain as xRouteWSService.Polyline; var points = new PointCollection(); foreach (xRouteWSService.Coordinate p in routePoly.polyline) { points.Add(new System.Windows.Point(p.x, p.y)); } MapPolyline mapPolyLine = new MapPolyline() { Points = points, Stroke = new SolidColorBrush(Colors.Blue), MapStrokeThickness = 10, Opacity = 1.0, ScaleFactor = 0.2 }; (routingLayer as ShapeLayer).Shapes.Add(mapPolyLine); mapPolyLine.ToolTip = string.Format("{0:0,0.0}km\n{1}", Math.Round(routeResponse.distance / 1000.0, 2), TimeSpan.FromSeconds(routeResponse.travelTime)); } else { MessageBox.Show("Error while calculating route"); return; } var markerStart = new Ptv.XServer.Controls.Map.Symbols.Ball { Color = Colors.Green }; var markerVia = new Ptv.XServer.Controls.Map.Symbols.Ball { Color = Colors.Yellow }; var markerDest = new Ptv.XServer.Controls.Map.Symbols.Ball { Color = Colors.Red }; mapCoordStart = new System.Windows.Point(double.Parse(tbxStartX.Text.Replace(".", ",")), double.Parse(tbxStartY.Text.Replace(".", ","))); mapCoordDest = new System.Windows.Point(double.Parse(tbxDestX.Text.Replace(".", ",")), double.Parse(tbxDestY.Text.Replace(".", ","))); ShapeCanvas.SetLocation(markerStart, mapCoordStart); ShapeCanvas.SetLocation(markerDest, mapCoordDest); markerStart.Width = markerStart.Height = markerDest.Height = markerDest.Width = markerVia.Height = markerVia.Width = 10; markerStart.ToolTip = "Start"; markerDest.ToolTip = "Destination"; if (cbxManipulateWpt.Checked == true) { mapCoordVia = new System.Windows.Point(double.Parse(tbxViaX.Text.Replace(".", ",")), double.Parse(tbxViaY.Text.Replace(".", ","))); ShapeCanvas.SetLocation(markerVia, mapCoordVia); markerVia.ToolTip = "Via"; routingLayer.Shapes.Add(markerVia); } routingLayer.Shapes.Add(markerStart); routingLayer.Shapes.Add(markerDest); dynMap.Layers.Add(routingLayer); //zoom to contain route MapRectangle mergedRoutesRectangle = new MapRectangle(); var polyLine = routeResponse.polyline.plain as xRouteWSService.Polyline; var winPoints = from coord in polyLine.polyline select new System.Windows.Point(coord.x, coord.y); mergedRoutesRectangle |= new MapRectangle(winPoints); dynMap.SetEnvelope(mergedRoutesRectangle.Inflate(1.2), mapCoordFormat); routingLayer.Refresh(); }
private void searchFerryButton_Click(object sender, EventArgs e) { try { Cursor = Cursors.WaitCursor; ferryLayer.Shapes.Clear(); routeLayer.Shapes.Clear(); if (string.IsNullOrEmpty(combinedTransportDepartureTextBox.Text)) { MessageBox.Show("You must fill in the combined transport departure. Only the arrival is optional"); return; } using (var xlocate = XWSClientFactory.GetXLocateWSClient(Properties.Settings.Default.XLocate, token)) { //geocode both cities, even if destiantion is left blank, i rather keep call numbers low to avoid extra latency var addresses = new Address[] { new Address() { city = combinedTransportDepartureTextBox.Text }, new Address() { city = combinedTransportArrivalTextBox.Text }, }; var addressResponse = xlocate.findAddresses(addresses, null, null, null, null); // check if we have found a start city else abort if (addressResponse[0].wrappedResultList == null || addressResponse[0].wrappedResultList.Length == 0) { MessageBox.Show("Departure city not found"); return; } // search for ferrie near departure, use a max range to prevent huge list var departureLocation = new Location() { coordinate = addressResponse[0].wrappedResultList[0].coordinates }; var searchOptions = new ReverseSearchOption[] { new ReverseSearchOption() { param = ReverseSearchParameter.ENGINE_SEARCHRANGE, value = Properties.Settings.Default.SeachRange.ToString(), }, }; var resultFields = new ResultField[] { ResultField.ISBLOCKEDFORTRUCKS, ResultField.ISBLOCKEDFORHAZARDOUSGOODS, ResultField.ISBLOCKEDFORCOMBUSTIBLEGOODS, }; var combinedTransportResponse = xlocate.findCombinedTransportByLocation(departureLocation, searchOptions, null, null); var resultCombinedTransports = combinedTransportResponse.wrappedResultList.ToList(); // by default xlocate return all ferrie that have a start or end near the location // we are only using the ones near the start, so filter on max range airline distance resultCombinedTransports = resultCombinedTransports.Where(r => Geotools.AirLineDistanceCalculator.CalculateUsingMercator( r.start.coordinate.point, addressResponse[0].wrappedResultList[0].coordinates.point) <= Properties.Settings.Default.SeachRange).ToList(); // if we have found a destination city, filter on ferries that have destination within max range airline if (addressResponse[1].wrappedResultList != null && addressResponse[1].wrappedResultList.Length != 0) { resultCombinedTransports = resultCombinedTransports.Where(r => Geotools.AirLineDistanceCalculator.CalculateUsingMercator( r.destination.coordinate.point, addressResponse[1].wrappedResultList[0].coordinates.point) <= Properties.Settings.Default.SeachRange).ToList(); } // show the result resultCombinedTransportBindingSource.DataSource = resultCombinedTransports; // paint the results on the map #region visualise foreach (var resultCombinedTransport in resultCombinedTransports) { System.Windows.Point startPoint = new System.Windows.Point( resultCombinedTransport.start.coordinate.point.x, resultCombinedTransport.start.coordinate.point.y ); System.Windows.Point endPoint = new System.Windows.Point( resultCombinedTransport.destination.coordinate.point.x, resultCombinedTransport.destination.coordinate.point.y ); var line = new Ptv.XServer.Controls.Map.Layers.Shapes.MapPolyline() { MapStrokeThickness = 6, Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Blue), Points = new System.Windows.Media.PointCollection(), ToolTip = $"{resultCombinedTransport.name}\n{resultCombinedTransport.type}\n{resultCombinedTransport.duration}\n{resultCombinedTransport.distance}\n{resultCombinedTransport.id}", }; line.Points.Add(startPoint); line.Points.Add(endPoint); ferryLayer.Shapes.Add(line); var startBall = new Ptv.XServer.Controls.Map.Symbols.Ball() { Height = 15, Width = 15, Color = System.Windows.Media.Colors.Green, ToolTip = $"{resultCombinedTransport.start.country} - {resultCombinedTransport.start.name}", }; Ptv.XServer.Controls.Map.Layers.Shapes.ShapeCanvas.SetLocation(startBall, startPoint); ferryLayer.Shapes.Add(startBall); var endBall = new Ptv.XServer.Controls.Map.Symbols.Ball() { Height = 15, Width = 15, Color = System.Windows.Media.Colors.Red, ToolTip = $"{resultCombinedTransport.destination.country} - {resultCombinedTransport.destination.name}", }; Ptv.XServer.Controls.Map.Layers.Shapes.ShapeCanvas.SetLocation(endBall, endPoint); ferryLayer.Shapes.Add(endBall); } map.WrappedMap.ZoomToAll(); #endregion } } catch (Exception exception) { MessageBox.Show(exception.Message, exception.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { Cursor = null; } }