From a5ebab5bc9340d88e2b28f527421e2febd633b40 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Wed, 23 Sep 2015 09:14:23 +0900 Subject: [PATCH] Show and center restaurant when review link is clicked --- static/index.html | 2 +- static/scripts/search.js | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/static/index.html b/static/index.html index 9511602..4c1b189 100644 --- a/static/index.html +++ b/static/index.html @@ -145,7 +145,7 @@ {{#each records}} - {{name}} + {{name}} {{#prettyFloat 2}}{{distanceToUser}}{{/prettyFloat}} km {{closestStn}} {{#prettyFloat 2}}{{distanceToStn}}{{/prettyFloat}} km diff --git a/static/scripts/search.js b/static/scripts/search.js index b1f8483..e8c58d5 100644 --- a/static/scripts/search.js +++ b/static/scripts/search.js @@ -57,11 +57,7 @@ $('iframe').attr('src', $('iframe').attr('src')); } }); - $('.nav-tabs a').on('shown.bs.tab', function(e) { - if ($(e.target).attr('href') !== '#mapTab' || _ctx.map !== null) { - return; - } - + $('.nav-tabs a[href="#mapTab"]').one('shown.bs.tab', function(e) { var options = { center: { lat: 35.6833, lng: 139.7667 }, zoom: 8 }; @@ -79,8 +75,23 @@ } }); - window.accessReview = function(id) { + window.accessReview = function(id, latitude, longitude) { + $('.nav-tabs a[href="#mapTab"]').tab('show'); + + var setter = function(e) { + _ctx.map.setCenter({lat: latitude, lng: longitude}); + _ctx.map.setZoom(18); + }; + + if (_ctx.map === null) { + $('.nav-tabs a[href="#mapTab"]').one('shown.bs.tab', setter); + } + else { + setter(); + } + $.post('/access', JSON.stringify({id: id, profile: getProfile()})); + onSearch(); };