-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapBridge.ts
More file actions
25 lines (22 loc) · 854 Bytes
/
Copy pathmapBridge.ts
File metadata and controls
25 lines (22 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/**
* MapBridge: map buttons never link to a specific map service directly.
* The query string is UTF-8 encoded, then URL-safe Base64 encoded:
* https://mapbridge.threelight-studio.com/s/<URL_SAFE_BASE64>
*/
export const MAPBRIDGE_BASE = 'https://mapbridge.threelight-studio.com/s/';
function bytesToBase64(bytes: Uint8Array): string {
let binary = '';
for (let i = 0; i < bytes.length; i += 1) {
binary += String.fromCharCode(bytes[i]);
}
return btoa(binary);
}
export function toUrlSafeBase64(input: string): string {
const bytes = new TextEncoder().encode(input);
return bytesToBase64(bytes).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
}
export function mapBridgeUrl(query: string): string {
const trimmed = query.trim();
if (!trimmed) return '';
return `${MAPBRIDGE_BASE}${toUrlSafeBase64(trimmed)}`;
}