### Eclipse Workspace Patch 1.0
#P josm
diff --git src/org/openstreetmap/josm/actions/AddImageryLayerAction.java src/org/openstreetmap/josm/actions/AddImageryLayerAction.java
index d6fe8be..18021dc 100644
|
|
|
|
| 57 | 57 | * @since 3715 |
| 58 | 58 | */ |
| 59 | 59 | public class AddImageryLayerAction extends JosmAction implements AdaptableAction { |
| | 60 | private static final String WMS_ERROR = "WMS Error"; |
| 60 | 61 | private final transient ImageryInfo info; |
| 61 | 62 | |
| 62 | 63 | static class SelectWmsLayersDialog extends ExtendedDialog { |
| … |
… |
|
| 84 | 85 | installAdapters(); |
| 85 | 86 | |
| 86 | 87 | // change toolbar icon from if specified |
| 87 | | String icon = info.getIcon(); |
| | 88 | final String icon = info.getIcon(); |
| 88 | 89 | if (icon != null) { |
| 89 | 90 | new ImageProvider(icon).setOptional(true).getResourceAsync(result -> { |
| 90 | 91 | if (result != null) { |
| … |
… |
|
| 126 | 127 | case WMTS: |
| 127 | 128 | // specify which layer to use |
| 128 | 129 | if (Utils.isEmpty(info.getDefaultLayers())) { |
| 129 | | WMTSTileSource tileSource = new WMTSTileSource(info); |
| 130 | | DefaultLayer layerId = tileSource.userSelectLayer(); |
| | 130 | final WMTSTileSource tileSource = new WMTSTileSource(info); |
| | 131 | final DefaultLayer layerId = tileSource.userSelectLayer(); |
| 131 | 132 | if (layerId != null) { |
| 132 | | ImageryInfo copy = new ImageryInfo(info); |
| | 133 | final ImageryInfo copy = new ImageryInfo(info); |
| 133 | 134 | copy.setDefaultLayers(Collections.singletonList(layerId)); |
| 134 | | String layerName = tileSource.getLayers().stream() |
| | 135 | final String layerName = tileSource.getLayers().stream() |
| 135 | 136 | .filter(x -> x.getIdentifier().equals(layerId.getLayerName())) |
| 136 | 137 | .map(Layer::getUserTitle) |
| 137 | 138 | .findFirst() |
| … |
… |
|
| 147 | 148 | return info; |
| 148 | 149 | } |
| 149 | 150 | } catch (MalformedURLException ex) { |
| 150 | | handleException(ex, tr("Invalid service URL."), tr("WMS Error"), null); |
| | 151 | handleException(ex, tr("Invalid service URL."), tr(WMS_ERROR), null); |
| 151 | 152 | } catch (IOException ex) { |
| 152 | | handleException(ex, tr("Could not retrieve WMS layer list."), tr("WMS Error"), null); |
| | 153 | handleException(ex, tr("Could not retrieve WMS layer list."), tr(WMS_ERROR), null); |
| 153 | 154 | } catch (WMSGetCapabilitiesException ex) { |
| 154 | | handleException(ex, tr("Could not parse WMS layer list."), tr("WMS Error"), |
| | 155 | handleException(ex, tr("Could not parse WMS layer list."), tr(WMS_ERROR), |
| 155 | 156 | "Could not parse WMS layer list. Incoming data:\n" + ex.getIncomingData()); |
| 156 | 157 | } catch (WMTSGetCapabilitiesException ex) { |
| 157 | 158 | handleException(ex, tr("Could not parse WMTS layer list."), tr("WMTS Error"), |
| … |
… |
|
| 162 | 163 | |
| 163 | 164 | @Override |
| 164 | 165 | public void actionPerformed(ActionEvent e) { |
| 165 | | if (!isEnabled()) return; |
| | 166 | if (!isEnabled()) { |
| | 167 | return; |
| | 168 | } |
| 166 | 169 | ImageryLayer layer = null; |
| 167 | 170 | try { |
| 168 | 171 | final ImageryInfo infoToAdd = convertImagery(info); |
| … |
… |
|
| 209 | 212 | private static LayerSelection askToSelectLayers(WMSImagery wms) { |
| 210 | 213 | final WMSLayerTree tree = new WMSLayerTree(); |
| 211 | 214 | |
| 212 | | Collection<String> wmsFormats = wms.getFormats(); |
| | 215 | final Collection<String> wmsFormats = wms.getFormats(); |
| 213 | 216 | final JComboBox<String> formats = new JComboBox<>(wmsFormats.toArray(new String[0])); |
| 214 | 217 | formats.setSelectedItem(wms.getPreferredFormat()); |
| 215 | 218 | formats.setToolTipText(tr("Select image format for WMS layer")); |
| 216 | 219 | |
| 217 | | JCheckBox checkBounds = new JCheckBox(tr("Show only layers for current view"), true); |
| 218 | | Runnable updateTree = () -> { |
| 219 | | LatLon latLon = checkBounds.isSelected() && MainApplication.isDisplayingMapView() |
| | 220 | final JCheckBox checkBounds = new JCheckBox(tr("Show only layers for current view"), true); |
| | 221 | final Runnable updateTree = () -> { |
| | 222 | final LatLon latLon = checkBounds.isSelected() && MainApplication.isDisplayingMapView() |
| 220 | 223 | ? MainApplication.getMap().mapView.getProjection().eastNorth2latlon(MainApplication.getMap().mapView.getCenter()) |
| 221 | 224 | : null; |
| 222 | 225 | tree.setCheckBounds(latLon); |
| … |
… |
|
| 227 | 230 | updateTree.run(); |
| 228 | 231 | |
| 229 | 232 | if (!GraphicsEnvironment.isHeadless()) { |
| 230 | | ExtendedDialog dialog = new ExtendedDialog(MainApplication.getMainFrame(), |
| | 233 | final ExtendedDialog dialog = new ExtendedDialog(MainApplication.getMainFrame(), |
| 231 | 234 | tr("Select WMS layers"), tr("Add layers"), tr("Cancel")); |
| 232 | 235 | final JScrollPane scrollPane = new JScrollPane(tree.getLayerTree()); |
| 233 | 236 | scrollPane.setPreferredSize(new Dimension(400, 400)); |
| … |
… |
|
| 259 | 262 | try { |
| 260 | 263 | return getWMSLayerInfo(info, AddImageryLayerAction::askToSelectLayers); |
| 261 | 264 | } catch (MalformedURLException ex) { |
| 262 | | handleException(ex, tr("Invalid service URL."), tr("WMS Error"), null); |
| | 265 | handleException(ex, tr("Invalid service URL."), tr(WMS_ERROR), null); |
| 263 | 266 | } catch (IOException ex) { |
| 264 | | handleException(ex, tr("Could not retrieve WMS layer list."), tr("WMS Error"), null); |
| | 267 | handleException(ex, tr("Could not retrieve WMS layer list."), tr(WMS_ERROR), null); |
| 265 | 268 | } catch (WMSGetCapabilitiesException ex) { |
| 266 | | handleException(ex, tr("Could not parse WMS layer list."), tr("WMS Error"), |
| | 269 | handleException(ex, tr("Could not parse WMS layer list."), tr(WMS_ERROR), |
| 267 | 270 | "Could not parse WMS layer list. Incoming data:\n" + ex.getIncomingData()); |
| 268 | 271 | } |
| 269 | 272 | return null; |
| … |
… |
|
| 285 | 288 | // We need to get the URL with {apikey} replaced. See #22642. |
| 286 | 289 | final TemplatedWMSTileSource tileSource = new TemplatedWMSTileSource(info, ProjectionRegistry.getProjection()); |
| 287 | 290 | final WMSImagery wms = new WMSImagery(tileSource.getBaseUrl(), info.getCustomHttpHeaders()); |
| 288 | | LayerSelection selection = choice.apply(wms); |
| | 291 | final LayerSelection selection = choice.apply(wms); |
| 289 | 292 | if (selection == null) { |
| 290 | 293 | return null; |
| 291 | 294 | } |
| … |
… |
|
| 297 | 300 | selection.transparent |
| 298 | 301 | ); |
| 299 | 302 | |
| 300 | | String selectedLayers = selection.layers.stream() |
| | 303 | final String selectedLayers = selection.layers.stream() |
| 301 | 304 | .map(LayerDetails::getName) |
| 302 | 305 | .collect(Collectors.joining(", ")); |
| 303 | 306 | // Use full copy of original Imagery info to copy all attributes. Only overwrite what's different |
| 304 | | ImageryInfo ret = new ImageryInfo(info); |
| | 307 | final ImageryInfo ret = new ImageryInfo(info); |
| 305 | 308 | ret.setUrl(url); |
| 306 | 309 | ret.setImageryType(ImageryType.WMS); |
| 307 | 310 | ret.setName(info.getName() + " - " + selectedLayers); |