Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Deploy static content to Pages

on:
# Runs on pushes targeting the default branch
push:
branches: ["master"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
# Single deploy job since we're just deploying
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Pages
run: |
mkdir docs
cp javascript/decode.html docs/index.html
cp javascript/index.js docs/index.js
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
# Upload docs folder only
path: 'docs'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
64 changes: 64 additions & 0 deletions javascript/decode.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flexpolyline Decoder/Encoder</title>
<script>const module = {}; // should move to ES6 modules</script>
<script src="index.js"></script>
</head>
<body>
<h1>Flexpolyline Decoder/Encoder</h1>
<textarea id="input" rows="10" cols="50" placeholder="Paste an encoded flexible polyline or an array of coordinates (JSON format)" oninput="validateInput()"></textarea>
<button id="decodeButton" onclick="processInput()">Decode</button>
<pre id="output"></pre>
<script>
const inputElement = document.getElementById('input');
const outputElement = document.getElementById('output');
const decodeButton = document.getElementById('decodeButton');

if (window.location.hash) {
inputElement.value = decodeURIComponent(window.location.hash.slice(1));
processInput();
}

function validateInput() {
const input = inputElement.value.trim();
const isEncoding = input.startsWith('[') || input.startsWith('{');
decodeButton.textContent = isEncoding ? 'Encode' : 'Decode';
}

function processInput() {
const data = inputElement.value.trim();
const isEncoding = data.startsWith('[') || data.startsWith('{');
if (isEncoding) {
encodeInput(data);
} else {
decodeInput(data);
}
}

function decodeInput(data) {
try {
const decodedData = decode(data);
outputElement.textContent = JSON.stringify(decodedData, null, 2);
} catch (error) {
outputElement.textContent = error.message;
}
}

function encodeInput(data) {
try {
let params = JSON.parse(data);
if (Array.isArray(params)) {
params = { polyline: params };
}
const encodedData = encode(params);
outputElement.textContent = encodedData;
} catch (error) {
outputElement.textContent = error.message;
}
}
</script>
</body>
</html>