1- import { init as initConfig , getVersion } from "../model/config.js" ;
2-
3- const DEBOUNCETIME = 100 ;
4-
5- await initConfig ( ) ;
6-
71class FilestashMap extends HTMLElement {
82 constructor ( ) {
93 super ( ) ;
@@ -30,7 +24,7 @@ class FilestashMap extends HTMLElement {
3024 type : "refresh" ,
3125 payload : { name : this . getAttribute ( "name" ) , src : this . getAttribute ( "src" ) } ,
3226 } , "*" ) ;
33- } , DEBOUNCETIME ) ;
27+ } , 100 ) ;
3428 }
3529 }
3630
@@ -41,12 +35,7 @@ class FilestashMap extends HTMLElement {
4135
4236 connectedCallback ( ) {
4337 const src = this . getAttribute ( "src" ) || "" ;
44- const name = this . getAttribute ( "name" ) || "main.dbf" ;
45- const mime = {
46- "geojson" : "application/geo+json" ,
47- "shp" : "application/vnd.shp" ,
48- "wms" : "application/vnd.ogc.wms_xml" ,
49- } [ name . split ( "." ) . pop ( ) . toLowerCase ( ) ] ;
38+ const name = this . getAttribute ( "name" ) || "main.dat" ;
5039
5140 this . style . display = "inline-block" ;
5241 this . iframe . srcdoc = `<!DOCTYPE html>
@@ -87,29 +76,45 @@ class FilestashMap extends HTMLElement {
8776 </script>
8877
8978 <script type="module" defer>
90- import { render } from "${ import . meta. url } /../../${ getVersion ( ) } /index.js";
91- import * as Application from "${ import . meta. url } /../../${ getVersion ( ) } /pages/viewerpage/application_map.js";
79+ const [{ version, mimes }] = await Promise.all([
80+ fetch("${ import . meta. url } /../../../api/config").then(async (resp) => {
81+ if (!resp.ok) return "na";
82+ const { result } = await resp.json();
83+ return { version: result.version, mimes: result.mime };
84+ }),
85+ import("${ import . meta. url } /../../boot/bundler_init.js").then(async () => {
86+ await new Promise((resolve, reject) => document.head.appendChild(Object.assign(document.createElement("script"), {
87+ type: "module",
88+ src: new URL("../bundle.js", "${ import . meta. url } "),
89+ onload: resolve,
90+ onerror: reject,
91+ })));
92+ await import("${ import . meta. url } /../../boot/bundler_complete.js");
93+ }),
94+ ]);
9295
93- const $app = document.querySelector("#app");
94- render(Application, $app, {
95- mime: "${ mime } ",
96- hasMenubar: true,
97- getFilename: () => "${ name } ",
98- getDownloadUrl: () => "${ src } ",
99- });
100- window.addEventListener("message", (event) => {
101- if(event.data.type === "refresh") {
96+ const { render } = await import("${ import . meta. url } /../../"+ version +"/index.js");
97+ const Application = await import("${ import . meta. url } /../../"+ version +"/pages/viewerpage/application_map.js");
98+
99+ const $app = document.querySelector("#app");
100+ const mime = mimes["${ name } ".split(".").pop().toLowerCase()];
101+ render(Application, $app, {
102+ mime: mime,
103+ hasMenubar: true,
104+ getFilename: () => "${ name } ",
105+ getDownloadUrl: () => "${ src } ",
106+ });
107+ window.addEventListener("message", (event) => {
108+ if(event.data.type !== "refresh") return;
102109 render(Application, $app, {
103- mime: " ${ mime } " ,
110+ mime: mime,
104111 hasMenubar: true,
105112 getFilename: () => event.data.payload.name,
106113 getDownloadUrl: () => event.data.payload.src,
107114 });
108- }
109- });
115+ });
110116 </script>
111117
112- <script type="module" src="${ import . meta. url } /../../${ getVersion ( ) } /components/modal.js"></script>
113118 <component-modal></component-modal>
114119 </body>
115120 </html>` ;
0 commit comments