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 c2a58b1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
29 changes: 17 additions & 12 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 All @@ -511,7 +516,7 @@
var SETTINGS = {
locale : GraphHopper.getInstance().locale, destinations : [], credentials : {
graphHopper : GraphHopper.getInstance().apiKey
}, exportURI : exportURI
}, exportURI : exportURI, exportEmail: "some@address"
};

for (i = 0; i < destinationsData.length; i++) {
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>
2 changes: 1 addition & 1 deletion src/system/js/routesCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ var RoutesCache = (function() {
if (errorDetected != null) {
alert(errorDetected.status + ": " + errorDetected.statusText);
} else {
var reqUrl = SETTINGS.exportURI + "/sendEmail?address=" + "some@address";
var reqUrl = SETTINGS.exportURI + "/sendEmail?address=" + SETTINGS.exportEmail;
$.ajax({
url : reqUrl, dataType : "json"
}).done(function(data) {
Expand Down
1 change: 1 addition & 0 deletions src/system/js/settings.js.example
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ var SETTINGS = {
// whether to use local titles or OSM online titles
mapOnline:false
exportURI: "http://localhost:8080",
exportEmail: "some@address"
};

0 comments on commit c2a58b1

Please sign in to comment.