added better lat/lng display when dragging,
added experimental faster route redraw (commented out), changed default website url and routing url, removed drag after dragend event workaround
This commit is contained in:
parent
afbd3347da
commit
c5a8ec7c31
@ -90,15 +90,17 @@ onClick: function(e) {
|
|||||||
my_markers.highlight.hide();
|
my_markers.highlight.hide();
|
||||||
},
|
},
|
||||||
onDrag: function(e) {
|
onDrag: function(e) {
|
||||||
// console.log("[event] drag event");
|
// OSRM.debug.log("[event] drag event");
|
||||||
this.parent.setPosition( e.target.getLatLng() );
|
this.parent.setPosition( e.target.getLatLng() );
|
||||||
if(OSRM.dragging == true) // TODO: hack to deal with drag events after dragend event
|
if(OSRM.dragging == true) // TODO: hack to deal with drag events after dragend event
|
||||||
getRoute(OSRM.NO_DESCRIPTION);
|
getRoute(OSRM.NO_DESCRIPTION);
|
||||||
else
|
// else
|
||||||
getRoute(OSRM.FULL_DESCRIPTION);
|
// getRoute(OSRM.FULL_DESCRIPTION);
|
||||||
|
|
||||||
|
updateLocation( this.parent.label );
|
||||||
},
|
},
|
||||||
onDragStart: function(e) {
|
onDragStart: function(e) {
|
||||||
// console.log("[event] dragstart event");
|
// OSRM.debug.log("[event] dragstart event");
|
||||||
OSRM.dragging = true;
|
OSRM.dragging = true;
|
||||||
|
|
||||||
// hack to store id of dragged marker
|
// hack to store id of dragged marker
|
||||||
@ -112,16 +114,19 @@ onDragStart: function(e) {
|
|||||||
if (my_route.isShown()) {
|
if (my_route.isShown()) {
|
||||||
my_route.showOldRoute();
|
my_route.showOldRoute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateLocation( this.parent.label );
|
||||||
},
|
},
|
||||||
onDragEnd: function(e) {
|
onDragEnd: function(e) {
|
||||||
// console.log("[event] dragend event");
|
// OSRM.debug.log("[event] dragend event");
|
||||||
getRoute(OSRM.FULL_DESCRIPTION);
|
getRoute(OSRM.FULL_DESCRIPTION);
|
||||||
if (my_route.isShown()) {
|
if (my_route.isShown()) {
|
||||||
my_route.hideOldRoute();
|
my_route.hideOldRoute();
|
||||||
my_route.hideUnnamedRoute(); // provides better visuals
|
my_route.hideUnnamedRoute(); // provides better visuals
|
||||||
}
|
}
|
||||||
OSRM.dragging = false;
|
OSRM.dragging = false;
|
||||||
//positionsToInput();
|
|
||||||
|
updateLocation( this.parent.label );
|
||||||
},
|
},
|
||||||
toString: function() {
|
toString: function() {
|
||||||
return "OSRM.RouteMarker: \""+this.label+"\", "+this.position+")";
|
return "OSRM.RouteMarker: \""+this.label+"\", "+this.position+")";
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
// (has to be loaded directly after OSRM.base!)
|
// (has to be loaded directly after OSRM.base!)
|
||||||
|
|
||||||
OSRM.DEFAULTS = {
|
OSRM.DEFAULTS = {
|
||||||
//HOST_ROUTING_URL: 'http://router.project-osrm.org/viaroute',
|
HOST_ROUTING_URL: 'http://router.project-osrm.org/viaroute',
|
||||||
HOST_ROUTING_URL: 'http://141.3.85.1/viaroute',
|
|
||||||
HOST_SHORTENER_URL: 'http://map.project-osrm.org/shorten/',
|
HOST_SHORTENER_URL: 'http://map.project-osrm.org/shorten/',
|
||||||
WEBSITE_URL: 'http://map.project-osrm.org/new/',
|
WEBSITE_URL: 'http://map.project-osrm.org/',
|
||||||
JSONP_TIMEOUT: 2000,
|
JSONP_TIMEOUT: 2000,
|
||||||
ZOOM_LEVEL: 14,
|
ZOOM_LEVEL: 14,
|
||||||
ONLOAD_LATITUDE: 48.84,
|
ONLOAD_LATITUDE: 48.84,
|
||||||
ONLOAD_LONGITUDE: 10.10,
|
ONLOAD_LONGITUDE: 10.10,
|
||||||
ONLOAD_SOURCE: "Karlsruhe",
|
ONLOAD_SOURCE: "",
|
||||||
ONLOAD_TARGET: "Aalen",
|
ONLOAD_TARGET: "",
|
||||||
};
|
};
|
@ -6,22 +6,29 @@ OSRM.TARGET_MARKER_LABEL = "target";
|
|||||||
|
|
||||||
|
|
||||||
// update locations in input boxes
|
// update locations in input boxes
|
||||||
|
function updateLocation(marker_id) {
|
||||||
|
if (marker_id == OSRM.SOURCE_MARKER_LABEL) {
|
||||||
|
document.getElementById("input-source-name").value = my_markers.route[0].getPosition().lat.toFixed(6) + ", " + my_markers.route[0].getPosition().lng.toFixed(6);
|
||||||
|
} else if (marker_id == OSRM.TARGET_MARKER_LABEL) {
|
||||||
|
document.getElementById("input-target-name").value = my_markers.route[my_markers.route.length-1].getPosition().lat.toFixed(6) + ", " + my_markers.route[my_markers.route.length-1].getPosition().lng.toFixed(6);
|
||||||
|
}
|
||||||
|
}
|
||||||
function updateLocations() {
|
function updateLocations() {
|
||||||
if( my_markers.route[0] && my_markers.route[0].label == OSRM.SOURCE_MARKER_LABEL) {
|
if( my_markers.route[0] && my_markers.route[0].label == OSRM.SOURCE_MARKER_LABEL) {
|
||||||
document.getElementById("input-source-name").value = my_markers.route[0].getPosition().lat.toFixed(6) + ", " + my_markers.route[0].getPosition().lng.toFixed(6);
|
document.getElementById("input-source-name").value = my_markers.route[0].getPosition().lat.toFixed(6) + ", " + my_markers.route[0].getPosition().lng.toFixed(6);
|
||||||
callReverseGeocoder("source", my_markers.route[0].getPosition().lat, my_markers.route[0].getPosition().lng);
|
callReverseGeocoder("source", my_markers.route[0].getPosition().lat, my_markers.route[0].getPosition().lng);
|
||||||
OSRM.debug.log("[call1] reverse geocoder");
|
//OSRM.debug.log("[call1] reverse geocoder");
|
||||||
}
|
}
|
||||||
|
|
||||||
// if( my_markers.route[my_markers.route.length-1] && my_markers.route[ my_markers.route.length-1 ].label == OSRM.TARGET_MARKER_LABEL) {
|
if( my_markers.route[my_markers.route.length-1] && my_markers.route[ my_markers.route.length-1 ].label == OSRM.TARGET_MARKER_LABEL) {
|
||||||
// document.getElementById("input-target-name").value = my_markers.route[my_markers.route.length-1].getPosition().lat.toFixed(6) + ", " + my_markers.route[my_markers.route.length-1].getPosition().lng.toFixed(6);
|
document.getElementById("input-target-name").value = my_markers.route[my_markers.route.length-1].getPosition().lat.toFixed(6) + ", " + my_markers.route[my_markers.route.length-1].getPosition().lng.toFixed(6);
|
||||||
// callReverseGeocoder("target", my_markers.route[my_markers.route.length-1].getPosition().lat, my_markers.route[my_markers.route.length-1].getPosition().lng);
|
callReverseGeocoder("target", my_markers.route[my_markers.route.length-1].getPosition().lat, my_markers.route[my_markers.route.length-1].getPosition().lng);
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function timeout_ReverseGeocoder() {
|
function timeout_ReverseGeocoder() {
|
||||||
OSRM.debug.log("[timeout] reverse geocoder");
|
//OSRM.debug.log("[timeout] reverse geocoder");
|
||||||
}
|
}
|
||||||
|
|
||||||
//prepare request and call reverse geocoder
|
//prepare request and call reverse geocoder
|
||||||
@ -30,7 +37,7 @@ function callReverseGeocoder(marker_id, lat, lon) {
|
|||||||
if (marker_id == OSRM.SOURCE_MARKER_LABEL) {
|
if (marker_id == OSRM.SOURCE_MARKER_LABEL) {
|
||||||
var src= OSRM.REVERSE_GEOCODE_POST + "&lat=" + lat + "&lon=" + lon;
|
var src= OSRM.REVERSE_GEOCODE_POST + "&lat=" + lat + "&lon=" + lon;
|
||||||
OSRM.JSONP.call( src, showReverseGeocoderResults_Source, timeout_ReverseGeocoder, OSRM.JSONP.TIMEOUT, "reverse_geocoder_source" );
|
OSRM.JSONP.call( src, showReverseGeocoderResults_Source, timeout_ReverseGeocoder, OSRM.JSONP.TIMEOUT, "reverse_geocoder_source" );
|
||||||
OSRM.debug.log("[call2] reverse geocoder");
|
//OSRM.debug.log("[call2] reverse geocoder");
|
||||||
} else if (marker_id == OSRM.TARGET_MARKER_LABEL) {
|
} else if (marker_id == OSRM.TARGET_MARKER_LABEL) {
|
||||||
var src = OSRM.REVERSE_GEOCODE_POST + "&lat=" + lat + "&lon=" + lon;
|
var src = OSRM.REVERSE_GEOCODE_POST + "&lat=" + lat + "&lon=" + lon;
|
||||||
OSRM.JSONP.call( src, showReverseGeocoderResults_Target, timeout_ReverseGeocoder, OSRM.JSONP.TIMEOUT, "reverse_geocoder_target" );
|
OSRM.JSONP.call( src, showReverseGeocoderResults_Target, timeout_ReverseGeocoder, OSRM.JSONP.TIMEOUT, "reverse_geocoder_target" );
|
||||||
@ -41,7 +48,7 @@ function callReverseGeocoder(marker_id, lat, lon) {
|
|||||||
function showReverseGeocoderResults_Source(response) { showReverseGeocoderResults(OSRM.SOURCE_MARKER_LABEL, response); }
|
function showReverseGeocoderResults_Source(response) { showReverseGeocoderResults(OSRM.SOURCE_MARKER_LABEL, response); }
|
||||||
function showReverseGeocoderResults_Target(response) { showReverseGeocoderResults(OSRM.TARGET_MARKER_LABEL, response); }
|
function showReverseGeocoderResults_Target(response) { showReverseGeocoderResults(OSRM.TARGET_MARKER_LABEL, response); }
|
||||||
function showReverseGeocoderResults(marker_id, response) {
|
function showReverseGeocoderResults(marker_id, response) {
|
||||||
OSRM.debug.log("[inner] reverse geocoder");
|
//OSRM.debug.log("[inner] reverse geocoder");
|
||||||
if(response){
|
if(response){
|
||||||
if(response.address == undefined)
|
if(response.address == undefined)
|
||||||
return;
|
return;
|
||||||
|
@ -56,8 +56,10 @@ function showRouteSimple(response) {
|
|||||||
if(!response)
|
if(!response)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (OSRM.JSONP.fences.route)
|
if (OSRM.JSONP.fences.route) { // is this still needed?
|
||||||
|
OSRM.debug.log("fenced");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if( response.status == 207) {
|
if( response.status == 207) {
|
||||||
showNoRouteGeometry();
|
showNoRouteGeometry();
|
||||||
@ -68,6 +70,11 @@ function showRouteSimple(response) {
|
|||||||
showRouteDescriptionSimple(response);
|
showRouteDescriptionSimple(response);
|
||||||
}
|
}
|
||||||
updateHints(response);
|
updateHints(response);
|
||||||
|
|
||||||
|
// if(OSRM.pending) {
|
||||||
|
// clearTimeout(OSRM.pendingTimer);
|
||||||
|
// OSRM.pendingTimer = setTimeout(timeoutDrag,100); // dirty dirty!
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
function showRoute(response) {
|
function showRoute(response) {
|
||||||
if(!response)
|
if(!response)
|
||||||
@ -298,11 +305,18 @@ function getRoute(do_description) {
|
|||||||
else {
|
else {
|
||||||
clearTimeout(OSRM.pendingTimer);
|
clearTimeout(OSRM.pendingTimer);
|
||||||
}
|
}
|
||||||
|
// if(called == false && !do_description) {
|
||||||
|
// OSRM.pending = true;
|
||||||
|
// } else {
|
||||||
|
// clearTimeout(OSRM.pendingTimer);
|
||||||
|
// OSRM.pending = false;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
function timeoutDrag() {
|
function timeoutDrag() {
|
||||||
my_markers.route[OSRM.dragid].hint = undefined;
|
my_markers.route[OSRM.dragid].hint = undefined;
|
||||||
getRoute(OSRM.NO_DESCRIPTION);
|
getRoute(OSRM.NO_DESCRIPTION);
|
||||||
|
// OSRM.debug.log("timer");
|
||||||
}
|
}
|
||||||
|
|
||||||
function startRouting() {
|
function startRouting() {
|
||||||
@ -334,7 +348,10 @@ function snapRoute() {
|
|||||||
my_markers.route[0].setPosition( positions[0] );
|
my_markers.route[0].setPosition( positions[0] );
|
||||||
my_markers.route[my_markers.route.length-1].setPosition( positions[positions.length-1] );
|
my_markers.route[my_markers.route.length-1].setPosition( positions[positions.length-1] );
|
||||||
for(var i=0; i<via_points.length; i++)
|
for(var i=0; i<via_points.length; i++)
|
||||||
my_markers.route[i+1].setPosition( new L.LatLng(via_points[i][0], via_points[i][1]) );
|
my_markers.route[i+1].setPosition( new L.LatLng(via_points[i][0], via_points[i][1]) );
|
||||||
|
|
||||||
|
updateLocation( "source" );
|
||||||
|
updateLocation( "target" );
|
||||||
}
|
}
|
||||||
|
|
||||||
function positionsToInput() {
|
function positionsToInput() {
|
||||||
|
Loading…
Reference in New Issue
Block a user