private string clientGetDescription(RoutingResult.Rootobject _route) { if (_route == null) { throw new ArgumentNullException(nameof(_route)); } if (!_route.IsValid) { throw new ArgumentException("_route -> not valid"); } var _htmlDescription = string.Empty; _htmlDescription += @"<html>"; _htmlDescription += @"<body>"; _htmlDescription += @"<font size=2>"; _htmlDescription += @"<p>"; _htmlDescription += $@"<b>Ziel: </b>{_route.StoppointText}<br />"; if (_route.Duration != null) { _htmlDescription += $@"<b>Dauer: </b>{_route.Duration.Value.TotalMinutes.ToString("F1")} min<br />"; } if (_route.Distance != null) { _htmlDescription += $@"<b>Strecke: </b>{(_route.Distance.Value / 1000).ToString("F1")} km<br />"; } _htmlDescription += @"</p>"; _htmlDescription += @"</font>"; _htmlDescription += @"<hr />"; // Write out the instructions var _maneuverIndex = 1; foreach (var _maneuver in _route.response.route[0].leg[0].maneuver) { _htmlDescription += @"<p>"; _htmlDescription += $@"<b>{_maneuverIndex}.</b> {_maneuver.instruction} [{TimeSpan.FromSeconds(_maneuver.travelTime).TotalMinutes.ToString("F1")} min]<br />"; _htmlDescription += @"</p>"; _maneuverIndex++; } // Close all open html tags _htmlDescription += @"</font>"; _htmlDescription += @"</body>"; _htmlDescription += @"</html>"; return(_htmlDescription); }
private byte[] clientMapImage(RoutingResult.Rootobject _route, double _width, double _height, int _marker) { if (_route == null) { throw new ArgumentNullException(nameof(_route)); } if (!_route.IsValid) { throw new ArgumentException("_route -> not valid"); } if (_width <= 0) { throw new ArgumentOutOfRangeException(nameof(_width)); } if (_height <= 0) { throw new ArgumentOutOfRangeException(nameof(_height)); } //Scale the size to be not larger than max values var _maxImageWidth = 2048; var _maxImageHeight = 2048; if (_width > _maxImageWidth) { var _widthScale = _maxImageWidth / _width; _width *= _widthScale; _height *= _widthScale; } if (_height > _maxImageHeight) { var _heightScale = _maxImageHeight / _height; _width *= _heightScale; _height *= _heightScale; } var _client = new RestClient("https://image.maps.api.here.com/"); _client.UserAgent = "RISv" + Assembly.GetExecutingAssembly().GetName().Version; var _request = new RestRequest(Method.GET); _request.RequestFormat = DataFormat.Json; _request.Resource = @"/mia/1.6/route"; _request.AddParameter("app_id", here_AppId); _request.AddParameter("app_code", here_AppCode); _request.AddParameter("f", 0); //format: png _request.AddParameter("h", _height); //Image height _request.AddParameter("w", _width); //Image height _request.AddParameter("ml", "ger"); //language _request.AddParameter("t", "12"); //Map scheme type var _routeLine = _route.Line; //Set routing points and must limit to 8k var _routeLineIndex = 1; while (Encoding.ASCII.GetByteCount(string.Join(",", _routeLine)) > 6000 && _routeLineIndex < _routeLine.Count) { _routeLine.RemoveAt(_routeLineIndex); _routeLineIndex++; } _request.AddParameter("r", string.Join(",", _routeLine)); //line points _request.AddParameter("lc", "A70000"); //line color _request.AddParameter("lw", "10"); //line width _request.AddParameter("poix0", $"{_route.StartpointCoordinates};{"C00000FF"};{""};{"18"};{"Start"}"); //line width _request.AddParameter("poix1", $"{_route.StoppointCoordinates};{"C0A70000"};{""};{"18"};{"Einsatz"}"); //line width if (_route.Distance > 10000 && _route.Distance < 30000) { _request.AddParameter("z", _route.Distance > 20000 ? "14" : "15"); //zoom (0-20) _request.AddParameter("ctr", _route.StoppointCoordinates); //center point } var _response = _client.Execute(_request); if (_response.ErrorException != null) { Logger.WriteError(MethodBase.GetCurrentMethod(), "Error retrieving response: " + _response.ErrorMessage); return(null); } if (_response.RawBytes == null || _response.RawBytes.Length <= 500) { Logger.WriteError(MethodBase.GetCurrentMethod(), "Error retrieving response: No Data"); return(null); } return(_response.RawBytes); }