Changeset 19661 in josm
- Timestamp:
- 2026-10-24T13:37:30+02:00 (87 minutes ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java
r19289 r19661 3 3 4 4 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 5 import static org.openstreetmap.josm.tools.I18n.marktr; 5 6 import static org.openstreetmap.josm.tools.I18n.tr; 6 7 … … 58 59 */ 59 60 public class AddImageryLayerAction extends JosmAction implements AdaptableAction { 61 private static final String WMS_ERROR = marktr("WMS Error"); 60 62 private final transient ImageryInfo info; 61 63 … … 85 87 86 88 // change toolbar icon from if specified 87 String icon = info.getIcon(); 89 final String icon = info.getIcon(); 88 90 if (icon != null) { 89 91 new ImageProvider(icon).setOptional(true).getResourceAsync(result -> { … … 127 129 // specify which layer to use 128 130 if (Utils.isEmpty(info.getDefaultLayers())) { 129 WMTSTileSource tileSource = new WMTSTileSource(info); 130 DefaultLayer layerId = tileSource.userSelectLayer(); 131 final WMTSTileSource tileSource = new WMTSTileSource(info); 132 final DefaultLayer layerId = tileSource.userSelectLayer(); 131 133 if (layerId != null) { 132 ImageryInfo copy = new ImageryInfo(info); 134 final ImageryInfo copy = new ImageryInfo(info); 133 135 copy.setDefaultLayers(Collections.singletonList(layerId)); 134 String layerName = tileSource.getLayers().stream() 136 final String layerName = tileSource.getLayers().stream() 135 137 .filter(x -> x.getIdentifier().equals(layerId.getLayerName())) 136 138 .map(Layer::getUserTitle) … … 148 150 } 149 151 } catch (MalformedURLException ex) { 150 handleException(ex, tr("Invalid service URL."), tr( "WMS Error"), null);152 handleException(ex, tr("Invalid service URL."), tr(WMS_ERROR), null); 151 153 } catch (IOException ex) { 152 handleException(ex, tr("Could not retrieve WMS layer list."), tr( "WMS Error"), null);154 handleException(ex, tr("Could not retrieve WMS layer list."), tr(WMS_ERROR), null); 153 155 } catch (WMSGetCapabilitiesException ex) { 154 handleException(ex, tr("Could not parse WMS layer list."), tr( "WMS Error"),156 handleException(ex, tr("Could not parse WMS layer list."), tr(WMS_ERROR), 155 157 "Could not parse WMS layer list. Incoming data:\n" + ex.getIncomingData()); 156 158 } catch (WMTSGetCapabilitiesException ex) { … … 163 165 @Override 164 166 public void actionPerformed(ActionEvent e) { 165 if (!isEnabled()) return; 167 if (!isEnabled()) { 168 return; 169 } 166 170 ImageryLayer layer = null; 167 171 try { … … 210 214 final WMSLayerTree tree = new WMSLayerTree(); 211 215 212 Collection<String> wmsFormats = wms.getFormats(); 216 final Collection<String> wmsFormats = wms.getFormats(); 213 217 final JComboBox<String> formats = new JComboBox<>(wmsFormats.toArray(new String[0])); 214 218 formats.setSelectedItem(wms.getPreferredFormat()); 215 219 formats.setToolTipText(tr("Select image format for WMS layer")); 216 220 217 JCheckBox checkBounds = new JCheckBox(tr("Show only layers for current view"), true); 218 Runnable updateTree = () -> { 219 LatLon latLon = checkBounds.isSelected() && MainApplication.isDisplayingMapView() 221 final JCheckBox checkBounds = new JCheckBox(tr("Show only layers for current view"), true); 222 final Runnable updateTree = () -> { 223 final LatLon latLon = checkBounds.isSelected() && MainApplication.isDisplayingMapView() 220 224 ? MainApplication.getMap().mapView.getProjection().eastNorth2latlon(MainApplication.getMap().mapView.getCenter()) 221 225 : null; … … 228 232 229 233 if (!GraphicsEnvironment.isHeadless()) { 230 ExtendedDialog dialog = new ExtendedDialog(MainApplication.getMainFrame(), 234 final ExtendedDialog dialog = new ExtendedDialog(MainApplication.getMainFrame(), 231 235 tr("Select WMS layers"), tr("Add layers"), tr("Cancel")); 232 236 final JScrollPane scrollPane = new JScrollPane(tree.getLayerTree()); … … 260 264 return getWMSLayerInfo(info, AddImageryLayerAction::askToSelectLayers); 261 265 } catch (MalformedURLException ex) { 262 handleException(ex, tr("Invalid service URL."), tr( "WMS Error"), null);266 handleException(ex, tr("Invalid service URL."), tr(WMS_ERROR), null); 263 267 } catch (IOException ex) { 264 handleException(ex, tr("Could not retrieve WMS layer list."), tr( "WMS Error"), null);268 handleException(ex, tr("Could not retrieve WMS layer list."), tr(WMS_ERROR), null); 265 269 } catch (WMSGetCapabilitiesException ex) { 266 handleException(ex, tr("Could not parse WMS layer list."), tr( "WMS Error"),270 handleException(ex, tr("Could not parse WMS layer list."), tr(WMS_ERROR), 267 271 "Could not parse WMS layer list. Incoming data:\n" + ex.getIncomingData()); 268 272 } … … 286 290 final TemplatedWMSTileSource tileSource = new TemplatedWMSTileSource(info, ProjectionRegistry.getProjection()); 287 291 final WMSImagery wms = new WMSImagery(tileSource.getBaseUrl(), info.getCustomHttpHeaders()); 288 LayerSelection selection = choice.apply(wms); 292 final LayerSelection selection = choice.apply(wms); 289 293 if (selection == null) { 290 294 return null; … … 298 302 ); 299 303 300 String selectedLayers = selection.layers.stream() 304 final String selectedLayers = selection.layers.stream() 301 305 .map(LayerDetails::getName) 302 306 .collect(Collectors.joining(", ")); 303 307 // Use full copy of original Imagery info to copy all attributes. Only overwrite what's different 304 ImageryInfo ret = new ImageryInfo(info); 308 final ImageryInfo ret = new ImageryInfo(info); 305 309 ret.setUrl(url); 306 310 ret.setImageryType(ImageryType.WMS);
Note:
See TracChangeset
for help on using the changeset viewer.
