|
31 | 31 | import org.slf4j.LoggerFactory; |
32 | 32 | import org.springframework.stereotype.Service; |
33 | 33 | import org.springframework.transaction.annotation.Transactional; |
| 34 | +import org.springframework.web.util.UriComponentsBuilder; |
34 | 35 | import org.tailormap.api.controller.GeoServiceProxyController; |
35 | 36 | import org.tailormap.api.persistence.Application; |
36 | 37 | import org.tailormap.api.persistence.Configuration; |
|
48 | 49 | import org.tailormap.api.persistence.json.GeoServiceLayerSettings; |
49 | 50 | import org.tailormap.api.persistence.json.ServicePublishingSettings; |
50 | 51 | import org.tailormap.api.persistence.json.TileLayerHiDpiMode; |
| 52 | +import org.tailormap.api.persistence.json.WMSStyle; |
51 | 53 | import org.tailormap.api.repository.ApplicationRepository; |
52 | 54 | import org.tailormap.api.repository.ConfigurationRepository; |
53 | 55 | import org.tailormap.api.repository.FeatureSourceRepository; |
@@ -191,6 +193,23 @@ private String getLegendProxyUrl(Application application, AppTreeLayerNode appTr |
191 | 193 | + "/" + LEGEND.getValue(); |
192 | 194 | } |
193 | 195 |
|
| 196 | + private List<WMSStyle> getProxiedLegendStyles( |
| 197 | + Application application, AppTreeLayerNode appTreeLayerNode, List<WMSStyle> legendStyles) { |
| 198 | + String legendProxyUrl = getLegendProxyUrl(application, appTreeLayerNode); |
| 199 | + return legendStyles.stream() |
| 200 | + .map(style -> |
| 201 | + // Create a copy of the style so we don't mutate configuration objects |
| 202 | + new WMSStyle( |
| 203 | + style.getName(), |
| 204 | + style.getTitle(), |
| 205 | + style.getAbstractText(), |
| 206 | + UriComponentsBuilder.fromUriString(legendProxyUrl) |
| 207 | + .queryParam("STYLE", style.getName()) |
| 208 | + .build(true) |
| 209 | + .toUri())) |
| 210 | + .toList(); |
| 211 | + } |
| 212 | + |
194 | 213 | private class MapResponseLayerBuilder { |
195 | 214 | private final Application app; |
196 | 215 | private final MapResponse mapResponse; |
@@ -404,6 +423,13 @@ private boolean addAppLayerItem(AppTreeLayerNode layerRef) { |
404 | 423 | } |
405 | 424 | } |
406 | 425 |
|
| 426 | + List<WMSStyle> legendStyles = appLayerSettings.getSelectedStyles(); |
| 427 | + if (proxied && legendStyles != null) { |
| 428 | + // when proxied the urls must be passed through getProxiedLegendStyles to be accessible, |
| 429 | + // so don't pass the original style URLs to the frontend |
| 430 | + legendStyles = getProxiedLegendStyles(app, layerRef, legendStyles); |
| 431 | + } |
| 432 | + |
407 | 433 | SearchIndex searchIndex = null; |
408 | 434 | if (appLayerSettings.getSearchIndexId() != null) { |
409 | 435 | searchIndex = searchIndexRepository |
@@ -450,7 +476,7 @@ private boolean addAppLayerItem(AppTreeLayerNode layerRef) { |
450 | 476 | .webMercatorAvailable(webMercatorAvailable) |
451 | 477 | .tileset3dStyle(appLayerSettings.getTileset3dStyle()) |
452 | 478 | .hiddenFunctionality(appLayerSettings.getHiddenFunctionality()) |
453 | | - .styles(appLayerSettings.getSelectedStyles())); |
| 479 | + .styles(legendStyles)); |
454 | 480 |
|
455 | 481 | return true; |
456 | 482 | } |
|
0 commit comments