Skip to content

Commit c98e507

Browse files
author
Peter Rushforth
committed
Add script to pages that use content from MapML Services Directory on
geogratis to check the sub-layers if required
1 parent aab2645 commit c98e507

3 files changed

Lines changed: 94 additions & 2 deletions

File tree

human-geo-web/index.html

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,36 @@
2020
height: 480px;
2121
}
2222
</style>
23+
<script>
24+
async function waitForMapLayersAndCheckExtents() {
25+
// Wait for the map-layer custom element to be defined
26+
await customElements.whenDefined('map-layer');
27+
28+
// Query all map-layer elements in the document
29+
const mapLayers = document.querySelectorAll('map-layer');
30+
31+
// Collect promises from each layer's whenReady function
32+
const readyPromises = Array.from(mapLayers).map(layer => layer.whenReady());
33+
34+
// Wait for all layers to be ready
35+
await Promise.all(readyPromises);
36+
37+
// Loop through each layer and set checked attribute on map-extent elements
38+
// because geogratis is a bit out of date and its map-extents don't have checked
39+
for (const layer of mapLayers) {
40+
if (layer.shadowRoot) {
41+
const mapExtents = layer.shadowRoot.querySelectorAll('map-extent');
42+
mapExtents.forEach(extent => {
43+
extent.setAttribute('checked', '');
44+
extent.setAttribute('hidden', '');
45+
});
46+
}
47+
}
48+
}
49+
50+
waitForMapLayersAndCheckExtents().catch(console.error);
51+
52+
</script>
2353
</head>
2454
<body>
2555

i18n/rtl/index.html

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,36 @@
66
<title>Right-to-left text (Ottawa Restaurants)</title>
77
<script type="module" src="../../dist/mapml.js"></script>
88
<link rel="stylesheet" href="../../global.css">
9+
<script>
10+
async function waitForMapLayersAndCheckExtents() {
11+
// Wait for the map-layer custom element to be defined
12+
await customElements.whenDefined('map-layer');
13+
14+
// Query all map-layer elements in the document
15+
const mapLayers = document.querySelectorAll('map-layer');
16+
17+
// Collect promises from each layer's whenReady function
18+
const readyPromises = Array.from(mapLayers).map(layer => layer.whenReady());
19+
20+
// Wait for all layers to be ready
21+
await Promise.all(readyPromises);
22+
23+
// Loop through each layer and set checked attribute on map-extent elements
24+
// because geogratis is a bit out of date and its map-extents don't have checked
25+
for (const layer of mapLayers) {
26+
if (layer.shadowRoot) {
27+
const mapExtents = layer.shadowRoot.querySelectorAll('map-extent');
28+
mapExtents.forEach(extent => {
29+
extent.setAttribute('checked', '');
30+
extent.setAttribute('hidden', '');
31+
});
32+
}
33+
}
34+
}
35+
36+
waitForMapLayersAndCheckExtents().catch(console.error);
37+
38+
</script>
939
</head>
1040
<body>
1141
<mapml-viewer dir="rtl" projection="OSMTILE" zoom="15" lat="45.4069740362364" lon="-75.70155300710053" controls>

security/csp/index.html

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
<head>
44
<meta charset="utf-8">
55
<meta http-equiv="content-security-policy" content="
6-
default-src 'self';
6+
default-src 'self'
7+
'sha256-Dg/+S/ZgqYPHC7APbOr4sSXBNAQV0DlPV2T8f9zGm20=';
78
style-src 'self'
89
'unsafe-hashes'
910
'sha256-i+apkz/LmUo63uwfP1/iCMKtQhZhY1CBUGVKuovPL0c='
@@ -14,12 +15,43 @@
1415
img-src 'self'
1516
data:
1617
https://geoappext.nrcan.gc.ca
17-
https://maps-cartes.services.geo.ca;
18+
https://maps-cartes.services.geo.ca
19+
https://www.w3.org/community/;
1820
">
1921
<meta name="viewport" content="width=device-width,initial-scale=1">
2022
<title>CSP evaluation</title>
2123
<script type="module" src="../../dist/mapml.js"></script>
2224
<link rel="stylesheet" href="self.css">
25+
<script>
26+
async function waitForMapLayersAndCheckExtents() {
27+
// Wait for the map-layer custom element to be defined
28+
await customElements.whenDefined('map-layer');
29+
30+
// Query all map-layer elements in the document
31+
const mapLayers = document.querySelectorAll('map-layer');
32+
33+
// Collect promises from each layer's whenReady function
34+
const readyPromises = Array.from(mapLayers).map(layer => layer.whenReady());
35+
36+
// Wait for all layers to be ready
37+
await Promise.all(readyPromises);
38+
39+
// Loop through each layer and set checked attribute on map-extent elements
40+
// because geogratis is a bit out of date and its map-extents don't have checked
41+
for (const layer of mapLayers) {
42+
if (layer.shadowRoot) {
43+
const mapExtents = layer.shadowRoot.querySelectorAll('map-extent');
44+
mapExtents.forEach(extent => {
45+
extent.setAttribute('checked', '');
46+
extent.setAttribute('hidden', '');
47+
});
48+
}
49+
}
50+
}
51+
52+
waitForMapLayersAndCheckExtents().catch(console.error);
53+
54+
</script>
2355
</head>
2456
<body>
2557

0 commit comments

Comments
 (0)