|
|
|
@ -106,4 +106,102 @@ function changeText(id, checkedValue, uncheckedValue, object) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function requestUserLocation(yourLocationText, unableToDetermineText) {
|
|
|
|
|
if (navigator.geolocation) {
|
|
|
|
|
navigator.geolocation.getCurrentPosition(function(position) {
|
|
|
|
|
var latitude = position.coords.latitude;
|
|
|
|
|
var longitude = position.coords.longitude;
|
|
|
|
|
setLatLon(latitude, longitude);
|
|
|
|
|
$('#console').hide();
|
|
|
|
|
initializeMapForCustomer(latitude, longitude, yourLocationText);
|
|
|
|
|
}, function(error) {
|
|
|
|
|
$('#map').hide();
|
|
|
|
|
$('#console').text(unableToDetermineText).show();
|
|
|
|
|
switch(error.code) {
|
|
|
|
|
case error.PERMISSION_DENIED:
|
|
|
|
|
setLatLon('E-1','E-1');
|
|
|
|
|
break;
|
|
|
|
|
case error.POSITION_UNAVAILABLE:
|
|
|
|
|
setLatLon('E-2','E-2');
|
|
|
|
|
break;
|
|
|
|
|
case error.TIMEOUT:
|
|
|
|
|
setLatLon('E-3','E-3');
|
|
|
|
|
break;
|
|
|
|
|
case error.UNKNOWN_ERROR:
|
|
|
|
|
setLatLon('E-4','E-4');
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
$('#map').hide();
|
|
|
|
|
$('#console').text(unableToDetermineText).show();
|
|
|
|
|
setLatLon('E-5','E-5');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setLatLon(lat, lon) {
|
|
|
|
|
$('#latitude').val(lat);
|
|
|
|
|
$('#longitude').val(lon);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var marker;
|
|
|
|
|
var map;
|
|
|
|
|
function resetLatLon(lat, lon) {
|
|
|
|
|
map.setView([lat, lon], 15);
|
|
|
|
|
marker.setLatLng(L.latLng(lat, lon));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function closeAndReset(lat, lon) {
|
|
|
|
|
$('#save-group').hide();
|
|
|
|
|
$('#close-button').show();
|
|
|
|
|
$('#friendly-location').show();
|
|
|
|
|
$('#save-for-address').hide();
|
|
|
|
|
resetLatLon(lat, lon);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function initializeMapForCustomer(latitude, longitude, yourLocationText) {
|
|
|
|
|
map = L.map('map').setView([latitude, longitude], 15);
|
|
|
|
|
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
|
|
|
|
|
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
|
|
|
|
|
}).addTo(map);
|
|
|
|
|
marker = L.marker([latitude, longitude], {draggable: true})
|
|
|
|
|
.addTo(map)
|
|
|
|
|
.bindPopup(yourLocationText);
|
|
|
|
|
|
|
|
|
|
marker.on('dragend', function(event) {
|
|
|
|
|
setLatLon(event.target.getLatLng().lat, event.target.getLatLng().lng);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function initializeMapForStaff(latitude, longitude, usersLocationText) {
|
|
|
|
|
map = L.map('map').setView([latitude, longitude], 15);
|
|
|
|
|
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
|
|
|
|
|
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
|
|
|
|
|
}).addTo(map);
|
|
|
|
|
marker = L.marker([latitude, longitude], {draggable: true})
|
|
|
|
|
.addTo(map)
|
|
|
|
|
.bindPopup(usersLocationText);
|
|
|
|
|
|
|
|
|
|
marker.on('dragend', function(event) {
|
|
|
|
|
setLatLon(event.target.getLatLng().lat, event.target.getLatLng().lng);
|
|
|
|
|
$('#save-group').show();
|
|
|
|
|
$('#close-button').hide();
|
|
|
|
|
$('#friendly-location').hide();
|
|
|
|
|
$('#save-for-address').show();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#map-modal').on('shown.bs.modal', function(){
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
map.invalidateSize();
|
|
|
|
|
}, 10);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getFriendlyLocation(latitude, longitude) {
|
|
|
|
|
var URL = 'http://nominatim.openstreetmap.org/reverse?format=json&lat='+ latitude +'&lon='+ longitude +'&zoom=15&addressdetails=1';
|
|
|
|
|
$.getJSON(URL, function(data) {
|
|
|
|
|
$('#friendly-location').text(data.display_name);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
jQuery(document).ready(loadJquery);
|
|
|
|
|