septima-widget 0.0.0-dev-ba761 → 0.0.0-dev-bbb42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -5
  2. package/widgetapi.mjs +204 -0
package/package.json CHANGED
@@ -1,12 +1,8 @@
1
1
  {
2
2
  "name": "septima-widget",
3
- "version": "0.0.0-dev-ba761",
3
+ "version": "0.0.0-dev-bbb42",
4
4
  "description": "Septima Widget API",
5
5
  "type": "module",
6
- "main": "./widgetapi.js",
7
6
  "module": "./widgetapi.mjs",
8
- "exports": {
9
- "default": "./widgetapi.mjs"
10
- },
11
7
  "license": "UNLICENSED"
12
8
  }
package/widgetapi.mjs ADDED
@@ -0,0 +1,204 @@
1
+ export default class WidgetAPI {
2
+
3
+ _readylisteners = []
4
+ _controlsreadylisteners = []
5
+ _vectorreadylisteners = []
6
+
7
+ _target = null
8
+
9
+ VERSION = 'dev'
10
+
11
+ constructor(target, config, options) {
12
+ this._target = target
13
+ this._load(target, config, options)
14
+ }
15
+
16
+ async _load(target, config, options) {
17
+ const { load } = await import('https://widget.cdn.septima.dk/dev/core/load.mjs')
18
+ this._widget = await load(target, config, options, this.VERSION)
19
+ this.on('controlsready', () => {
20
+ this._controlsReady()
21
+ })
22
+ this.on('vectorready', () => {
23
+ this._vectorsReady()
24
+ })
25
+ this._widget.ready(() => {
26
+ this._ready()
27
+ })
28
+ }
29
+
30
+ _ready(func) {
31
+ if (!this._widget || typeof this._widget.events === 'undefined') {
32
+ if (func) {
33
+ this._readylisteners.push(func);
34
+ }
35
+ } else {
36
+ if (func) {
37
+ func();
38
+ } else {
39
+ for (var i = 0; i < this._readylisteners.length; i++) {
40
+ this._readylisteners[i]();
41
+ }
42
+ }
43
+ }
44
+ };
45
+
46
+ _controlsReady(func) {
47
+ if (func) {
48
+ if (this._controlsAreReady) {
49
+ func();
50
+ } else {
51
+ this._controlsreadylisteners.push(func);
52
+ }
53
+ } else {
54
+ this._controlsAreReady = true;
55
+ for (var i = 0; i < this._controlsreadylisteners.length; i++) {
56
+ this._controlsreadylisteners[i]();
57
+ }
58
+ }
59
+ };
60
+
61
+ _vectorsReady(func) {
62
+ if (func) {
63
+ if (this._vectorsAreReady) {
64
+ func();
65
+ } else {
66
+ this._vectorreadylisteners.push(func);
67
+ }
68
+ } else {
69
+ this._vectorsAreReady = true;
70
+ for (var i = 0; i < this._vectorreadylisteners.length; i++) {
71
+ this._vectorreadylisteners[i]();
72
+ }
73
+ }
74
+ };
75
+
76
+ async _setConfig(config = {}, options = {}) {
77
+ this._vectorsAreReady = false;
78
+ this._controlsAreReady = false;
79
+ this._load(this._target, config, options)
80
+ };
81
+
82
+ getURLParam(name) {
83
+ return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) || [undefined, ""])[1].replace(/\+/g, '%20')) || null;
84
+ };
85
+
86
+ bind(func, object) {
87
+ var args = Array.prototype.slice.apply(arguments, [2]);
88
+ return function () {
89
+ var newArgs = args.concat(
90
+ Array.prototype.slice.apply(arguments, [0])
91
+ );
92
+ return func.apply(object, newArgs);
93
+ };
94
+ };
95
+
96
+ setConfig(config, options) {
97
+ if (this._widget) {
98
+ this._setConfig(config, options);
99
+ } else {
100
+ this._ready(() => this._setConfig(config, options));
101
+ }
102
+ };
103
+
104
+ on(event, callback) {
105
+ if (this._widget && typeof this._widget.events !== 'undefined') {
106
+ this._widget.events.on(event, callback);
107
+ } else {
108
+ this._ready(() => this._widget.events.on(event, callback));
109
+ }
110
+ };
111
+
112
+ addData(config, options, silen) {
113
+ this._vectorsReady(() => this._widget.addData(config, options, silen));
114
+ };
115
+
116
+ removeData(id) {
117
+ this._vectorsReady(() => this._widget.removeData(id));
118
+ };
119
+
120
+ addSelect(geojson, options, silent) {
121
+ if (typeof options !== 'undefined' && typeof options.activateZoom === 'undefined') {
122
+ options.activateZoom = true;
123
+ }
124
+ this._controlsReady(() => this._widget.addSelect(geojson, options, silent));
125
+ };
126
+
127
+ removeSelect(silent) {
128
+ this._controlsReady(() => this._widget.removeSelect(silent));
129
+ };
130
+
131
+ setView(options) {
132
+ this._controlsReady(() => this._widget.setView(options));
133
+ };
134
+
135
+ getView(srs) {
136
+ if (this._widget) {
137
+ return this._widget.getView(srs)
138
+ }
139
+ return null
140
+ };
141
+
142
+ selectFeatureInLayer(layerId, filterFunction, options, silent) {
143
+ if (typeof options !== 'undefined' && typeof options.activateZoom === 'undefined') {
144
+ options.activateZoom = true;
145
+ }
146
+ this._vectorsReady(() => this._widget.selectFeatureInLayer(layerId, filterFunction, options, silent));
147
+ };
148
+
149
+ deselectFeature(silent) {
150
+ this._vectorsReady(() => this._widget.deselectFeature(silent));
151
+ };
152
+
153
+ showLayer(layerId) {
154
+ this._controlsReady(() => this._widget.showLayer(layerId));
155
+ };
156
+
157
+ hideLayer(layerId) {
158
+ this._controlsReady(() => this._widget.hideLayer(layerId));
159
+ };
160
+
161
+ setLayerOpacity(layerId, opacity) {
162
+ this._controlsReady(() => this._widget.setLayerOpacity(layerId, opacity));
163
+ };
164
+
165
+ reloadLayer(layerId) {
166
+ this._controlsReady(() => this._widget.reloadLayer(layerId));
167
+ };
168
+
169
+ updateLayerParams(layerId, params) {
170
+ this._controlsReady(() => this._widget.updateLayerParams(layerId, params));
171
+ };
172
+
173
+ showPopup(geojson, html, options) {
174
+ this._controlsReady(() => this._widget.showPopup(geojson, html, options));
175
+ };
176
+
177
+ hidePopup() {
178
+ this._controlsReady(() => this._widget.hidePopup());
179
+ };
180
+
181
+ draw(options, callback, sketchCallback) {
182
+ this._controlsReady(() => this._widget.draw(options, callback, sketchCallback));
183
+ };
184
+
185
+ unDraw() {
186
+ this._controlsReady(() => this._widget.unDraw());
187
+ };
188
+
189
+ createMapImage(options, callback) {
190
+ this._controlsReady(() => this._widget.createMapImage(options, callback));
191
+ }
192
+
193
+ transform(geojson, options, callback) {
194
+ this._controlsReady(async () => {
195
+ const { transform } = await import('https://widget.cdn.septima.dk/dev/core/utils.mjs')
196
+ if (callback) {
197
+ callback(transform(geojson, options));
198
+ } else {
199
+ transform(geojson, options)
200
+ }
201
+ });
202
+ }
203
+
204
+ }