public void CreateDynamicMap(IEnumerable <MapAreaInputs> mapAreaInputs, MapInputs mapInputs, string fileName) { var borders = new List <GeoLocation[]>(); var minLat = double.MaxValue; var maxLat = double.MinValue; var minLon = double.MaxValue; var maxLon = double.MinValue; foreach (var mapAreaInput in mapAreaInputs) { var range = new RangeGrid(mapAreaInput.OriginName, mapAreaInput.RangeMins, mapAreaInput.UnitDistance); range.Process(); // set border mapAreaInput.Border = range.GetBorder(mapAreaInput.SmoothPct); if (range.Home.Latitude > maxLat) { maxLat = range.Home.Latitude; } if (range.Home.Latitude < minLat) { minLat = range.Home.Latitude; } if (range.Home.Longitude > maxLon) { maxLon = range.Home.Longitude; } if (range.Home.Longitude < minLon) { minLon = range.Home.Longitude; } } var center = new GeoLocation() { Latitude = (minLat + maxLat) / 2.0, Longitude = (minLon + maxLon) / 2.0 }; var filePath = Path.Combine(Default.RangerFolder, "Maps", fileName); // generate map GeometryApi.GenerateDynamicMap(mapAreaInputs, mapInputs, center, apiKey, filePath); }
/// <summary> /// Creates a dynamic Google map. /// </summary> public void CreateDynamicMap(MapAreaInputs mapAreaInput, MapInputs mapInputs) { // build a filename with origin name, range, grid size and smooth percentage var fileName = string.Format( "{0}-Rng{1}-Unt{2}-Pct{3}.html", mapAreaInput.OriginName.Replace(" ", ""), mapAreaInput.RangeMins.ToString("000"), mapAreaInput.UnitDistance, mapAreaInput.SmoothPct.ToString("000")); CreateDynamicMap(new List <MapAreaInputs>() { mapAreaInput }, mapInputs, fileName); }
static void Main(string[] args) { var ranger = new Ranger(); var mapAreaInputs = new MapAreaInputs() { OriginName = "Rome, Italy" }; var mapInputs = new MapInputs(); ranger.CreateDynamicMap(mapAreaInputs, mapInputs); var area = ranger.CalculateArea(mapAreaInputs); Console.WriteLine("Area = {0:0.00} sq km", area); Console.WriteLine("Done"); Console.ReadLine(); }
/// <summary> /// Generate dynamic map with a border determined by nodes. /// </summary> public static void GenerateDynamicMap(IEnumerable <MapAreaInputs> inputs, MapInputs mapInputs, IGeoLocation center, string apiKey, string filePath) { // create folder if it doesn't exist new FileInfo(filePath).Directory.Create(); var mapTemplate = File.ReadAllText(Path.Combine("HtmlTemplates", "DynamicMapTemplate.html")); var polygonTemplate = File.ReadAllText(Path.Combine("HtmlTemplates", "PolygonTemplate.html")); var html = new StringBuilder(mapTemplate); html.Replace("/*key*/", apiKey); html.Replace("/*center*/", $"{center.Latitude}, {center.Longitude}"); html.Replace("/*zoom*/", mapInputs.Zoom.ToString()); html.Replace("/*width*/", mapInputs.Width.ToString()); html.Replace("/*height*/", mapInputs.Height.ToString()); var polygons = new List <string>(); var num = 0; foreach (var input in inputs) { var polygon = new StringBuilder(polygonTemplate); var nodesStrings = GetNodesStrings(input.Border, 16); polygon.Replace("/*num*/", num.ToString()); polygon.Replace("/*color*/", $"\"{input.Color}\""); polygon.Replace("/*strokeOpacity*/", input.StrokeOpacity.ToString("0.00")); polygon.Replace("/*strokeWeight*/", input.StrokeWeight.ToString()); polygon.Replace("/*fillOpacity*/", input.FillOpacity.ToString("0.00")); polygon.Replace("/*nodes*/", string.Join($",{Environment.NewLine}", nodesStrings)); polygons.Add(polygon.ToString()); num++; } html.Replace("/*polygons*/", string.Join(Environment.NewLine, polygons)); File.WriteAllText(filePath, html.ToString()); }