@@ -281,6 +281,95 @@ var searchProjects = function(){
281281 }
282282}
283283
284+ var addPrefetchOnClick = function ( ) {
285+ console . log ( 'Test ' + $ ( 'a.liz-project-view' ) . length ) ;
286+ const links = [ {
287+ url : lizUrls . map ,
288+ type : 'text/html' ,
289+ as : 'document' ,
290+ params : { } ,
291+ } , {
292+ url : lizUrls . config ,
293+ type : 'application/json' ,
294+ as : 'fetch' ,
295+ params : { } ,
296+ } , {
297+ url : lizUrls . keyValueConfig ,
298+ type : 'application/json' ,
299+ as : 'fetch' ,
300+ params : { } ,
301+ } , {
302+ url : lizUrls . ogcService ,
303+ type : 'text/xml' ,
304+ as : 'fetch' ,
305+ params : {
306+ SERVICE : 'WMS' ,
307+ REQUEST : 'GetCapabilities' ,
308+ VERSION : '1.3.0' ,
309+ } ,
310+ } , {
311+ url : lizUrls . ogcService ,
312+ type : 'text/xml' ,
313+ as : 'fetch' ,
314+ params : {
315+ SERVICE : 'WFS' ,
316+ REQUEST : 'GetCapabilities' ,
317+ VERSION : '1.0.0' ,
318+ } ,
319+ } , {
320+ url : lizUrls . ogcService ,
321+ type : 'text/xml' ,
322+ as : 'fetch' ,
323+ params : {
324+ SERVICE : 'WMTS' ,
325+ REQUEST : 'GetCapabilities' ,
326+ VERSION : '1.0.0' ,
327+ } ,
328+ } ] ;
329+ $ ( 'a.liz-project-view' ) . click ( function ( ) {
330+ var self = $ ( this ) ;
331+ var projElem = self . parent ( ) . parent ( ) . find ( 'div.liz-project' ) ;
332+ if ( projElem . length < 1 ) {
333+ alert ( 'no project' ) ;
334+ return false ;
335+ }
336+ projElem = projElem [ 0 ] ;
337+ var repId = projElem . dataset . lizmapRepository ;
338+ var projId = projElem . dataset . lizmapProject ;
339+ links . forEach ( link => {
340+ const params = new URLSearchParams ( ) ;
341+ params . append ( 'repository' , repId ) ;
342+ params . append ( 'project' , projId ) ;
343+ for ( const key in link . params ) {
344+ params . append ( key , link . params [ key ] ) ;
345+ }
346+ //create link tag
347+ const linkTag = document . createElement ( 'link' ) ;
348+ linkTag . rel = 'prefetch' ;
349+ linkTag . href = link . url + '?' + params ;
350+ linkTag . type = link . type ;
351+ linkTag . as = link . as ;
352+ //inject tag in the head of the document
353+ document . head . appendChild ( linkTag ) ;
354+ } ) ;
355+
356+ return true ;
357+ } ) ;
358+ }
359+
284360window . addEventListener ( 'load' , function ( ) {
361+ // Initialize global variables
362+ const lizmapVariablesJSON = document . getElementById ( 'lizmap-vars' ) ?. innerText ;
363+ if ( lizmapVariablesJSON ) {
364+ try {
365+ const lizmapVariables = JSON . parse ( lizmapVariablesJSON ) ;
366+ for ( const variable in lizmapVariables ) {
367+ globalThis [ variable ] = lizmapVariables [ variable ] ;
368+ }
369+ } catch {
370+ console . warn ( 'JSON for Lizmap global variables is not valid!' ) ;
371+ }
372+ }
285373 searchProjects ( ) ;
374+ addPrefetchOnClick ( ) ;
286375} ) ;
0 commit comments