Changeset 7251 in josm


Ignore:
Timestamp:
2014-06-17T22:23:01+02:00 (10 years ago)
Author:
simon04
Message:

Remote control, load_and_zoom/zoom: allow to select objects by a search expression (use search=)

Location:
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/ImageryHandler.java

    r7005 r7251  
    126126    @Override
    127127    public String getUsage() {
    128         return "adds an imagery layer (e.g. WMS, TMS))";
     128        return "adds an imagery layer (e.g. WMS, TMS)";
    129129    }
    130130
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/LoadAndZoomHandler.java

    r7005 r7251  
    66import java.awt.geom.Area;
    77import java.awt.geom.Rectangle2D;
     8import java.util.Collection;
     9import java.util.Collections;
    810import java.util.HashSet;
    911import java.util.Set;
     
    1517import org.openstreetmap.josm.actions.downloadtasks.DownloadTask;
    1618import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler;
     19import org.openstreetmap.josm.actions.search.SearchCompiler;
    1720import org.openstreetmap.josm.data.Bounds;
    1821import org.openstreetmap.josm.data.coor.LatLon;
     
    7073    @Override
    7174    public String[] getOptionalParams() {
    72         return new String[] {"new_layer", "addtags", "select", "zoom_mode", "changeset_comment", "changeset_source"};
     75        return new String[] {"new_layer", "addtags", "select", "zoom_mode", "changeset_comment", "changeset_source", "search"};
    7376    }
    7477
     
    9194        } else {
    9295            return new String[] {
    93             "/zoom?left=8.19&right=8.20&top=48.605&bottom=48.590&select=node413602999"};
     96            "/zoom?left=8.19&right=8.20&top=48.605&bottom=48.590&select=node413602999",
     97            "/zoom?left=8.19&right=8.20&top=48.605&bottom=48.590&search=highway+OR+railway",
     98            };
    9499        }
    95100    }
     
    163168                    Set<OsmPrimitive> newSel = new HashSet<>();
    164169                    DataSet ds = Main.main.getCurrentDataSet();
    165                     if(ds == null) // e.g. download failed
     170                    if (ds == null) // e.g. download failed
    166171                        return;
    167172                    for (SimplePrimitiveId id : toSelect) {
     
    173178                    toSelect.clear();
    174179                    ds.setSelected(newSel);
    175                     if (PermissionPrefWithDefault.CHANGE_VIEWPORT.isAllowed()) {
    176                         // zoom_mode=(download|selection), defaults to selection
    177                         if (!"download".equals(args.get("zoom_mode")) && !newSel.isEmpty()) {
    178                             AutoScaleAction.autoScale("selection");
    179                         } else {
    180                             zoom(bbox);
    181                         }
    182                     }
     180                    zoom(newSel, bbox);
    183181                    if (Main.isDisplayingMapView() && Main.map.relationListDialog != null) {
    184182                        Main.map.relationListDialog.selectRelations(null); // unselect all relations to fix #7342
     
    188186                }
    189187            });
    190         } else if (PermissionPrefWithDefault.CHANGE_VIEWPORT.isAllowed()) {
     188        } else if (args.containsKey("search") && PermissionPrefWithDefault.CHANGE_SELECTION.isAllowed()) {
     189            try {
     190                final DataSet ds = Main.main.getCurrentDataSet();
     191                final SearchCompiler.Match search = SearchCompiler.compile(args.get("search"), false, false);
     192                final Collection<OsmPrimitive> filteredPrimitives = Utils.filter(ds.allPrimitives(), search);
     193                ds.setSelected(filteredPrimitives);
     194                zoom(filteredPrimitives, bbox);
     195            } catch (SearchCompiler.ParseError ex) {
     196                Main.error(ex);
     197                throw new RequestHandlerErrorException(ex);
     198            }
     199        } else {
    191200            // after downloading, zoom to downloaded area.
    192             zoom(bbox);
     201            zoom(Collections.<OsmPrimitive>emptySet(), bbox);
    193202        }
    194203
     
    213222    }
    214223
    215     protected void zoom(final Bounds bounds) {
    216         // make sure this isn't called unless there *is* a MapView
    217         if (Main.isDisplayingMapView()) {
     224    protected void zoom(Collection<OsmPrimitive> primitives, final Bounds bbox) {
     225        if (!PermissionPrefWithDefault.CHANGE_VIEWPORT.isAllowed()) {
     226            return;
     227        }
     228        // zoom_mode=(download|selection), defaults to selection
     229        if (!"download".equals(args.get("zoom_mode")) && !primitives.isEmpty()) {
     230            AutoScaleAction.autoScale("selection");
     231        } else if (Main.isDisplayingMapView()) {
     232            // make sure this isn't called unless there *is* a MapView
    218233            GuiHelper.executeByMainWorkerInEDT(new Runnable() {
    219234                @Override
    220235                public void run() {
    221                     BoundingXYVisitor bbox = new BoundingXYVisitor();
    222                     bbox.visit(bounds);
    223                     Main.map.mapView.recalculateCenterScale(bbox);
     236                    BoundingXYVisitor bbox1 = new BoundingXYVisitor();
     237                    bbox1.visit(bbox);
     238                    Main.map.mapView.recalculateCenterScale(bbox1);
    224239                }
    225240            });
Note: See TracChangeset for help on using the changeset viewer.