diff --git a/apps/golfview/ChangeLog b/apps/golfview/ChangeLog new file mode 100644 index 000000000..b243db101 --- /dev/null +++ b/apps/golfview/ChangeLog @@ -0,0 +1 @@ +0.01: New App! Very limited course support. diff --git a/apps/golfview/README.md b/apps/golfview/README.md new file mode 100644 index 000000000..56d90782d --- /dev/null +++ b/apps/golfview/README.md @@ -0,0 +1,21 @@ +# App Name + +Describe the app... + +Add screen shots (if possible) to the app folder and link then into this file with ![](.png) + +## Usage + +Select your course of interest upon loading this app. + +## Contributions + +The performance of this app depends on the accuracy and consistency of user-submitted maps. Please contribute to Open Street Map using these guidelines and provide input in ways to support this application. + +## Controls + +Swipe to change holes and tap to see a green closeup. + +## Requests/Creator + +[Jason Dekarske](https://github.com/jdekarske) \ No newline at end of file diff --git a/apps/golfview/golfview-icon.js b/apps/golfview/golfview-icon.js new file mode 100644 index 000000000..83b180e4c --- /dev/null +++ b/apps/golfview/golfview-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("AAkCpMkyQCBwANGggLCAQYOOpAONpMgBwgLFHxAOJyVABwt/8QRGBwsv/mREAwOEkv/K4IOFyBZE3/ypMiHwwODy/+AYOJPowFD//Jkh9HAodf/IsGAQMSAoVL/4FD7dtBwWCCgd/6QOE2wjGl/6AoVbBwJDBBwh6BGQYOB7ZBG3/pAoUtBwNkBwuX/ojDBwNsZw3/0gFCBwJcDPQn0AoYOB2QOFpf+AoZcCNYx6ELgRrGAQoOB7IONPQUJBxB6CAoNBBxB6CRINIBYdJlIOIggODkiJFU4UABwmSAoWWU4cAfwQOCpSJDBwcCBAOJHQRNDBwUggAIByIKCJoYCCBwJ6CLAYOHgIFBogKCLgYCCgEAAoNIA4WUBw56CkRrFAQWAB4J6FqQOEyAOBPQRrCPQYCCBwJ6CNYYOFoAPBAoQOIpAOBPQRcCRIwOBPQRcCTBB6CFIoOGeoYCIBwJ6DARCJCNYQOIRIRrDARAOCLgckydtAQaJDLgttcwICCRIRNFpu0AQYOEJpQODVQYOLTZKYCHw4OKHw4NFAAS8ELIgABA==")) diff --git a/apps/golfview/golfview.js b/apps/golfview/golfview.js new file mode 100644 index 000000000..93d70e31c --- /dev/null +++ b/apps/golfview/golfview.js @@ -0,0 +1,51 @@ +let course = require("Storage").readJSON("course_data_hole1.json"); + +console.log(Object.keys(course)); + +g.clear(); + +for (var feature of course.features) { + //console.log(Object.keys(feature)); + if (feature.type === "fairway"){ + g.setColor(0,0,1); + } else if ( feature.type === "tee"){ + g.setColor(1,0,0); + } else if (feature.type === "green"){ + g.setColor(0,1,0); + } else if (feature.type === "bunker"){ + g.setColor(1,1,0); + } else { + continue; + } + + var nodelist = []; + feature.nodesXY.forEach(function (node) { + nodelist.push(node.x); + nodelist.push(node.y); + }); + newnodelist = g.transformVertices(nodelist,{ + x: 150, // x offset (default 0) + y: 150, // y offset (default 0) + scale: 0.45, // scale factor (default 1) + rotate: course.angle - 1.57, // angle in radians (default 0) + }); + + g.fillPoly(newnodelist, true); + console.log(feature.type); + console.log(nodelist); +} + +var nodelist = []; +course.nodesXY.forEach(function (node) { + nodelist.push(node.x); + nodelist.push(node.y); +}); + +newnodelist = g.transformVertices(nodelist,{ + x: 150, // x offset (default 0) + y: 150, // y offset (default 0) + scale: 0.45, // scale factor (default 1) + rotate: course.angle - 1.57, // angle in radians (default 0) +}); +g.setColor(0,1,1); +g.drawPoly(newnodelist); \ No newline at end of file diff --git a/apps/golfview/golfview.png b/apps/golfview/golfview.png new file mode 100644 index 000000000..2bb616282 Binary files /dev/null and b/apps/golfview/golfview.png differ diff --git a/apps/golfview/index.html b/apps/golfview/index.html new file mode 100644 index 000000000..24016ccbd --- /dev/null +++ b/apps/golfview/index.html @@ -0,0 +1,114 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/apps/golfview/maptools.js b/apps/golfview/maptools.js new file mode 100644 index 000000000..af05343c8 --- /dev/null +++ b/apps/golfview/maptools.js @@ -0,0 +1,59 @@ +const EARTHRADIUS = 6371000; //km + +function radians(a) { + return a * Math.PI / 180; +} + +function degrees(a) { + let d = a * 180 / Math.PI; + return (d + 360) % 360; +} + +function toXY(a, origin) { + let pt = { + x: 0, + y: 0 + }; + + pt.x = EARTHRADIUS * radians(a.lon - origin.lon) * Math.cos(radians((a.lat + origin.lat) / 2)); + pt.y = EARTHRADIUS * radians(origin.lat - a.lat); + return pt; +} + +function arraytoXY(array, origin) { + let out = []; + for (var j in array) { + let newpt = toXY(array[j], origin); + out.push(newpt); + } + return out; +} + +function angle(a, b) { + let x = b.x - a.x; + let y = b.y - a.y; + return Math.atan2(-y, x); +} + +function rotateVec(a, theta) { + let pt = { + x: 0, + y: 0 + }; + c = Math.cos(theta); + s = Math.sin(theta); + pt.x = c * a.x - s * a.y; + pt.y = s * a.x + c * a.y; + return pt; +} + +// https://stackoverflow.com/questions/19721439/download-json-object-as-a-file-from-browser +function downloadObjectAsJSON(exportObj, exportName) { + var dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(exportObj)); + var downloadAnchorNode = document.createElement('a'); + downloadAnchorNode.setAttribute("href", dataStr); + downloadAnchorNode.setAttribute("download", exportName + ".json"); + document.body.appendChild(downloadAnchorNode); // required for firefox + downloadAnchorNode.click(); + downloadAnchorNode.remove(); +} \ No newline at end of file diff --git a/apps/golfview/metadata.json b/apps/golfview/metadata.json new file mode 100644 index 000000000..bbb221b64 --- /dev/null +++ b/apps/golfview/metadata.json @@ -0,0 +1,14 @@ +{ "id": "glfview", + "name": "Golf View", + "version":"0.01", + "description": "This app will provide you with on course data to support your golf game! All information comes from OpenStreetMap. Please contribute by drawing your course using these guidelines: [guidelines](guidelines.com)", + "icon": "golfview.png", + "tags": "", + "supports" : ["BANGLEJS2"], + "readme": "README.md", + "custom": "index.html", + "storage": [ + {"name":"glfview.app.js","url":"golfview.js"}, + {"name":"glfview.img","url":"golfview-icon.js","evaluate":true} + ] +}