| | | 1 | | using System.Collections.Generic; |
| | | 2 | | using Newtonsoft.Json.Linq; |
| | | 3 | | |
| | | 4 | | namespace Itinero.IO.Osm.Tiles.Parsers.Semantics; |
| | | 5 | | |
| | | 6 | | internal static class TagMapper |
| | | 7 | | { |
| | | 8 | | /// <summary> |
| | | 9 | | /// Reverse maps the given property using the given semantic mappings. |
| | | 10 | | /// </summary> |
| | | 11 | | /// <param name="property">The property to map.</param> |
| | | 12 | | /// <param name="reverseMappings">The reverse mappings.</param> |
| | | 13 | | /// <returns>True if there was a mapping for this tag.</returns> |
| | | 14 | | public static (string key, string value)? Map(this JProperty property, |
| | | 15 | | Dictionary<string, TagMapperConfig> reverseMappings) |
| | 0 | 16 | | { |
| | 0 | 17 | | if (!reverseMappings.TryGetValue(property.Name, out var mapperConfig)) |
| | 0 | 18 | | { |
| | 0 | 19 | | return null; |
| | | 20 | | } |
| | | 21 | | |
| | 0 | 22 | | if (property.Value == null) |
| | 0 | 23 | | { |
| | 0 | 24 | | return (mapperConfig.OsmKey, null); |
| | | 25 | | } |
| | | 26 | | |
| | 0 | 27 | | var valueString = property.Value.ToInvariantString(); |
| | 0 | 28 | | if (mapperConfig.ReverseMapping == null) |
| | 0 | 29 | | { |
| | 0 | 30 | | return (mapperConfig.OsmKey, valueString); |
| | | 31 | | } |
| | | 32 | | |
| | 0 | 33 | | if (mapperConfig.ReverseMapping.TryGetValue(valueString, out var reverseMapped)) |
| | 0 | 34 | | { |
| | 0 | 35 | | return (mapperConfig.OsmKey, reverseMapped); |
| | | 36 | | } |
| | | 37 | | |
| | 0 | 38 | | return null; |
| | 0 | 39 | | } |
| | | 40 | | } |