Skip to content

Commit ac8d962

Browse files
committed
Add WMTS license fallback to capabilities document
When a WMTS layer doesn't have a specific license URL, the license link now falls back to the service's GetCapabilities URL with the service title. This ensures all WMTS layers have proper attribution linking back to the source capabilities document. - Pass serviceInfo to addWMTSLayerToViewer function - Construct proper GetCapabilities URL (SERVICE=WMTS&REQUEST=GetCapabilities) - Use service title as license link title when no layer license exists
1 parent 98e010b commit ac8d962

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

src/script/main.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3080,14 +3080,14 @@ function createViewerForWMTSLayer(index, layer, serviceInfo, selectedFormat, que
30803080
viewer.appendChild(baseLayer);
30813081
}
30823082

3083-
addWMTSLayerToViewer(viewer, layer, tileMatrixSet, selectedFormat, queryEnabled, styleName, imgFormat, includeBounds, index);
3083+
addWMTSLayerToViewer(viewer, layer, tileMatrixSet, selectedFormat, queryEnabled, styleName, imgFormat, includeBounds, index, serviceInfo);
30843084

30853085
container.appendChild(viewer);
30863086

30873087
console.log('Created WMTS viewer for layer:', layer.name);
30883088
}
30893089

3090-
function addWMTSLayerToViewer(viewer, layer, tileMatrixSet, selectedFormat, queryEnabled, selectedStyle, imageFormat, boundsEnabled, layerIndex) {
3090+
function addWMTSLayerToViewer(viewer, layer, tileMatrixSet, selectedFormat, queryEnabled, selectedStyle, imageFormat, boundsEnabled, layerIndex, serviceInfo) {
30913091
const viewerProjection = viewer.getAttribute('projection') || 'OSMTILE';
30923092
const bbox = layer.bbox;
30933093

@@ -3109,13 +3109,26 @@ function addWMTSLayerToViewer(viewer, layer, tileMatrixSet, selectedFormat, quer
31093109
mapLayer.appendChild(mapMeta);
31103110
}
31113111

3112+
// Add license link - use layer license if available, otherwise fall back to capabilities document
3113+
const licenseLink = document.createElement('map-link');
3114+
licenseLink.setAttribute('rel', 'license');
3115+
31123116
if (layer.licenseUrl) {
3113-
const licenseLink = document.createElement('map-link');
3114-
licenseLink.setAttribute('rel', 'license');
31153117
licenseLink.setAttribute('href', layer.licenseUrl);
31163118
if (layer.licenseTitle) {
31173119
licenseLink.setAttribute('title', layer.licenseTitle + ' for ' + layer.title);
31183120
}
3121+
} else if (serviceInfo && serviceInfo.baseUrl) {
3122+
// Fallback to capabilities document - construct proper GetCapabilities URL
3123+
const capabilitiesUrl = serviceInfo.baseUrl + '?SERVICE=WMTS&REQUEST=GetCapabilities';
3124+
licenseLink.setAttribute('href', capabilitiesUrl);
3125+
if (serviceInfo.title) {
3126+
licenseLink.setAttribute('title', serviceInfo.title);
3127+
}
3128+
}
3129+
3130+
// Only append if we have an href
3131+
if (licenseLink.getAttribute('href')) {
31193132
mapLayer.appendChild(licenseLink);
31203133
}
31213134

0 commit comments

Comments
 (0)