Changeset 17594 in josm for trunk/src


Ignore:
Timestamp:
2021-03-20T11:50:08+01:00 (4 years ago)
Author:
simon04
Message:

fix #19857 - Select WMS layers: option to only show layers for current view

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java

    r16629 r17594  
    2020import java.util.stream.Collectors;
    2121
     22import javax.swing.JCheckBox;
    2223import javax.swing.JComboBox;
    2324import javax.swing.JOptionPane;
     
    2526import javax.swing.JScrollPane;
    2627
     28import org.openstreetmap.josm.data.coor.LatLon;
    2729import org.openstreetmap.josm.data.imagery.DefaultLayer;
    2830import org.openstreetmap.josm.data.imagery.ImageryInfo;
     
    203205    private static LayerSelection askToSelectLayers(WMSImagery wms) {
    204206        final WMSLayerTree tree = new WMSLayerTree();
    205         tree.updateTree(wms);
    206207
    207208        Collection<String> wmsFormats = wms.getFormats();
     
    209210        formats.setSelectedItem(wms.getPreferredFormat());
    210211        formats.setToolTipText(tr("Select image format for WMS layer"));
     212
     213        JCheckBox checkBounds = new JCheckBox(tr("Show only layers for current view"), true);
     214        Runnable updateTree = () -> {
     215            LatLon latLon = checkBounds.isSelected() && MainApplication.isDisplayingMapView()
     216                    ? MainApplication.getMap().mapView.getProjection().eastNorth2latlon(MainApplication.getMap().mapView.getCenter())
     217                    : null;
     218            tree.setCheckBounds(latLon);
     219            tree.updateTree(wms);
     220            System.out.println(wms);
     221        };
     222        checkBounds.addActionListener(ignore -> updateTree.run());
     223        updateTree.run();
    211224
    212225        if (!GraphicsEnvironment.isHeadless()) {
     
    217230            final JPanel panel = new JPanel(new GridBagLayout());
    218231            panel.add(scrollPane, GBC.eol().fill());
     232            panel.add(checkBounds, GBC.eol().fill(GBC.HORIZONTAL));
    219233            panel.add(formats, GBC.eol().fill(GBC.HORIZONTAL));
    220234            dialog.setContent(panel);
  • trunk/src/org/openstreetmap/josm/gui/preferences/imagery/WMSLayerTree.java

    r13824 r17594  
    44import java.awt.Component;
    55import java.util.Collection;
     6import java.util.Comparator;
    67import java.util.LinkedList;
    78import java.util.List;
     
    1617import javax.swing.tree.TreePath;
    1718
     19import org.openstreetmap.josm.data.coor.LatLon;
    1820import org.openstreetmap.josm.data.imagery.LayerDetails;
    1921import org.openstreetmap.josm.io.imagery.WMSImagery;
     
    2729    private final JTree layerTree = new JTree(treeData);
    2830    private final List<LayerDetails> selectedLayers = new LinkedList<>();
     31    private LatLon checkBounds = null;
    2932
    3033    /**
     
    6063    }
    6164
     65    /**
     66     * Set coordinate to check {@linkplain LayerDetails#getBounds() layer bounds}
     67     * when {@linkplain #updateTree updating the tree}.
     68     * @param checkBounds the coordinate
     69     */
     70    public void setCheckBounds(LatLon checkBounds) {
     71        this.checkBounds = checkBounds;
     72    }
     73
    6274    void addLayersToTreeData(MutableTreeNode parent, Collection<LayerDetails> layers) {
    6375        for (LayerDetails layerDetails : layers.stream()
    64                 .sorted((l1, l2) -> -1 * l1.toString().compareTo(l2.toString()))
     76                .filter(l -> checkBounds == null || l.getBounds() == null || l.getBounds().contains(checkBounds))
     77                .sorted(Comparator.comparing(LayerDetails::toString).reversed())
    6578                .toArray(LayerDetails[]::new)
    6679                ) {
     
    89102    public void updateTreeList(Collection<LayerDetails> layers) {
    90103        addLayersToTreeData(getTreeRootNode(), layers);
     104        treeData.nodeStructureChanged(getTreeRootNode());
    91105        getLayerTree().expandRow(0);
    92106        getLayerTree().expandRow(1);
Note: See TracChangeset for help on using the changeset viewer.