Ticket #23913: 23913.patch
File 23913.patch, 2.5 KB (added by , 5 weeks ago) |
---|
-
src/org/openstreetmap/gui/jmapviewer/tilesources/BingAerialTileSource.java
75 75 private String[] subdomains; 76 76 private String brandLogoUri; 77 77 private String layer = "Aerial"; 78 private final String imageryId = "Bing"; 78 79 79 80 /** 80 81 * Constructs a new {@code BingAerialTileSource}. … … 131 132 protected URL getAttributionUrl() throws MalformedURLException { 132 133 try { 133 134 return new URI(FeatureAdapter.getSetting(METADATA_API_SETTING, METADATA_API_URL) 134 .replace(API_KEY_PLACEHOLDER, FeatureAdapter.getSetting(API_KEY_SETTING, API_KEY))135 .replace(API_KEY_PLACEHOLDER, getKey()) 135 136 .replace(API_KEY_LAYER, this.layer)).toURL(); 136 137 } catch (URISyntaxException e) { 137 138 MalformedURLException malformedURLException = new MalformedURLException(e.getMessage()); … … 140 141 } 141 142 } 142 143 144 /** 145 * Get the API key for Bing imagery 146 * Order of preference is as follows: 147 * <ol> 148 * <li>Custom API key provided by {@link FeatureAdapter#getSetting(String, String)} via {@link #API_KEY_SETTING}</li> 149 * <li>API key provided by {@link FeatureAdapter#retrieveApiKey(String)}</li> 150 * <li>The hardcoded API key. This should not be used whenever possible.</li> 151 * </ol> 152 * @return The API key to use 153 */ 154 private String getKey() { 155 // Preference order for key 156 // 1. Custom API key 157 // 2. Remote API key 158 // 3. Hardcoded API key 159 final String customKey = FeatureAdapter.getSetting(API_KEY_SETTING, API_KEY); 160 String key; 161 try { 162 key = FeatureAdapter.retrieveApiKey(imageryId); // id is getURL from info, for some reason. Probably Bing. 163 if (!API_KEY.equals(customKey)) { 164 key = customKey; 165 } 166 } catch (IOException ioException) { 167 FeatureAdapter.getLogger(this.getClass()).log(Level.WARNING, "Failed to retrieve api key", ioException); 168 key = customKey; 169 } 170 return key; 171 } 172 143 173 protected List<Attribution> parseAttributionText(InputSource xml) throws IOException { 144 174 try { 145 175 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();