Changeset 18371 in josm for trunk/src/org
- Timestamp:
- 2022-02-09T17:03:51+01:00 (3 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data/imagery
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/imagery/ImageryPatterns.java
r17578 r18371 5 5 import static org.openstreetmap.josm.tools.I18n.tr; 6 6 7 import java.io.IOException; 7 8 import java.util.Arrays; 8 9 import java.util.Map; … … 10 11 import java.util.regex.Matcher; 11 12 import java.util.regex.Pattern; 13 14 import org.openstreetmap.gui.jmapviewer.FeatureAdapter; 12 15 13 16 /** … … 30 33 static final Pattern PATTERN_TIME = Pattern.compile("\\{time\\}"); // Sentinel-2 31 34 static final Pattern PATTERN_PARAM = Pattern.compile("\\{([^}]+)\\}"); 35 /** 36 * The api key pattern is used to allow us to quickly switch apikeys. This is functionally the same as the pattern 37 * in {@link org.openstreetmap.gui.jmapviewer.tilesources.TemplatedTMSTileSource}. 38 */ 39 static final Pattern PATTERN_API_KEY = Pattern.compile("\\{apikey}"); 32 40 // CHECKSTYLE.ON: SingleSpaceSeparator 33 41 … … 35 43 PATTERN_HEADER, PATTERN_PROJ, PATTERN_WKID, PATTERN_BBOX, 36 44 PATTERN_W, PATTERN_S, PATTERN_E, PATTERN_N, 37 PATTERN_WIDTH, PATTERN_HEIGHT, PATTERN_TIME 45 PATTERN_WIDTH, PATTERN_HEIGHT, PATTERN_TIME, 46 PATTERN_API_KEY 38 47 }; 39 48 40 49 private static final Pattern[] ALL_WMTS_PATTERNS = { 41 PATTERN_HEADER 50 PATTERN_HEADER, PATTERN_API_KEY 42 51 }; 43 52 … … 75 84 return output.toString(); 76 85 } 86 87 /** 88 * Handle the {@link #PATTERN_API_KEY} replacement 89 * @param id The id of the info 90 * @param url The templated url 91 * @return The templated url with {@link #PATTERN_API_KEY} replaced 92 */ 93 static String handleApiKeyTemplate(final String id, final String url) { 94 if (id != null && url != null) { 95 try { 96 final String apiKey = FeatureAdapter.retrieveApiKey(id); 97 return PATTERN_API_KEY.matcher(url).replaceAll(apiKey); 98 } catch (IOException | NullPointerException e) { 99 // Match rough behavior in JMapViewer TemplatedTMSTileSource, but with better error message. 100 throw new IllegalArgumentException(tr("Could not retrieve API key for imagery with id={0}. Cannot add layer.", id), e); 101 } 102 } 103 return url; 104 } 77 105 } -
trunk/src/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSource.java
r17578 r18371 45 45 this.headers.putAll(info.getCustomHttpHeaders()); 46 46 this.date = info.getDate(); 47 this.baseUrl = ImageryPatterns.handle HeaderTemplate(baseUrl, headers);47 this.baseUrl = ImageryPatterns.handleApiKeyTemplate(info.getId(), ImageryPatterns.handleHeaderTemplate(baseUrl, headers)); 48 48 initProjection(); 49 49 // Bounding box coordinates have to be switched for WMS 1.3.0 EPSG:4326. -
trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java
r17578 r18371 361 361 CheckParameterUtil.ensureThat(info.getDefaultLayers().size() < 2, "At most 1 default layer for WMTS is supported"); 362 362 this.headers.putAll(info.getCustomHttpHeaders()); 363 this.baseUrl = GetCapabilitiesParseHelper.normalizeCapabilitiesUrl(ImageryPatterns.handleHeaderTemplate(info.getUrl(), headers)); 363 this.baseUrl = GetCapabilitiesParseHelper.normalizeCapabilitiesUrl( 364 ImageryPatterns.handleApiKeyTemplate(info.getId(), ImageryPatterns.handleHeaderTemplate(info.getUrl(), headers))); 364 365 WMTSCapabilities capabilities = getCapabilities(baseUrl, headers); 365 366 this.layers = capabilities.getLayers();
Note:
See TracChangeset
for help on using the changeset viewer.