Skip to content

Commit

Permalink
entering GraphHopper API key improved
Browse files Browse the repository at this point in the history
  • Loading branch information
quaso committed Feb 21, 2016
1 parent e874038 commit 9457e30
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
27 changes: 16 additions & 11 deletions MazdaRoutesEditor/src/main/resources/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@
$('#cleanNewRoute').on('click', cleanNewRoute);
$('#addNewRoute').on('click', addNewRoute);
$('#saveToFile').on('click', saveToFile);
$('#setAPIKey').on('click', setAPIKey);
$('#createSettings').click(function(e) {
createSettings();
e.preventDefault();
});
});

function createMap() {
Expand Down Expand Up @@ -479,22 +484,22 @@
});
}
}

$('#createSettings').click(function(e) {
createSettings();
e.preventDefault();
});

function setAPIKey(){
GraphHopper.getInstance().apiKey = window.prompt(
"Enter GraphHopper API key or obtain one at https://graphhopper.com/", GraphHopper.getInstance().apiKey || "");
if (GraphHopper.getInstance().apiKey != null) {
$('#graphhopperAPILabel').html("GraphHopper API key set");
$('#graphhopperAPILabel').removeClass("alert-danger");
$('#graphhopperAPILabel').addClass("alert-success");
}
}

function createSettings() {
if (GraphHopper.getInstance().apiKey == null) {
GraphHopper.getInstance().apiKey = window.prompt(
"Enter GraphHopper API key or obtain one at https://graphhopper.com/", "");
setAPIKey();
if (GraphHopper.getInstance().apiKey == null) {
return;
} else {
$('#graphhopperAPILabel').html("GraphHopper API key set");
$('#graphhopperAPILabel').removeClass("alert-danger");
$('#graphhopperAPILabel').addClass("alert-success");
}
}

Expand Down
17 changes: 16 additions & 1 deletion MazdaRoutesEditor/src/main/resources/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<li><a href="#" id="show-all-routes">Show all routes</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="https://graphhopper.com/" target="_blank"><div
<li><a href="#" id="setAPIKey"><div
id="graphhopperAPILabel" class="alert-danger" role="alert">GraphHopper
API key not set!</div></a></li>
<li><a href="#" id="createSettings">Create settings.js</a></li>
Expand Down Expand Up @@ -88,5 +88,20 @@
<script type="text/javascript" src="js/jquery.fileDownload.js"></script>
<script type="text/javascript" src="js/FileSaver.js"></script>
<script type="text/javascript" src="js/main.js"></script>
<script>
(function(i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function() {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o), m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');

ga('create', 'UA-74113626-1', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>

0 comments on commit 9457e30

Please sign in to comment.