septima-widget 0.0.0-dev-ba761 → 0.0.0-dev-2f579

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "septima-widget",
3
- "version": "0.0.0-dev-ba761",
3
+ "version": "0.0.0-dev-2f579",
4
4
  "description": "Septima Widget API",
5
5
  "type": "module",
6
6
  "main": "./widgetapi.js",
package/widgetapi.js ADDED
@@ -0,0 +1,206 @@
1
+ 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
+ }
205
+
206
+ window.WidgetAPI = WidgetAPI
package/widgetapi.mjs ADDED
@@ -0,0 +1 @@
1
+ class t{_readylisteners=[];_controlsreadylisteners=[];_vectorreadylisteners=[];_target=null;VERSION="0.0.0-dev-2f579";constructor(t,e,a){this._target=t,this._load(t,e,a)}async _load(t,e,a){const{load:i}=await import("./core/load.mjs");this._widget=await i(t,e,a,this.VERSION),this.on("controlsready",(()=>{this._controlsReady()})),this.on("vectorready",(()=>{this._vectorsReady()})),this._widget.ready((()=>{this._ready()}))}_ready(t){if(!this._widget||typeof this._widget.events>"u")t&&this._readylisteners.push(t);else if(t)t();else for(var e=0;e<this._readylisteners.length;e++)this._readylisteners[e]()}_controlsReady(t){if(t)this._controlsAreReady?t():this._controlsreadylisteners.push(t);else{this._controlsAreReady=!0;for(var e=0;e<this._controlsreadylisteners.length;e++)this._controlsreadylisteners[e]()}}_vectorsReady(t){if(t)this._vectorsAreReady?t():this._vectorreadylisteners.push(t);else{this._vectorsAreReady=!0;for(var e=0;e<this._vectorreadylisteners.length;e++)this._vectorreadylisteners[e]()}}async _setConfig(t={},e={}){this._vectorsAreReady=!1,this._controlsAreReady=!1,this._load(this._target,t,e)}getURLParam(t){return decodeURIComponent((new RegExp("[?|&]"+t+"=([^&;]+?)(&|#|;|$)").exec(location.search)||[void 0,""])[1].replace(/\+/g,"%20"))||null}bind(t,e){var a=Array.prototype.slice.apply(arguments,[2]);return function(){var i=a.concat(Array.prototype.slice.apply(arguments,[0]));return t.apply(e,i)}}setConfig(t,e){this._widget?this._setConfig(t,e):this._ready((()=>this._setConfig(t,e)))}on(t,e){this._widget&&typeof this._widget.events<"u"?this._widget.events.on(t,e):this._ready((()=>this._widget.events.on(t,e)))}addData(t,e,a){this._vectorsReady((()=>this._widget.addData(t,e,a)))}removeData(t){this._vectorsReady((()=>this._widget.removeData(t)))}addSelect(t,e,a){typeof e<"u"&&typeof e.activateZoom>"u"&&(e.activateZoom=!0),this._controlsReady((()=>this._widget.addSelect(t,e,a)))}removeSelect(t){this._controlsReady((()=>this._widget.removeSelect(t)))}setView(t){this._controlsReady((()=>this._widget.setView(t)))}getView(t){return this._widget?this._widget.getView(t):null}selectFeatureInLayer(t,e,a,i){typeof a<"u"&&typeof a.activateZoom>"u"&&(a.activateZoom=!0),this._vectorsReady((()=>this._widget.selectFeatureInLayer(t,e,a,i)))}deselectFeature(t){this._vectorsReady((()=>this._widget.deselectFeature(t)))}showLayer(t){this._controlsReady((()=>this._widget.showLayer(t)))}hideLayer(t){this._controlsReady((()=>this._widget.hideLayer(t)))}setLayerOpacity(t,e){this._controlsReady((()=>this._widget.setLayerOpacity(t,e)))}reloadLayer(t){this._controlsReady((()=>this._widget.reloadLayer(t)))}updateLayerParams(t,e){this._controlsReady((()=>this._widget.updateLayerParams(t,e)))}showPopup(t,e,a){this._controlsReady((()=>this._widget.showPopup(t,e,a)))}hidePopup(){this._controlsReady((()=>this._widget.hidePopup()))}draw(t,e,a){this._controlsReady((()=>this._widget.draw(t,e,a)))}unDraw(){this._controlsReady((()=>this._widget.unDraw()))}createMapImage(t,e){this._controlsReady((()=>this._widget.createMapImage(t,e)))}transform(t,e,a){this._controlsReady((async()=>{const{transform:i}=await import("./core/utils.mjs").then((t=>t.D));a?a(i(t,e)):i(t,e)}))}}async function e(a=document){if(!a)return;await async function(t){if(!t)return;const e=t.querySelectorAll("[data-widget-html]");for(let t=0;t<e.length;t++){const a=e[t],i=a.getAttribute("data-widget-html"),s=await(await fetch(i)).text(),r=document.createRange().createContextualFragment(s);a.replaceWith(r)}}(a);const i=a.querySelectorAll("[data-widget],[data-widget-url]");i.length>0&&i.forEach((async e=>{e.getAttribute("data-widget-initialized")||(e.setAttribute("data-widget-initialized",!0),new t(e))})),function(e=document){const a=e.querySelectorAll("[septimamap-address],[septimamap-point]");a.length>0&&a.forEach((async e=>{if(e.getAttribute("data-widget-initialized"))return;e.setAttribute("data-widget-initialized",!0);const a=e.getAttribute("septimamap-pincolor")||"rgba(255,0,0,1)",i=(e.getAttribute("septimamap-layer")||"#dk_standard").replace("sdfe","gst"),s=e.getAttribute("septimamap-zoom")||10,r=e.getAttribute("septimamap-zoomstyle")||"none",o="false"===e.getAttribute("septimamap-overlay"),d=e.getAttribute("septimamap-address");d&&e.setAttribute("data-widget-address",d);const n=e.getAttribute("septimamap-point");n&&e.setAttribute("data-widget-point",n);const l=e.getAttribute("septimamap-text");e.setAttribute("data-widget-text",l);const c=e.getAttribute("septimamap-height");c&&e.setAttribute("data-widget-height",c);const p=e.getAttribute("septimamap-width");p&&e.setAttribute("data-widget-width",p);const h={maxZoomLevel:0,minZoomLevel:13,view:{zoomLevel:3,x:671157,y:6240022},layer:[{namedlayer:i},{id:"marking",features:!0,type:"geojson",data:{type:"FeatureCollection",crs:{type:"name",properties:{name:"urn:ogc:def:crs:EPSG::25832"}},features:[]},template_info:"<% if (text) { %><div class='widget-simple-title'><%= text %></div><% } %><% if (typeof vejnavn !== 'undefined') { %><div class='widget-simple-sub'><div><%= vejnavn %> <%= husnr %></div><div><%= postnr %> <%= postnrnavn %></div></div><% } %>",features_dataType:"json",features_style:{namedstyle:"#100",fillcolor:a,fillcolor_selected:a,fillopacity:.8,fillopacity_selected:1}}],controls:[{showpoint:{layer:"marking",zoom:s-0,zoomStyle:r,type:"popup"},info:{disable:!1,eventtype:"click",type:"cloud",offset:[0,10],className:"widget-simple-popup"}}]};"#osm"===i&&(h.srs="EPSG:3857",h.maxZoomLevel=7,h.minZoomLevel=22,h.view={zoomLevel:3,x:12.57089928,y:55.67707833},h.layer[1].srs=h.srs,h.layer[1].data.crs={type:"name",properties:{name:"urn:ogc:def:crs:EPSG::4326"}},h.layer[1].template_info='<% if (text) { %><div class="widget-simple-title"><%= text %></div><% } %>'+(d?'<div class="widget-simple-sub">'+d+"<div></div></div>":""),h.controls[0].showpoint.srs="EPSG:4326"),o&&(h.controls[0].overlay={}),new t(e,{map:h})}))}(a),function(t=document){const a=t.querySelectorAll("[data-map-id]");a.length>0&&(a.forEach((async t=>{const e=t.getAttribute("data-map-id"),a=t.getAttribute("data-map-token"),i=t.getAttribute("data-map-test");t.removeAttribute("data-map-id"),t.removeAttribute("data-map-token"),t.removeAttribute("data-map-test");const s=`https://${a}.map.${i?"test.":""}septima.dk/rpc/getmap?mapid=${e}&token=${a}`;t.setAttribute("data-widget-url",s)})),e(t))}(a)}export{e as createWidgetsFromDOM,t as default};