Put latitude and longitude in window hash (close #2)
This commit is contained in:
parent
d964623779
commit
90a0a17093
20
index.html
20
index.html
@ -221,6 +221,12 @@
|
||||
}
|
||||
});
|
||||
|
||||
// Check for coordinates in hash
|
||||
parseWindowHash();
|
||||
window.addEventListener('hashchange', function () {
|
||||
parseWindowHash();
|
||||
}, false);
|
||||
|
||||
$("body").on("click", ".copyonclick", function () {
|
||||
var copyitem = $(this);
|
||||
var copytext = copyitem.text();
|
||||
@ -276,6 +282,20 @@
|
||||
alert(e);
|
||||
}
|
||||
}
|
||||
|
||||
function parseWindowHash() {
|
||||
var hash = window.location.hash.substr(1);
|
||||
if (/^-?[0-9]{1,2}\.?[0-9]*,-?[0-9]{1,3}\.?[0-9]*$/.test(hash)) {
|
||||
var lat = hash.split(",")[0];
|
||||
var lon = hash.split(",")[1];
|
||||
lat = (Math.round(lat * 10000) / 10000);
|
||||
lon = (Math.round(lon * 10000) / 10000);
|
||||
lookupAndShowCoords(lat, lon);
|
||||
setTimeout(function () {
|
||||
window.location.hash = hash;
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
15
js/map.js
15
js/map.js
@ -100,6 +100,7 @@ function showLocationPopup(latitude, longitude, words, accuracy) {
|
||||
latitude + (accuracy / 2),
|
||||
longitude + (accuracy / 2)
|
||||
);
|
||||
window.location.hash = latitude + "," + longitude;
|
||||
}
|
||||
|
||||
function drawRectangle(fromlat, fromlng, tolat, tolng) {
|
||||
@ -143,4 +144,18 @@ function clearRectangle() {
|
||||
if (typeof map.getLayer("rectangle") != "undefined") {
|
||||
map.removeLayer('rectangle');
|
||||
}
|
||||
}
|
||||
|
||||
function lookupAndShowCoords(latitude, longitude) {
|
||||
var words = FixPhrase.encode(latitude, longitude);
|
||||
|
||||
map.flyTo({
|
||||
center: {
|
||||
lat: latitude,
|
||||
lng: longitude
|
||||
},
|
||||
zoom: Math.max(map.getZoom(), 14)
|
||||
});
|
||||
|
||||
showLocationPopup(latitude, longitude, words, 0.0001);
|
||||
}
|
@ -28,17 +28,7 @@ function maplibreMap() {
|
||||
try {
|
||||
var latitude = (Math.round(coordinates.lat * 10000) / 10000);
|
||||
var longitude = (Math.round(coordinates.lng * 10000) / 10000);
|
||||
var words = FixPhrase.encode(latitude, longitude);
|
||||
|
||||
map.flyTo({
|
||||
center: {
|
||||
lat: latitude,
|
||||
lng: longitude
|
||||
},
|
||||
zoom: Math.max(map.getZoom(), 14)
|
||||
});
|
||||
|
||||
showLocationPopup(latitude, longitude, words, 0.0001);
|
||||
lookupAndShowCoords(latitude, longitude);
|
||||
} catch (e) {
|
||||
alert(e);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user