Skip to content

Commit b5e771d

Browse files
author
Peter
committed
if only one location is specified zoom in
1 parent 32e6583 commit b5e771d

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

web/src/main/webapp/js/ghrequest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,5 @@ GHInput.prototype.setCoord = function(lat, lng) {
113113
GHInput.prototype.toString = function() {
114114
if (this.lat && this.lng)
115115
return this.lat + "," + this.lng;
116-
return null;
116+
return undefined;
117117
};

web/src/main/webapp/js/main.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,13 @@ function createCallback(errorFallback) {
351351
};
352352
}
353353

354+
function focus(coord) {
355+
if(coord.lat && coord.lng) {
356+
routingLayer.clearLayers();
357+
map.setView(new L.LatLng(coord.lat, coord.lng), 11);
358+
setFlag(coord, true);
359+
}
360+
}
354361
function routeLatLng(request) {
355362
clickToRoute = true;
356363
$("#info").empty();
@@ -560,23 +567,28 @@ function initForm() {
560567
});
561568

562569
// if FROM will be submitted
563-
$('#fromInput').keyup(function(e) {
564-
if(e.which == 10 || e.which == 13) {
570+
$('#fromInput').keypress(function(e) {
571+
if(e.which == 13) {
572+
var from = $("#fromInput").val()
565573
var to = $("#toInput").val();
566574
// do not resolve 'to'
567575
if(to == "To") {
568-
resolveTo();
576+
if(from != ghRequest.from.input)
577+
ghRequest.from = new GHInput(from);
578+
$.when(resolveFrom()).done(function() {
579+
focus(ghRequest.from);
580+
});
569581
} else
570-
resolveCoords($("#fromInput").val(), to);
582+
resolveCoords(from, to);
571583
}
572584
});
573585

574586
// if TO will be submitted
575-
$('#toInput').keyup(function(e) {
576-
if(e.which == 10 || e.which == 13) {
587+
$('#toInput').keypress(function(e) {
588+
if(e.which == 13) {
577589
var from = $("#fromInput").val();
578590
if(from == "From") {
579-
resolveFrom();
591+
// resolveFrom();
580592
} else
581593
resolveCoords(from, $("#toInput").val());
582594
}

0 commit comments

Comments
 (0)