mirror of https://github.com/espruino/BangleApps
prototype course search
parent
0eb1c5fe0c
commit
fa448837b8
|
@ -7,30 +7,56 @@
|
||||||
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
|
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
#searchresults ul {
|
||||||
|
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 {
|
||||||
|
background-color: #ccc;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div>
|
<div>
|
||||||
<input type="text" placeholder="Course ID" id="course_id">
|
<input type="text" placeholder="Whistling Straits" id="course_id">
|
||||||
<button type="button" onclick="courseSearch();">Search</button>
|
<button type="button" onclick="courseSearch();">Search</button>
|
||||||
<p id="status"></p>
|
<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>
|
<button id="upload" class="btn btn-primary" disabled="true">Upload to Device</button>
|
||||||
<button id="download" class="btn btn-primary" disabled="true">Download Course</button>
|
<button id="download" class="btn btn-primary" disabled="true">Download Course</button>
|
||||||
</div>
|
</div>
|
||||||
<p>A course needs a few things to be parsed correctly by this tool.</p>
|
<div>
|
||||||
<ul>
|
<p>A course needs a few things to be parsed correctly by this tool.</p>
|
||||||
<li>See official mapping guidelines <a
|
<ul>
|
||||||
href="https://wiki.openstreetmap.org/wiki/Tag:leisure%3Dgolf_course">here</a>.</li>
|
<li>See official mapping guidelines <a
|
||||||
<li>All holes and features must be within the target course's area.</li>
|
href="https://wiki.openstreetmap.org/wiki/Tag:leisure%3Dgolf_course">here</a>.</li>
|
||||||
<li>Supported features are greens, fairways, tees, bunkers, water hazards and holes.</li>
|
<li>All holes and features must be within the target course's area.</li>
|
||||||
<li>All features for a given hole should have the "ref" tag with the hole number as value. Shared features should
|
<li>Supported features are greens, fairways, tees, bunkers, water hazards and holes.</li>
|
||||||
list ref values separated by ';'. <a href="https://www.openstreetmap.org/way/36896320">example</a>.</li>
|
<li>All features for a given hole should have the "ref" tag with the hole number as value. Shared features
|
||||||
<li>There must be 18 holes and they must have the following tags: handicap, par, ref, dist</li>
|
should
|
||||||
<li>For any mapping assistance or issues, please file in the <a
|
list ref values separated by ';'. <a href="https://www.openstreetmap.org/way/36896320">example</a>.</li>
|
||||||
href="https://github.com/espruino/BangleApps/issues/new?assignees=&labels=bug&template=bangle-bug-report-custom-form.yaml&title=[golfview]+Short+description+of+bug">official
|
<li>There must be 18 holes and they must have the following tags: handicap, par, ref, dist</li>
|
||||||
repo</a></li>
|
<li>For any mapping assistance or issues, please file in the <a
|
||||||
</ul>
|
href="https://github.com/espruino/BangleApps/issues/new?assignees=&labels=bug&template=bangle-bug-report-custom-form.yaml&title=[golfview]+Short+description+of+bug">official
|
||||||
<a href="https://www.openstreetmap.org/way/25447898">Example Course</a>
|
repo</a></li>
|
||||||
<a href="https://www.openstreetmap.org/copyright">© OpenStreetMap contributors</p>
|
</ul>
|
||||||
|
<a href="https://www.openstreetmap.org/way/25447898">Example Course</a>
|
||||||
|
</div>
|
||||||
|
<footer>
|
||||||
|
<hr />
|
||||||
|
<a href="https://www.openstreetmap.org/copyright">© OpenStreetMap contributors</p>
|
||||||
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="../../core/lib/customize.js"></script>
|
<script src="../../core/lib/customize.js"></script>
|
||||||
|
@ -38,13 +64,21 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const url = "https://overpass-api.de/api/interpreter";
|
const url = "https://overpass-api.de/api/interpreter";
|
||||||
let query = `[out:json][timeout:5];way(25447898);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 search_url = "https://nominatim.openstreetmap.org/search";
|
||||||
|
let search_query = null;
|
||||||
let course_input = null;
|
let course_input = null;
|
||||||
|
let search_results = $("#searchresults");
|
||||||
|
|
||||||
function courseSearch() {
|
function courseSearch() {
|
||||||
let inputVal = document.getElementById("course_id").value;
|
let inputVal = document.getElementById("course_id").value;
|
||||||
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;`;
|
search_query = {
|
||||||
doQuery();
|
"format": "jsonv2",
|
||||||
|
"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) {
|
function processFeatures(course_verbose) {
|
||||||
|
@ -127,6 +161,24 @@
|
||||||
downloadObjectAsJSON(courses[0].content, "golfcourse-" + course_name);
|
downloadObjectAsJSON(courses[0].content, "golfcourse-" + course_name);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// download info from the course
|
||||||
|
function doSearch() {
|
||||||
|
$.get(search_url, search_query, function (result) {
|
||||||
|
if (result.length === 0) {
|
||||||
|
$('#status').text("Course not found!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
search_results.empty();
|
||||||
|
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)));
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// download info from the course
|
// download info from the course
|
||||||
function doQuery() {
|
function doQuery() {
|
||||||
$.post(url, query, function (result) {
|
$.post(url, query, function (result) {
|
||||||
|
|
Loading…
Reference in New Issue