| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="GoogleMapsHelper.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | using System.Collections.Generic; |
| | | 9 | | using System.Linq; |
| | | 10 | | using MyNet.Primitives.Helpers; |
| | | 11 | | |
| | | 12 | | namespace MyNet.Google.Maps; |
| | | 13 | | |
| | | 14 | | public static class GoogleMapsHelper |
| | | 15 | | { |
| | | 16 | | public const string Url = "https://maps.google.com/maps"; |
| | | 17 | | |
| | 0 | 18 | | public static void OpenGoogleMaps(GoogleMapsSettings settings) => ProcessHelper.Start(GetGoogleMapsUrl(settings)); |
| | | 19 | | |
| | | 20 | | public static string GetGoogleMapsUrl(GoogleMapsSettings settings) |
| | | 21 | | { |
| | 12 | 22 | | var url = Url; |
| | 12 | 23 | | var parameters = settings.ToDictionary(); |
| | 12 | 24 | | if (parameters.Count != 0) |
| | | 25 | | { |
| | 9 | 26 | | url += $"?{string.Join("&", settings.ToDictionary().Select(x => $"{x.Key}={x.Value}"))}"; |
| | | 27 | | } |
| | | 28 | | |
| | 12 | 29 | | return url; |
| | | 30 | | } |
| | | 31 | | |
| | | 32 | | private static Dictionary<string, string> ToDictionary(this GoogleMapsSettings settings) |
| | | 33 | | { |
| | 21 | 34 | | var result = new Dictionary<string, string>(); |
| | | 35 | | |
| | 21 | 36 | | if (settings.HideLeftPanel) |
| | | 37 | | { |
| | 6 | 38 | | result.Add("output", "embed"); |
| | | 39 | | } |
| | | 40 | | |
| | 21 | 41 | | if (!string.IsNullOrEmpty(settings.Address)) |
| | | 42 | | { |
| | 12 | 43 | | result.Add("q", settings.Address.Replace(" ", "+", StringComparison.OrdinalIgnoreCase)); |
| | | 44 | | } |
| | | 45 | | |
| | 21 | 46 | | if (settings.Coordinates is not null) |
| | | 47 | | { |
| | 6 | 48 | | result.Add("ll", $"{settings.Coordinates.Latitude},{settings.Coordinates.Longitude}"); |
| | | 49 | | } |
| | | 50 | | |
| | 21 | 51 | | return result; |
| | | 52 | | } |
| | | 53 | | } |
| | | 54 | | |