Skip to content

Commit a198ef7

Browse files
committed
Add preload for initial fetch request
1 parent eaca1bc commit a198ef7

File tree

3 files changed

+62
-7
lines changed

3 files changed

+62
-7
lines changed

lizmap/modules/lizmap/lib/Project/Project.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,27 @@ public function getWMSGetCapabilitiesUrl()
534534
'repository' => $this->repository->getKey(),
535535
'project' => $this->key,
536536
'SERVICE' => 'WMS',
537+
'REQUEST' => 'GetCapabilities',
537538
'VERSION' => '1.3.0',
539+
)
540+
);
541+
}
542+
543+
/**
544+
* Get the WMS GetCapabilities Url.
545+
*
546+
* @return string
547+
*/
548+
public function getWFSGetCapabilitiesUrl()
549+
{
550+
return $this->appContext->getFullUrl(
551+
'lizmap~service:index',
552+
array(
553+
'repository' => $this->repository->getKey(),
554+
'project' => $this->key,
555+
'SERVICE' => 'WFS',
538556
'REQUEST' => 'GetCapabilities',
557+
'VERSION' => '1.0.0',
539558
)
540559
);
541560
}
@@ -553,8 +572,8 @@ public function getWMTSGetCapabilitiesUrl()
553572
'repository' => $this->repository->getKey(),
554573
'project' => $this->key,
555574
'SERVICE' => 'WMTS',
556-
'VERSION' => '1.0.0',
557575
'REQUEST' => 'GetCapabilities',
576+
'VERSION' => '1.0.0',
558577
)
559578
);
560579
}

lizmap/modules/view/controllers/lizMap.classic.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,27 @@ public function index()
213213
'resourceUrlReplacement' => array(),
214214
);
215215

216+
// Add preload links
217+
$rep->addPreloadLink(
218+
jUrl::get(
219+
'lizmap~service:getProjectConfig',
220+
array('repository' => $repository, 'project' => $project),
221+
),
222+
'fetch',
223+
'application/json',
224+
);
225+
$rep->addPreloadLink(
226+
jUrl::get(
227+
'lizmap~service:getKeyValueConfig',
228+
array('repository' => $repository, 'project' => $project),
229+
),
230+
'fetch',
231+
'application/json',
232+
);
233+
$rep->addPreloadLink($lproj->getWMSGetCapabilitiesUrl(), 'fetch', 'application/xml');
234+
$rep->addPreloadLink($lproj->getWFSGetCapabilitiesUrl(), 'fetch', 'application/xml');
235+
$rep->addPreloadLink($lproj->getWMTSGetCapabilitiesUrl(), 'fetch', 'application/xml');
236+
216237
// Get optional WMS public url list
217238
$lser = lizmap::getServices();
218239
if ($lser->wmsPublicUrlList) {
@@ -316,6 +337,7 @@ function f($x)
316337
}
317338
}
318339

340+
// Add map theme
319341
$rep->addAssets('maptheme');
320342

321343
// Add dockable css

tests/end2end/playwright/viewport.spec.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,17 @@ test.describe('Viewport devicePixelRatio 1', () => {
2727

2828
// Go to the map
2929
await gotoMap(url, page)
30-
// Wait to let the config loaded
31-
await page.waitForTimeout(1000);
3230
// Check that the get project config has been catched
33-
expect(requests).toHaveLength(1);
31+
// Preload and fetch
32+
let timeCount = 0;
33+
while (requests.length < 2) {
34+
timeCount += 100;
35+
if (timeCount > 1000) {
36+
throw new Error('Timeout');
37+
}
38+
await page.waitForTimeout(100);
39+
}
40+
await expect(requests).toHaveLength(2);
3441

3542
// Wait to let the JS build classes
3643
await page.waitForTimeout(1000);
@@ -97,10 +104,17 @@ test.describe('Viewport devicePixelRatio 2', () => {
97104

98105
// Go to the map
99106
await gotoMap(url, page)
100-
// Wait to let the config loaded
101-
await page.waitForTimeout(1000);
102107
// Check that the get project config has been catched
103-
expect(requests).toHaveLength(1);
108+
// Preload and fetch
109+
let timeCount = 0;
110+
while (requests.length < 2) {
111+
timeCount += 100;
112+
if (timeCount > 1000) {
113+
throw new Error('Timeout');
114+
}
115+
await page.waitForTimeout(100);
116+
}
117+
expect(requests).toHaveLength(2);
104118

105119
// Wait to let the JS build classes
106120
await page.waitForTimeout(1000);

0 commit comments

Comments
 (0)