Changeset 33455 in osm for applications


Ignore:
Timestamp:
2017-07-18T13:34:16+02:00 (7 years ago)
Author:
giackserva
Message:

[pt_assistant] #josm14904 - sort edge ways by connectivity

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/actions/EdgeSelectionAction.java

    r33429 r33455  
    1111import java.util.List;
    1212import java.util.Set;
     13import java.util.stream.Collectors;
    1314
    1415import org.openstreetmap.josm.Main;
     
    1617import org.openstreetmap.josm.data.osm.DataSet;
    1718import org.openstreetmap.josm.data.osm.OsmPrimitive;
     19import org.openstreetmap.josm.data.osm.RelationMember;
    1820import org.openstreetmap.josm.data.osm.Way;
     21import org.openstreetmap.josm.gui.dialogs.relation.sort.RelationSorter;
    1922import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils;
    2023import org.openstreetmap.josm.tools.ImageProvider;
     
    3033public class EdgeSelectionAction extends MapMode {
    3134
    32     private static final String mapModeName = "Edge Selection";
     35    private static final String MAP_MODE_NAME = "Edge Selection";
    3336    private static final long serialVersionUID = 2414977774504904238L;
    3437
     
    3942
    4043    public EdgeSelectionAction() {
    41         super(tr(mapModeName), "edgeSelection", tr(mapModeName),
     44        super(tr(MAP_MODE_NAME), "edgeSelection", tr(MAP_MODE_NAME),
    4245                Shortcut.registerShortcut("mapmode:edge_selection",
    43                         tr("Mode: {0}", tr(mapModeName)),
     46                        tr("Mode: {0}", tr(MAP_MODE_NAME)),
    4447                        KeyEvent.VK_K, Shortcut.CTRL),
    4548                ImageProvider.getCursor("normal", "selection"));
     
    8083
    8184        edge.add(initial);
     85        edge = sortEdgeWays(edge);
    8286        return edge;
     87    }
     88
     89    private List<Way> sortEdgeWays(List<Way> edge) {
     90        List<RelationMember> members =
     91                edge.stream()
     92                    .map(w -> new RelationMember("", w))
     93                    .collect(Collectors.toList());
     94        List<RelationMember> sorted = new RelationSorter().sortMembers(members);
     95        return sorted.stream()
     96                .map(RelationMember::getWay)
     97                .collect(Collectors.toList());
    8398    }
    8499
Note: See TracChangeset for help on using the changeset viewer.