diff --git a/FixPhrase.lib.php b/FixPhrase.lib.php
index 71724e4..f208c7d 100644
--- a/FixPhrase.lib.php
+++ b/FixPhrase.lib.php
@@ -7661,11 +7661,16 @@ class FixPhrase {
$lon = str_pad($lon, 7, "0", STR_PAD_LEFT);
// Split up coordinates into chunks, add offsets so no two words will be the same and order won't matter
+ $lat1dec = (int) substr($lat, 0, 4);
+ $lon1dec = (int) substr($lon, 0, 4);
+ $latlon2dec = (int) (substr($lat, 4, 2) . substr($lon, 4, 1));
+ $latlon4dec = (int) (substr($lat, 6, 1) . substr($lon, 5, 2));
+
$groups = [
- (int) substr($lat, 0, 4) + 0,
- ((int) substr($lon, 0, 4)) + 2000,
- ((int) substr($lat, 4, 3)) + 5610,
- ((int) substr($lon, 4, 3)) + 6610
+ $lat1dec + 0,
+ $lon1dec + 2000,
+ $latlon2dec + 5610,
+ $latlon4dec + 6610
];
return implode(" ", [self::WORDLIST[$groups[0]], self::WORDLIST[$groups[1]], self::WORDLIST[$groups[2]], self::WORDLIST[$groups[3]]]);
@@ -7707,18 +7712,43 @@ class FixPhrase {
$lat = str_pad((string) $indexes[0], 4, "0", STR_PAD_LEFT);
$lon = str_pad((string) $indexes[1], 4, "0", STR_PAD_LEFT);
- // Get the last three digits of each coordinate
+ // Get second decimal for latitude and longitude
+ if ($indexes[2] != -1) {
+ $divby = 100.0;
+ $latlon2dec = str_pad((string) $indexes[2], 3, "0", STR_PAD_LEFT);
+ $lat .= substr($latlon2dec, 0, 1);
+ $lon .= substr($latlon2dec, 2, 1);
+ }
+
+ // Get third and fourth latitude and fourth longitude
if ($indexes[2] != -1 && $indexes[3] != -1) {
$divby = 10000.0;
- $lat .= str_pad((string) $indexes[2], 3, "0", STR_PAD_LEFT);
- $lon .= str_pad((string) $indexes[3], 3, "0", STR_PAD_LEFT);
+ $latlon4dec = str_pad((string) $indexes[3], 3, "0", STR_PAD_LEFT);
+ $lat .= substr($latlon2dec, 1, 1) . substr($latlon4dec, 0, 1);
+ $lon .= substr($latlon4dec, 1, 2);
}
// Make them normal coordinates again with +/- and 0-90 or 0-180
$latitude = round((((int) $lat) / $divby) - 90.0, 4);
$longitude = round((((int) $lon) / $divby) - 180.0, 4);
- return [$latitude, $longitude];
+ switch ($divby) {
+ case 10.0:
+ $latitude += 0.05;
+ $longitude += 0.05;
+ $accuracy = 0.1;
+ break;
+ case 100.0:
+ $latitude += 0.005;
+ $longitude += 0.005;
+ $accuracy = 0.01;
+ break;
+ case 10000.0:
+ $accuracy = 0.0001;
+ break;
+ }
+
+ return [round($latitude, 4), round($longitude, 4), $accuracy];
}
}
diff --git a/index.html b/index.html
index 7dc03a2..9afd0aa 100644
--- a/index.html
+++ b/index.html
@@ -196,12 +196,30 @@
words = words.trim().toLowerCase().replace(/\s+/g, ' ');
var coords = FixPhrase.decode(words);
+ drawRectangle(
+ coords[0] - (coords[2] / 2),
+ coords[1] - (coords[2] / 2),
+ coords[0] + (coords[2] / 2),
+ coords[1] + (coords[2] / 2)
+ );
+
location.hash = "#map";
- new mapboxgl.Popup()
- .setLngLat({lat: coords[0], lng: coords[1]})
- .setHTML("" + words + "
" + coords[0] + ", " + coords[1])
- .addTo(map);
- map.animateMapIn(coords[0], coords[1], 18);
+ $('.mapboxgl-popup').remove();
+ var popup = new mapboxgl.Popup()
+ popup.on('close', clearRectangle);
+ popup.setLngLat({lat: coords[0], lng: coords[1]});
+ popup.setHTML("" + words + "
" + coords[0] + ", " + coords[1]);
+ popup.addTo(map);
+ var zoomlevel = 18;
+ switch (coords[2]) {
+ case 0.1:
+ zoomlevel = 10;
+ break;
+ case 0.01:
+ zoomlevel = 13;
+ break;
+ }
+ map.animateMapIn(coords[0], coords[1], zoomlevel);
} catch (e) {
alert(e);
}
@@ -214,11 +232,28 @@
}, function (resp) {
if (resp.status == "OK") {
location.hash = "#map";
- new mapboxgl.Popup()
- .setLngLat({lat: resp.coords[0], lng: resp.coords[1]})
- .setHTML("" + resp.words + "
" + resp.coords[0] + ", " + resp.coords[1])
- .addTo(map);
- map.animateMapIn(resp.coords[0], resp.coords[1], 18);
+ drawRectangle(
+ resp.coords[0] - (resp.coords[2] / 2),
+ resp.coords[1] - (resp.coords[2] / 2),
+ resp.coords[0] + (resp.coords[2] / 2),
+ resp.coords[1] + (resp.coords[2] / 2)
+ );
+ $('.mapboxgl-popup').remove();
+ var popup = new mapboxgl.Popup()
+ popup.on('close', clearRectangle);
+ popup.setLngLat({lat: resp.coords[0], lng: resp.coords[1]});
+ popup.setHTML("" + resp.words + "
" + resp.coords[0] + ", " + resp.coords[1]);
+ popup.addTo(map);
+ var zoomlevel = 18;
+ switch (resp.coords[2]) {
+ case 0.1:
+ zoomlevel = 10;
+ break;
+ case 0.01:
+ zoomlevel = 13;
+ break;
+ }
+ map.animateMapIn(resp.coords[0], resp.coords[1], zoomlevel);
} else {
alert(resp.msg);
}
diff --git a/index.html.php b/index.html.php
new file mode 100644
index 0000000..d84e5c2
--- /dev/null
+++ b/index.html.php
@@ -0,0 +1,180 @@
+
+
+