diff --git a/spatial-coordinate-systems/src/urls.rs b/spatial-coordinate-systems/src/urls.rs index d45c4ac..19d49e2 100644 --- a/spatial-coordinate-systems/src/urls.rs +++ b/spatial-coordinate-systems/src/urls.rs @@ -17,13 +17,29 @@ impl CoordinateUrls { pub fn parse(i: &str) -> Result { let url = Url::parse(i.trim())?; - // Try to parse a url from google maps - url.query_pairs() - .find_map(|(key, value)| { - if key != "query" { - return None; - } + let pairs = url.query_pairs(); + let mut possible_latlon = vec![]; + for (key, value) in pairs { + if key == "query" { + possible_latlon.push(value.to_string()); + } + } + + if let Some(fragment) = url.fragment() { + if let Some(("map", v)) = fragment.split_once("=") { + if let Some((_, lat_slash_lon)) = v.split_once("/") { + if let Some((lat, lon)) = lat_slash_lon.split_once("/") { + possible_latlon.push(format!("{lat},{lon}")); + } + } + } + } + + // Try to parse a url from google maps + possible_latlon + .iter() + .find_map(|value| { LatLon::parse_full(value.as_ref()) .map(|(_, ret)| ret) .ok() @@ -31,6 +47,29 @@ impl CoordinateUrls { }) .ok_or_else(|| Error::NoUrlLatLon(i.to_string()))? } + + // fn parse_openstreetmap(i: Url) ->IResult<(), LatLon> { + // map_res(tuple(( + // tag("map="), + // digit1, + // tag("/"), + // parse_f64 , + // tag("/"), + // parse_f64 , + // eof + // )), |( + // _, + // _, + // _, + // lat , + // _, + // lon , + // _, + // )| { + // LatLon::new(lat,lon) + + // })(i.fragment().ok_or((Err(())))) + // } } impl From<&CoordinateUrls> for LatLon { diff --git a/web-frontend/src/routes/app/CoordinateInfo.svelte b/web-frontend/src/routes/app/CoordinateInfo.svelte index c8052a6..e862185 100644 --- a/web-frontend/src/routes/app/CoordinateInfo.svelte +++ b/web-frontend/src/routes/app/CoordinateInfo.svelte @@ -19,14 +19,6 @@ - {#each formats as format} - - {format.toUpperCase()} - {xpin.allCoordinates[format]} - - - {/each} - {#each urlFormats as format} {format.toUpperCase()} @@ -38,4 +30,12 @@ {/each} + + {#each formats as format} + + {format.toUpperCase()} + {xpin.allCoordinates[format]} + + + {/each}