-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.user.ts
79 lines (67 loc) · 2.35 KB
/
main.user.ts
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { WmeSDK } from "wme-sdk-typings";
// the sdk initScript function will be called after the SDK is initialized
window.SDK_INITIALIZED.then(initScript);
function initScript() {
// initialize the sdk, these should remain here at the top of the script
if (!window.getWmeSdk) {
// This block is required for type checking, but it is guaranteed that the function exists.
throw new Error("SDK not available");
}
const wmeSDK: WmeSDK = window.getWmeSdk(
{
scriptId: "example-ts-id", // TODO: replace with your script id and script name
scriptName: "Typescript example" // TODO
}
)
console.debug(`SDK v. ${wmeSDK.getSDKVersion()} on ${wmeSDK.getWMEVersion()} initialized`)
/* Example functions, define your functions in this section */
function setKeyboardShortcuts() {
wmeSDK.Shortcuts.createShortcut({
callback: () => {
alert("Shortcut is working!");
},
description: "typescript shortcut",
shortcutId: "test-shortcut-id",
shortcutKeys: "A+s",
});
}
function addLayer() {
const layer = wmeSDK.Map.addLayer({
layerName: "TS Layer"
});
wmeSDK.LayerSwitcher.addLayerCheckbox({
name: "TS Layer",
})
// Draw a feature
wmeSDK.Map.addFeatureToLayer(
{
layerName: "TS Layer",
feature: {
id: "test-feature",
geometry: {
coordinates: [wmeSDK.Map.getMapCenter().lon, wmeSDK.Map.getMapCenter().lat],
type: "Point"
},
type: "Feature",
}
}
)
}
function addEventListeners() {
// ...
}
async function addScriptTab() {
const { tabLabel, tabPane } = await wmeSDK.Sidebar.registerScriptTab()
tabLabel.innerText = "Typescript Tab" // TODO
tabPane.innerHTML = "<h1>Typescript Tab</h1>" // TODO
}
function init(): void {
// Call the functions you need to run initialize / run your script here
addScriptTab()
setKeyboardShortcuts()
addLayer()
addEventListeners()
alert("Your script is running! - TODO remove this line :)")
}
init()
}