@@ -740,7 +740,15 @@ function createQueryLink(layer, version, projectionCode, infoFormat, layerIndex,
740740 queryLink . setAttribute ( 'data-query-link' , 'true' ) ; // Mark for easy identification
741741
742742 // Build GetFeatureInfo URL template - same as GetMap but with different REQUEST and additional params
743- let tref = `${ currentWmsBaseUrl } ?SERVICE=WMS&VERSION=${ version } &REQUEST=GetFeatureInfo&LAYERS=${ encodeURIComponent ( layer . name ) } &QUERY_LAYERS=${ encodeURIComponent ( layer . name ) } &WIDTH={w}&HEIGHT={h}&FORMAT=${ encodeURIComponent ( imageFormat || 'image/png' ) } &INFO_FORMAT=${ encodeURIComponent ( infoFormat ) } ` ;
743+ let tref = `${ currentWmsBaseUrl } ?SERVICE=WMS&VERSION=${ version } &REQUEST=GetFeatureInfo&LAYERS=${ encodeURIComponent ( layer . name ) } &QUERY_LAYERS=${ encodeURIComponent ( layer . name ) } &WIDTH={w}&HEIGHT={h}&FORMAT=${ encodeURIComponent ( imageFormat || 'image/png' ) } ` ;
744+
745+ // Only add TRANSPARENT=TRUE for formats that support transparency
746+ const imgFormat = imageFormat || 'image/png' ;
747+ if ( imgFormat . toLowerCase ( ) . includes ( 'png' ) || imgFormat . toLowerCase ( ) . includes ( 'gif' ) ) {
748+ tref += '&TRANSPARENT=TRUE' ;
749+ }
750+
751+ tref += `&INFO_FORMAT=${ encodeURIComponent ( infoFormat ) } ` ;
744752
745753 // Add STYLES parameter if a style is selected
746754 if ( styleName ) {
@@ -1068,6 +1076,49 @@ function addLayerToViewer(viewer, layer, version, selectedFormat, queryEnabled,
10681076 mapLayer . setAttribute ( 'checked' , '' ) ;
10691077 mapLayer . setAttribute ( 'data-wms-layer' , layer . name ) ;
10701078
1079+ // Add map-meta extent using geographic bounding box (WGS84)
1080+ const mapMeta = document . createElement ( 'map-meta' ) ;
1081+ mapMeta . setAttribute ( 'name' , 'extent' ) ;
1082+ mapMeta . setAttribute ( 'content' , `top-left-longitude=${ bbox . minx } , top-left-latitude=${ bbox . maxy } , bottom-right-longitude=${ bbox . maxx } , bottom-right-latitude=${ bbox . miny } ` ) ;
1083+ mapLayer . appendChild ( mapMeta ) ;
1084+
1085+ // Add license link if available (before map-extent)
1086+ if ( layer . licenseUrl ) {
1087+ const licenseLink = document . createElement ( 'map-link' ) ;
1088+ licenseLink . setAttribute ( 'rel' , 'license' ) ;
1089+ licenseLink . setAttribute ( 'href' , layer . licenseUrl ) ;
1090+ if ( layer . licenseTitle ) {
1091+ licenseLink . setAttribute ( 'title' , `${ layer . licenseTitle } for ${ layer . title } ` ) ;
1092+ }
1093+ mapLayer . appendChild ( licenseLink ) ;
1094+ console . log ( 'Added license link to layer:' , layer . name , 'URL:' , layer . licenseUrl , 'Title:' , layer . licenseTitle || 'none' ) ;
1095+ } else {
1096+ console . log ( 'No license URL for layer:' , layer . name ) ;
1097+ }
1098+
1099+ // Add legend link for the selected style only (before map-extent)
1100+ if ( layer . styles && layer . styles . length > 0 && styleName ) {
1101+ const selectedStyle = layer . styles . find ( style => style . name === styleName ) ;
1102+ if ( selectedStyle && selectedStyle . legendURLs && selectedStyle . legendURLs . length > 0 ) {
1103+ // Only add the first legend URL for the selected style
1104+ const legend = selectedStyle . legendURLs [ 0 ] ;
1105+ const legendLink = document . createElement ( 'map-link' ) ;
1106+ legendLink . setAttribute ( 'rel' , 'legend' ) ;
1107+ legendLink . setAttribute ( 'href' , legend . href ) ;
1108+ if ( selectedStyle . title ) {
1109+ legendLink . setAttribute ( 'title' , selectedStyle . title ) ;
1110+ }
1111+ if ( legend . width ) {
1112+ legendLink . setAttribute ( 'width' , legend . width ) ;
1113+ }
1114+ if ( legend . height ) {
1115+ legendLink . setAttribute ( 'height' , legend . height ) ;
1116+ }
1117+ mapLayer . appendChild ( legendLink ) ;
1118+ console . log ( 'Added legend link for selected style:' , selectedStyle . title ) ;
1119+ }
1120+ }
1121+
10711122 // Create map-extent
10721123 const mapExtent = document . createElement ( 'map-extent' ) ;
10731124 mapExtent . setAttribute ( 'units' , units ) ;
@@ -1162,7 +1213,12 @@ function addLayerToViewer(viewer, layer, version, selectedFormat, queryEnabled,
11621213 mapLink . setAttribute ( 'rel' , 'image' ) ;
11631214
11641215 // Build URL manually to preserve template variables
1165- let tref = `${ currentWmsBaseUrl } ?SERVICE=WMS&VERSION=${ version } &REQUEST=GetMap&LAYERS=${ encodeURIComponent ( layer . name ) } &WIDTH={w}&HEIGHT={h}&FORMAT=${ encodeURIComponent ( imgFormat ) } &TRANSPARENT=TRUE` ;
1216+ let tref = `${ currentWmsBaseUrl } ?SERVICE=WMS&VERSION=${ version } &REQUEST=GetMap&LAYERS=${ encodeURIComponent ( layer . name ) } &WIDTH={w}&HEIGHT={h}&FORMAT=${ encodeURIComponent ( imgFormat ) } ` ;
1217+
1218+ // Only add TRANSPARENT=TRUE for formats that support transparency
1219+ if ( imgFormat . toLowerCase ( ) . includes ( 'png' ) || imgFormat . toLowerCase ( ) . includes ( 'gif' ) ) {
1220+ tref += '&TRANSPARENT=TRUE' ;
1221+ }
11661222
11671223 // Add STYLES parameter if a style is selected
11681224 if ( styleName ) {
@@ -1204,44 +1260,6 @@ function addLayerToViewer(viewer, layer, version, selectedFormat, queryEnabled,
12041260 mapExtent . appendChild ( queryLink ) ;
12051261 }
12061262
1207- // Add license link if available (before map-extent)
1208- if ( layer . licenseUrl ) {
1209- const licenseLink = document . createElement ( 'map-link' ) ;
1210- licenseLink . setAttribute ( 'rel' , 'license' ) ;
1211- licenseLink . setAttribute ( 'href' , layer . licenseUrl ) ;
1212- if ( layer . licenseTitle ) {
1213- licenseLink . setAttribute ( 'title' , `${ layer . licenseTitle } for ${ layer . title } ` ) ;
1214- }
1215- mapLayer . appendChild ( licenseLink ) ;
1216- console . log ( 'Added license link to layer:' , layer . name , 'URL:' , layer . licenseUrl , 'Title:' , layer . licenseTitle || 'none' ) ;
1217- } else {
1218- console . log ( 'No license URL for layer:' , layer . name ) ;
1219- }
1220-
1221- // Add legend link for the selected style only (before map-extent)
1222- if ( layer . styles && layer . styles . length > 0 && styleName ) {
1223- const selectedStyle = layer . styles . find ( style => style . name === styleName ) ;
1224- if ( selectedStyle && selectedStyle . legendURLs && selectedStyle . legendURLs . length > 0 ) {
1225- // Only add the first legend URL for the selected style
1226- const legend = selectedStyle . legendURLs [ 0 ] ;
1227- const legendLink = document . createElement ( 'map-link' ) ;
1228- legendLink . setAttribute ( 'rel' , 'legend' ) ;
1229- legendLink . setAttribute ( 'href' , legend . href ) ;
1230- if ( selectedStyle . title ) {
1231- legendLink . setAttribute ( 'title' , selectedStyle . title ) ;
1232- }
1233- if ( legend . width ) {
1234- legendLink . setAttribute ( 'width' , legend . width ) ;
1235- }
1236- if ( legend . height ) {
1237- legendLink . setAttribute ( 'height' , legend . height ) ;
1238- }
1239- mapLayer . appendChild ( legendLink ) ;
1240- console . log ( 'Added legend link for selected style:' , selectedStyle . title ) ;
1241- }
1242- }
1243-
1244- // Add map-extent after license and legend links
12451263 mapLayer . appendChild ( mapExtent ) ;
12461264
12471265 viewer . appendChild ( mapLayer ) ;
0 commit comments