mirror of https://github.com/espruino/BangleApps
nominatim course search
parent
fa448837b8
commit
4aa5de663b
|
@ -8,29 +8,26 @@
|
|||
</head>
|
||||
|
||||
<style>
|
||||
#searchresults ul {
|
||||
#searchresults {
|
||||
list-style-type: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
#searchresults ul li a {
|
||||
display: block;
|
||||
width: 100%;
|
||||
text-decoration: none;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
#searchresults ul li a:hover {
|
||||
#searchresults li:hover {
|
||||
background-color: #ccc;
|
||||
}
|
||||
</style>
|
||||
|
||||
<body>
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="input-example-1">Course Search</label>
|
||||
<input class="form-input" type="text" id="course_id" placeholder="Whistling Straits">
|
||||
<button type="button" class="btn btn-primary" onclick="courseSearch();">Search</button>
|
||||
</div>
|
||||
<div>
|
||||
<input type="text" placeholder="Whistling Straits" id="course_id">
|
||||
<button type="button" onclick="courseSearch();">Search</button>
|
||||
<ul id="searchresults"></ul>
|
||||
</div>
|
||||
<div>
|
||||
<p id="status">No course loaded.</p>
|
||||
<button id="upload" class="btn btn-primary" disabled="true">Upload to Device</button>
|
||||
|
@ -57,7 +54,6 @@
|
|||
<hr />
|
||||
<a href="https://www.openstreetmap.org/copyright">© OpenStreetMap contributors</p>
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
<script src="../../core/lib/customize.js"></script>
|
||||
<script src="./maptools.js"></script>
|
||||
|
@ -67,6 +63,7 @@
|
|||
const search_url = "https://nominatim.openstreetmap.org/search";
|
||||
let search_query = null;
|
||||
let course_input = null;
|
||||
let current_course = null;
|
||||
let search_results = $("#searchresults");
|
||||
|
||||
function courseSearch() {
|
||||
|
@ -76,9 +73,6 @@
|
|||
"q": inputVal,
|
||||
};
|
||||
doSearch();
|
||||
|
||||
// query = `[out:json][timeout:5];way(${inputVal});map_to_area ->.golfcourse;way["golf"="hole"](area.golfcourse)->.holes;(relation["golf"="fairway"](area.golfcourse);way["golf"~"^(green|tee|water_hazard|bunker|fairway)"](area.golfcourse);)->.features;.holes out geom;.features out geom;`;
|
||||
// doQuery();
|
||||
}
|
||||
|
||||
function processFeatures(course_verbose) {
|
||||
|
@ -150,7 +144,6 @@
|
|||
}
|
||||
|
||||
var courses = [];
|
||||
var course_name = "Davis";
|
||||
$("#upload").click(function () {
|
||||
sendCustomizedApp({
|
||||
storage: courses,
|
||||
|
@ -158,9 +151,13 @@
|
|||
});
|
||||
|
||||
$("#download").click(function () {
|
||||
downloadObjectAsJSON(courses[0].content, "golfcourse-" + course_name);
|
||||
downloadObjectAsJSON(courses[0].content, "golfcourse-download");
|
||||
});
|
||||
|
||||
function testfunc(params) {
|
||||
console.log(params);
|
||||
}
|
||||
|
||||
// download info from the course
|
||||
function doSearch() {
|
||||
$.get(search_url, search_query, function (result) {
|
||||
|
@ -173,25 +170,35 @@
|
|||
for (let index = 0; index < result.length; index++) {
|
||||
const element = result[index];
|
||||
if (element.type != "golf_course") continue;
|
||||
search_results.append($("<li>").append($("<a>").attr('href', 'google.com').text(element.display_name)));
|
||||
search_results.append($("<li>")
|
||||
.append($("<p>").text(element.display_name)
|
||||
.append($("<div>")
|
||||
.append($('<button>').addClass("btn btn-primary").text("select").on('click', function () {
|
||||
console.log(element);
|
||||
doQuery(element);
|
||||
}))
|
||||
.append($('<a>').attr('href', `https://www.openstreetmap.org/${element.osm_type}/${element.osm_id}`).attr('target', '_blank')
|
||||
.append('<button>').addClass("btn btn-primary").text("view")
|
||||
))));
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
// download info from the course
|
||||
function doQuery() {
|
||||
function doQuery(course) {
|
||||
const query = `[out:json][timeout:5];way(${course.osm_id});map_to_area ->.golfcourse;way["golf"="hole"](area.golfcourse)->.holes;(relation["golf"="fairway"](area.golfcourse);way["golf"~"^(green|tee|water_hazard|bunker|fairway)"](area.golfcourse);)->.features;.holes out geom;.features out geom;`;
|
||||
const course_name = course.display_name.split(",")[0];
|
||||
$.post(url, query, function (result) {
|
||||
if (result.elements.length === 0) {
|
||||
$('#status').text("Course not found!");
|
||||
return;
|
||||
}
|
||||
course_input = result;
|
||||
console.log(course_input);
|
||||
out = processFeatures(course_input.elements);
|
||||
console.log(result);
|
||||
out = processFeatures(result.elements);
|
||||
console.log(out);
|
||||
courses.push({
|
||||
name: "golfcourse-" + course_name + ".json",
|
||||
name: `golfcourse-${course_name}.json`,
|
||||
content: JSON.stringify(out),
|
||||
});
|
||||
$('#status').text("Course retrieved!");
|
||||
|
|
Loading…
Reference in New Issue