| 1 | package org.openstreetmap.josm.io.remotecontrol.handler;
|
|---|
| 2 |
|
|---|
| 3 | import static org.openstreetmap.josm.tools.I18n.tr;
|
|---|
| 4 |
|
|---|
| 5 | import java.util.LinkedList;
|
|---|
| 6 | import java.util.List;
|
|---|
| 7 | import org.openstreetmap.josm.Main;
|
|---|
| 8 | import org.openstreetmap.josm.actions.AutoScaleAction;
|
|---|
| 9 | import org.openstreetmap.josm.command.AddCommand;
|
|---|
| 10 | import org.openstreetmap.josm.command.Command;
|
|---|
| 11 | import org.openstreetmap.josm.command.SequenceCommand;
|
|---|
| 12 | import org.openstreetmap.josm.data.coor.LatLon;
|
|---|
| 13 | import org.openstreetmap.josm.data.osm.Node;
|
|---|
| 14 | import org.openstreetmap.josm.data.osm.Way;
|
|---|
| 15 |
|
|---|
| 16 | /**
|
|---|
| 17 | * Adds a way to the current dataset. For instance, {@code /add_way?way=lat1,lon2;lat2,lon2}.
|
|---|
| 18 | */
|
|---|
| 19 | public class AddWayHandler extends RequestHandler {
|
|---|
| 20 |
|
|---|
| 21 | public static final String command = "add_way";
|
|---|
| 22 |
|
|---|
| 23 | @Override
|
|---|
| 24 | public String[] getMandatoryParams() {
|
|---|
| 25 | return new String[]{"way"};
|
|---|
| 26 | }
|
|---|
| 27 |
|
|---|
| 28 | @Override
|
|---|
| 29 | protected void handleRequest() throws RequestHandlerErrorException, RequestHandlerBadRequestException {
|
|---|
| 30 | Way way = new Way();
|
|---|
| 31 | List<Command> commands = new LinkedList<Command>();
|
|---|
| 32 | for (String coordinatesString : args.get("way").split(";\\s*")) {
|
|---|
| 33 | String[] coordinates = coordinatesString.split(",\\s*", 2);
|
|---|
| 34 | double lat = Double.parseDouble(coordinates[0]);
|
|---|
| 35 | double lon = Double.parseDouble(coordinates[1]);
|
|---|
| 36 | Node node = new Node(new LatLon(lat, lon));
|
|---|
| 37 | way.addNode(node);
|
|---|
| 38 | commands.add(new AddCommand(node));
|
|---|
| 39 | }
|
|---|
| 40 | commands.add(new AddCommand(way));
|
|---|
| 41 | Main.main.undoRedo.add(new SequenceCommand(tr("Add way"), commands));
|
|---|
| 42 | Main.main.getCurrentDataSet().setSelected(way);
|
|---|
| 43 | if (Main.pref.getBoolean(LoadAndZoomHandler.changeViewportPermissionKey, LoadAndZoomHandler.changeViewportPermissionDefault)) {
|
|---|
| 44 | AutoScaleAction.autoScale("selection");
|
|---|
| 45 | } else {
|
|---|
| 46 | Main.map.mapView.repaint();
|
|---|
| 47 | }
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | @Override
|
|---|
| 51 | public String getPermissionMessage() {
|
|---|
| 52 | return tr("Remote Control has been asked to create a new way.");
|
|---|
| 53 | }
|
|---|
| 54 | }
|
|---|