kopia lustrzana https://github.com/JOSM/MapWithAI
Mass edit for formatting
Signed-off-by: Taylor Smock <taylor.smock@kaart.com>pull/1/head
rodzic
63bc9e1d06
commit
42109b4533
|
@ -13,30 +13,30 @@ import org.openstreetmap.josm.plugins.rapid.backend.RapiDDataUtils;
|
||||||
import org.openstreetmap.josm.plugins.rapid.backend.RapiDMoveAction;
|
import org.openstreetmap.josm.plugins.rapid.backend.RapiDMoveAction;
|
||||||
|
|
||||||
public final class RapiDPlugin extends Plugin {
|
public final class RapiDPlugin extends Plugin {
|
||||||
/** The name of the plugin */
|
/** The name of the plugin */
|
||||||
public static final String NAME = "RapiD";
|
public static final String NAME = "RapiD";
|
||||||
private static String versionInfo;
|
private static String versionInfo;
|
||||||
|
|
||||||
private final PreferenceSetting preferences = new RapiDPreferences();
|
private final PreferenceSetting preferences = new RapiDPreferences();
|
||||||
|
|
||||||
public RapiDPlugin(PluginInformation info) {
|
public RapiDPlugin(PluginInformation info) {
|
||||||
super(info);
|
super(info);
|
||||||
|
|
||||||
JMenu dataMenu = MainApplication.getMenu().dataMenu;
|
JMenu dataMenu = MainApplication.getMenu().dataMenu;
|
||||||
MainMenu.add(dataMenu, new RapiDAction(), false);
|
MainMenu.add(dataMenu, new RapiDAction(), false);
|
||||||
MainMenu.add(dataMenu, new RapiDMoveAction(), false);
|
MainMenu.add(dataMenu, new RapiDMoveAction(), false);
|
||||||
|
|
||||||
RapiDDataUtils.addRapiDPaintStyles();
|
RapiDDataUtils.addRapiDPaintStyles();
|
||||||
|
|
||||||
versionInfo = info.localversion;
|
versionInfo = info.localversion;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PreferenceSetting getPreferenceSetting() {
|
public PreferenceSetting getPreferenceSetting() {
|
||||||
return preferences;
|
return preferences;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getVersionInfo() {
|
public static String getVersionInfo() {
|
||||||
return versionInfo;
|
return versionInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,67 +17,65 @@ import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting;
|
||||||
import org.openstreetmap.josm.plugins.rapid.backend.RapiDDataUtils;
|
import org.openstreetmap.josm.plugins.rapid.backend.RapiDDataUtils;
|
||||||
|
|
||||||
public class RapiDPreferences implements SubPreferenceSetting {
|
public class RapiDPreferences implements SubPreferenceSetting {
|
||||||
|
private final JLabel rapidApiUrl = new JLabel(tr("RapiD API URL"));
|
||||||
|
private final JComboBox<String> possibleRapidApiUrl = new JComboBox<>();
|
||||||
|
|
||||||
private final JLabel rapidApiUrl = new JLabel(tr("RapiD API URL"));
|
private final JLabel switchLayer = new JLabel(tr("Automatically switch layers"));
|
||||||
private final JComboBox<String> possibleRapidApiUrl = new JComboBox<>();
|
private final JCheckBox switchLayerCheckBox = new JCheckBox();
|
||||||
|
|
||||||
private final JLabel switchLayer = new JLabel(tr("Automatically switch layers"));
|
@Override
|
||||||
private final JCheckBox switchLayerCheckBox = new JCheckBox();
|
public void addGui(PreferenceTabbedPane gui) {
|
||||||
|
final JPanel container = new JPanel(new GridBagLayout());
|
||||||
|
container.setAlignmentY(JPanel.TOP_ALIGNMENT);
|
||||||
|
final GridBagConstraints constraints = new GridBagConstraints();
|
||||||
|
|
||||||
@Override
|
for (String url : RapiDDataUtils.getRapiDURLs()) {
|
||||||
public void addGui(PreferenceTabbedPane gui) {
|
possibleRapidApiUrl.addItem(url);
|
||||||
final JPanel container = new JPanel(new GridBagLayout());
|
}
|
||||||
container.setAlignmentY(JPanel.TOP_ALIGNMENT);
|
|
||||||
final GridBagConstraints constraints = new GridBagConstraints();
|
|
||||||
|
|
||||||
for (String url : RapiDDataUtils.getRapiDURLs()) {
|
possibleRapidApiUrl.setEditable(true);
|
||||||
possibleRapidApiUrl.addItem(url);
|
possibleRapidApiUrl.setPrototypeDisplayValue("https://example.url/some/end/point");
|
||||||
}
|
possibleRapidApiUrl.setSelectedItem(RapiDDataUtils.getRapiDURL());
|
||||||
|
|
||||||
possibleRapidApiUrl.setEditable(true);
|
switchLayerCheckBox.setSelected(RapiDDataUtils.getSwitchLayers());
|
||||||
possibleRapidApiUrl.setPrototypeDisplayValue("https://example.url/some/end/point");
|
|
||||||
possibleRapidApiUrl.setSelectedItem(RapiDDataUtils.getRapiDURL());
|
|
||||||
|
|
||||||
switchLayerCheckBox.setSelected(RapiDDataUtils.getSwitchLayers());
|
constraints.gridx = 0;
|
||||||
|
constraints.gridy = 0;
|
||||||
|
constraints.weightx = .1;
|
||||||
|
constraints.weighty = 0;
|
||||||
|
constraints.insets = new Insets(5, 10, 5, 10);
|
||||||
|
constraints.anchor = GridBagConstraints.EAST;
|
||||||
|
constraints.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
container.add(rapidApiUrl, constraints);
|
||||||
|
|
||||||
constraints.gridx = 0;
|
constraints.gridx++;
|
||||||
constraints.gridy = 0;
|
constraints.weightx = 1;
|
||||||
constraints.weightx = .1;
|
container.add(possibleRapidApiUrl, constraints);
|
||||||
constraints.weighty = 0;
|
|
||||||
constraints.insets = new Insets(5, 10, 5, 10);
|
|
||||||
constraints.anchor = GridBagConstraints.EAST;
|
|
||||||
constraints.fill = GridBagConstraints.HORIZONTAL;
|
|
||||||
container.add(rapidApiUrl, constraints);
|
|
||||||
|
|
||||||
constraints.gridx++;
|
constraints.gridx--;
|
||||||
constraints.weightx = 1;
|
constraints.gridy++;
|
||||||
container.add(possibleRapidApiUrl, constraints);
|
container.add(switchLayer, constraints);
|
||||||
|
|
||||||
constraints.gridx--;
|
constraints.gridx++;
|
||||||
constraints.gridy++;
|
container.add(switchLayerCheckBox, constraints);
|
||||||
container.add(switchLayer, constraints);
|
|
||||||
|
|
||||||
constraints.gridx++;
|
getTabPreferenceSetting(gui).addSubTab(this, "RapiD", container);
|
||||||
container.add(switchLayerCheckBox, constraints);
|
}
|
||||||
|
|
||||||
getTabPreferenceSetting(gui).addSubTab(this, "RapiD", container);
|
@Override
|
||||||
}
|
public boolean ok() {
|
||||||
|
RapiDDataUtils.setRapiDUrl((String) possibleRapidApiUrl.getSelectedItem());
|
||||||
|
RapiDDataUtils.setSwitchLayers(switchLayerCheckBox.isSelected());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean ok() {
|
public boolean isExpert() {
|
||||||
RapiDDataUtils.setRapiDUrl((String) possibleRapidApiUrl.getSelectedItem());
|
return false;
|
||||||
RapiDDataUtils.setSwitchLayers(switchLayerCheckBox.isSelected());
|
}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isExpert() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TabPreferenceSetting getTabPreferenceSetting(PreferenceTabbedPane gui) {
|
|
||||||
return gui.getPluginPreference();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TabPreferenceSetting getTabPreferenceSetting(PreferenceTabbedPane gui) {
|
||||||
|
return gui.getPluginPreference();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,89 +15,91 @@ import org.openstreetmap.josm.plugins.rapid.RapiDPlugin;
|
||||||
import org.openstreetmap.josm.tools.Shortcut;
|
import org.openstreetmap.josm.tools.Shortcut;
|
||||||
|
|
||||||
public class RapiDAction extends JosmAction {
|
public class RapiDAction extends JosmAction {
|
||||||
/** UID */
|
/** UID */
|
||||||
private static final long serialVersionUID = 8886705479253246588L;
|
private static final long serialVersionUID = 8886705479253246588L;
|
||||||
|
|
||||||
public RapiDAction() {
|
private static final Object layerLock = new Object();
|
||||||
super(RapiDPlugin.NAME, null, tr("Get data from RapiD"),
|
|
||||||
Shortcut.registerShortcut("data:rapid", tr("Data: {0}", tr("RapiD")), KeyEvent.VK_R, Shortcut.SHIFT),
|
|
||||||
true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public RapiDAction() {
|
||||||
public void actionPerformed(ActionEvent event) {
|
super(RapiDPlugin.NAME, null, tr("Get data from RapiD"),
|
||||||
final RapiDLayer layer = getLayer(true);
|
Shortcut.registerShortcut("data:rapid", tr("Data: {0}", tr("RapiD")), KeyEvent.VK_R, Shortcut.SHIFT),
|
||||||
getRapiDData(layer);
|
true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Get the first {@link RapiDLayer} that we can find.
|
public void actionPerformed(ActionEvent event) {
|
||||||
*
|
final RapiDLayer layer = getLayer(true);
|
||||||
* @param create true if we want to create a new layer
|
getRapiDData(layer);
|
||||||
* @return A RapiDLayer, or a new RapiDLayer if none exist. May return
|
}
|
||||||
* {@code null} if {@code create} is {@code false}.
|
|
||||||
*/
|
|
||||||
public RapiDLayer getLayer(boolean create) {
|
|
||||||
final List<RapiDLayer> rapidLayers = MainApplication.getLayerManager().getLayersOfType(RapiDLayer.class);
|
|
||||||
RapiDLayer layer;
|
|
||||||
synchronized (this) {
|
|
||||||
if (rapidLayers.isEmpty() && create) {
|
|
||||||
layer = new RapiDLayer(new DataSet(), RapiDPlugin.NAME, null);
|
|
||||||
MainApplication.getLayerManager().addLayer(layer);
|
|
||||||
} else if (!rapidLayers.isEmpty()) {
|
|
||||||
layer = rapidLayers.get(0);
|
|
||||||
} else {
|
|
||||||
layer = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return layer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get data for a {@link RapiDLayer}
|
* Get the first {@link RapiDLayer} that we can find.
|
||||||
*
|
*
|
||||||
* @param layer The {@link RapiDLayer} to add data to
|
* @param create true if we want to create a new layer
|
||||||
*/
|
* @return A RapiDLayer, or a new RapiDLayer if none exist. May return
|
||||||
public void getRapiDData(RapiDLayer layer) {
|
* {@code null} if {@code create} is {@code false}.
|
||||||
final List<OsmDataLayer> osmLayers = MainApplication.getLayerManager().getLayersOfType(OsmDataLayer.class);
|
*/
|
||||||
for (final OsmDataLayer osmLayer : osmLayers) {
|
public RapiDLayer getLayer(boolean create) {
|
||||||
if (!osmLayer.isLocked()) {
|
final List<RapiDLayer> rapidLayers = MainApplication.getLayerManager().getLayersOfType(RapiDLayer.class);
|
||||||
getRapiDData(layer, osmLayer);
|
RapiDLayer layer;
|
||||||
}
|
synchronized (this) {
|
||||||
}
|
if (rapidLayers.isEmpty() && create) {
|
||||||
}
|
layer = new RapiDLayer(new DataSet(), RapiDPlugin.NAME, null);
|
||||||
|
MainApplication.getLayerManager().addLayer(layer);
|
||||||
|
} else if (!rapidLayers.isEmpty()) {
|
||||||
|
layer = rapidLayers.get(0);
|
||||||
|
} else {
|
||||||
|
layer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return layer;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the data for RapiD
|
* Get data for a {@link RapiDLayer}
|
||||||
*
|
*
|
||||||
* @param layer A pre-existing {@link RapiDLayer}
|
* @param layer The {@link RapiDLayer} to add data to
|
||||||
* @param osmLayer The osm datalayer with a set of bounds
|
*/
|
||||||
*/
|
public void getRapiDData(RapiDLayer layer) {
|
||||||
public void getRapiDData(RapiDLayer layer, OsmDataLayer osmLayer) {
|
final List<OsmDataLayer> osmLayers = MainApplication.getLayerManager().getLayersOfType(OsmDataLayer.class);
|
||||||
final DataSet editSet = osmLayer.getDataSet();
|
for (final OsmDataLayer osmLayer : osmLayers) {
|
||||||
final List<Bounds> editSetBounds = editSet.getDataSourceBounds();
|
if (!osmLayer.isLocked()) {
|
||||||
final DataSet rapidSet = layer.getDataSet();
|
getRapiDData(layer, osmLayer);
|
||||||
final List<Bounds> rapidBounds = rapidSet.getDataSourceBounds();
|
}
|
||||||
for (final Bounds bound : editSetBounds) {
|
}
|
||||||
if (!rapidBounds.contains(bound)) {
|
}
|
||||||
final DataSet newData = RapiDDataUtils.getData(bound.toBBox());
|
|
||||||
/* Microsoft buildings don't have a source, so we add one */
|
|
||||||
RapiDDataUtils.addSourceTags(newData, "building", "Microsoft");
|
|
||||||
synchronized (layer) {
|
|
||||||
layer.unlock();
|
|
||||||
layer.mergeFrom(newData);
|
|
||||||
layer.lock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
protected void updateEnabledState() {
|
* Get the data for RapiD
|
||||||
if (getLayerManager().getEditDataSet() == null) {
|
*
|
||||||
setEnabled(false);
|
* @param layer A pre-existing {@link RapiDLayer}
|
||||||
} else {
|
* @param osmLayer The osm datalayer with a set of bounds
|
||||||
setEnabled(true);
|
*/
|
||||||
}
|
public void getRapiDData(RapiDLayer layer, OsmDataLayer osmLayer) {
|
||||||
}
|
final DataSet editSet = osmLayer.getDataSet();
|
||||||
|
final List<Bounds> editSetBounds = editSet.getDataSourceBounds();
|
||||||
|
final DataSet rapidSet = layer.getDataSet();
|
||||||
|
final List<Bounds> rapidBounds = rapidSet.getDataSourceBounds();
|
||||||
|
for (final Bounds bound : editSetBounds) {
|
||||||
|
if (!rapidBounds.contains(bound)) {
|
||||||
|
final DataSet newData = RapiDDataUtils.getData(bound.toBBox());
|
||||||
|
/* Microsoft buildings don't have a source, so we add one */
|
||||||
|
RapiDDataUtils.addSourceTags(newData, "building", "Microsoft");
|
||||||
|
synchronized (layerLock) {
|
||||||
|
layer.unlock();
|
||||||
|
layer.mergeFrom(newData);
|
||||||
|
layer.lock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateEnabledState() {
|
||||||
|
if (getLayerManager().getEditDataSet() == null) {
|
||||||
|
setEnabled(false);
|
||||||
|
} else {
|
||||||
|
setEnabled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,210 +30,209 @@ import org.openstreetmap.josm.tools.Pair;
|
||||||
import org.openstreetmap.josm.tools.Utils;
|
import org.openstreetmap.josm.tools.Utils;
|
||||||
|
|
||||||
public class RapiDAddCommand extends Command {
|
public class RapiDAddCommand extends Command {
|
||||||
DataSet editable;
|
DataSet editable;
|
||||||
DataSet rapid;
|
DataSet rapid;
|
||||||
Collection<OsmPrimitive> primitives;
|
Collection<OsmPrimitive> primitives;
|
||||||
AddPrimitivesCommand addPrimitivesCommand;
|
AddPrimitivesCommand addPrimitivesCommand;
|
||||||
Collection<OsmPrimitive> modifiedPrimitives;
|
Collection<OsmPrimitive> modifiedPrimitives;
|
||||||
|
|
||||||
OsmDataLayer editLayer = null;
|
OsmDataLayer editLayer = null;
|
||||||
|
|
||||||
public RapiDAddCommand(RapiDLayer rapidLayer, OsmDataLayer editLayer, Collection<OsmPrimitive> selection) {
|
public RapiDAddCommand(RapiDLayer rapidLayer, OsmDataLayer editLayer, Collection<OsmPrimitive> selection) {
|
||||||
super(rapidLayer.getDataSet());
|
super(rapidLayer.getDataSet());
|
||||||
this.rapid = rapidLayer.getDataSet();
|
this.rapid = rapidLayer.getDataSet();
|
||||||
this.editable = editLayer.getDataSet();
|
this.editable = editLayer.getDataSet();
|
||||||
this.primitives = selection;
|
this.primitives = selection;
|
||||||
this.editLayer = editLayer;
|
this.editLayer = editLayer;
|
||||||
modifiedPrimitives = null;
|
modifiedPrimitives = null;
|
||||||
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Add primitives from RapiD to the OSM data layer
|
* Add primitives from RapiD to the OSM data layer
|
||||||
*
|
*
|
||||||
* @param rapid The rapid dataset
|
* @param rapid The rapid dataset
|
||||||
* @param editable The OSM dataset
|
* @param editable The OSM dataset
|
||||||
* @param selection The primitives to add from RapiD
|
* @param selection The primitives to add from RapiD
|
||||||
*/
|
*/
|
||||||
public RapiDAddCommand(DataSet rapid, DataSet editable, Collection<OsmPrimitive> selection) {
|
public RapiDAddCommand(DataSet rapid, DataSet editable, Collection<OsmPrimitive> selection) {
|
||||||
super(rapid);
|
super(rapid);
|
||||||
this.rapid = rapid;
|
this.rapid = rapid;
|
||||||
this.editable = editable;
|
this.editable = editable;
|
||||||
this.primitives = selection;
|
this.primitives = selection;
|
||||||
modifiedPrimitives = null;
|
modifiedPrimitives = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean executeCommand() {
|
public boolean executeCommand() {
|
||||||
if (rapid.equals(editable)) {
|
if (rapid.equals(editable)) {
|
||||||
Logging.error("{0}: DataSet rapid ({1}) should not be the same as DataSet editable ({2})", RapiDPlugin.NAME,
|
Logging.error("{0}: DataSet rapid ({1}) should not be the same as DataSet editable ({2})", RapiDPlugin.NAME,
|
||||||
rapid, editable);
|
rapid, editable);
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
primitives = new HashSet<>(primitives);
|
primitives = new HashSet<>(primitives);
|
||||||
RapiDDataUtils.addPrimitivesToCollection(/* collection= */ primitives, /* primitives= */ primitives);
|
RapiDDataUtils.addPrimitivesToCollection(/* collection= */ primitives, /* primitives= */ primitives);
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
rapid.unlock();
|
rapid.unlock();
|
||||||
Collection<OsmPrimitive> newPrimitives = new TreeSet<>(moveCollection(rapid, editable, primitives));
|
Collection<OsmPrimitive> newPrimitives = new TreeSet<>(moveCollection(rapid, editable, primitives));
|
||||||
createConnections(editable, newPrimitives);
|
createConnections(editable, newPrimitives);
|
||||||
RapiDDataUtils.removePrimitivesFromDataSet(primitives);
|
RapiDDataUtils.removePrimitivesFromDataSet(primitives);
|
||||||
rapid.lock();
|
rapid.lock();
|
||||||
}
|
}
|
||||||
if (editLayer != null && RapiDDataUtils.getSwitchLayers()) {
|
if (editLayer != null && RapiDDataUtils.getSwitchLayers()) {
|
||||||
MainApplication.getLayerManager().setActiveLayer(editLayer);
|
MainApplication.getLayerManager().setActiveLayer(editLayer);
|
||||||
editable.setSelected(
|
editable.setSelected(
|
||||||
editable.getSelected().stream().filter(OsmPrimitive::isTagged).collect(Collectors.toSet()));
|
editable.getSelected().stream().filter(OsmPrimitive::isTagged).collect(Collectors.toSet()));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create connections based off of current RapiD syntax
|
* Create connections based off of current RapiD syntax
|
||||||
*
|
*
|
||||||
* @param dataSet The {@link DataSet} that should have the primitives we are
|
* @param dataSet The {@link DataSet} that should have the primitives we are
|
||||||
* connecting to
|
* connecting to
|
||||||
* @param collection The primitives with connection information (currently only
|
* @param collection The primitives with connection information (currently only
|
||||||
* checks Nodes)
|
* checks Nodes)
|
||||||
*/
|
*/
|
||||||
public static void createConnections(DataSet dataSet, Collection<OsmPrimitive> collection) {
|
public static void createConnections(DataSet dataSet, Collection<OsmPrimitive> collection) {
|
||||||
Collection<Node> nodes = Utils.filteredCollection(collection, Node.class);
|
Collection<Node> nodes = Utils.filteredCollection(collection, Node.class);
|
||||||
for (Node node : nodes) {
|
for (Node node : nodes) {
|
||||||
if (node.hasKey("conn")) {
|
if (node.hasKey("conn")) {
|
||||||
// Currently w<way id>,n<node1>,n<node2>
|
// Currently w<way id>,n<node1>,n<node2>
|
||||||
OsmPrimitive[] primitiveConnections = getPrimitives(dataSet, node.get("conn"));
|
OsmPrimitive[] primitiveConnections = getPrimitives(dataSet, node.get("conn"));
|
||||||
for (int i = 0; i < primitiveConnections.length / 3; i++) {
|
for (int i = 0; i < primitiveConnections.length / 3; i++) {
|
||||||
if (primitiveConnections[i] instanceof Way && primitiveConnections[i + 1] instanceof Node
|
if (primitiveConnections[i] instanceof Way && primitiveConnections[i + 1] instanceof Node
|
||||||
&& primitiveConnections[i + 2] instanceof Node) {
|
&& primitiveConnections[i + 2] instanceof Node) {
|
||||||
addNodesToWay(node, (Way) primitiveConnections[i], (Node) primitiveConnections[i + 1],
|
addNodesToWay(node, (Way) primitiveConnections[i], (Node) primitiveConnections[i + 1],
|
||||||
(Node) primitiveConnections[i + 2]);
|
(Node) primitiveConnections[i + 2]);
|
||||||
} else {
|
} else {
|
||||||
Logging.error("{0}: {1}, {2}: {3}, {4}: {5}", i, primitiveConnections[i].getClass(), i + 1,
|
Logging.error("{0}: {1}, {2}: {3}, {4}: {5}", i, primitiveConnections[i].getClass(), i + 1,
|
||||||
primitiveConnections[i + 1].getClass(), i + 2, primitiveConnections[i + 2].getClass());
|
primitiveConnections[i + 1].getClass(), i + 2, primitiveConnections[i + 2].getClass());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Logging.debug("RapiD: Removing conn from {0} in {1}", node, dataSet.getName());
|
Logging.debug("RapiD: Removing conn from {0} in {1}", node, dataSet.getName());
|
||||||
node.remove("conn");
|
node.remove("conn");
|
||||||
}
|
}
|
||||||
if (node.hasKey("dupe")) {
|
if (node.hasKey("dupe")) {
|
||||||
OsmPrimitive[] primitiveConnections = getPrimitives(dataSet, node.get("dupe"));
|
OsmPrimitive[] primitiveConnections = getPrimitives(dataSet, node.get("dupe"));
|
||||||
if (primitiveConnections.length != 1) {
|
if (primitiveConnections.length != 1) {
|
||||||
Logging.error("RapiD: dupe connection connected to more than one node? (dupe={0})",
|
Logging.error("RapiD: dupe connection connected to more than one node? (dupe={0})",
|
||||||
node.get("dupe"));
|
node.get("dupe"));
|
||||||
}
|
}
|
||||||
replaceNode(node, (Node) primitiveConnections[0]);
|
replaceNode(node, (Node) primitiveConnections[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the primitives from a dataset with specified ids
|
* Get the primitives from a dataset with specified ids
|
||||||
*
|
*
|
||||||
* @param dataSet The dataset holding the primitives (hopefully)
|
* @param dataSet The dataset holding the primitives (hopefully)
|
||||||
* @param ids The ids formated like n<NUMBER>,r<NUMBER>,w<NUMBER>
|
* @param ids The ids formated like n<NUMBER>,r<NUMBER>,w<NUMBER>
|
||||||
* @return The primitives that the ids point to, if in the dataset.
|
* @return The primitives that the ids point to, if in the dataset.
|
||||||
*/
|
*/
|
||||||
private static OsmPrimitive[] getPrimitives(DataSet dataSet, String ids) {
|
private static OsmPrimitive[] getPrimitives(DataSet dataSet, String ids) {
|
||||||
String[] connections = ids.split(",", -1);
|
String[] connections = ids.split(",", -1);
|
||||||
OsmPrimitive[] primitiveConnections = new OsmPrimitive[connections.length];
|
OsmPrimitive[] primitiveConnections = new OsmPrimitive[connections.length];
|
||||||
for (int i = 0; i < connections.length; i++) {
|
for (int i = 0; i < connections.length; i++) {
|
||||||
String member = connections[i];
|
String member = connections[i];
|
||||||
long id = Long.parseLong(member.substring(1));
|
long id = Long.parseLong(member.substring(1));
|
||||||
char firstChar = member.charAt(0);
|
char firstChar = member.charAt(0);
|
||||||
if (firstChar == 'w') {
|
if (firstChar == 'w') {
|
||||||
primitiveConnections[i] = dataSet.getPrimitiveById(id, OsmPrimitiveType.WAY);
|
primitiveConnections[i] = dataSet.getPrimitiveById(id, OsmPrimitiveType.WAY);
|
||||||
} else if (firstChar == 'n') {
|
} else if (firstChar == 'n') {
|
||||||
primitiveConnections[i] = dataSet.getPrimitiveById(id, OsmPrimitiveType.NODE);
|
primitiveConnections[i] = dataSet.getPrimitiveById(id, OsmPrimitiveType.NODE);
|
||||||
} else if (firstChar == 'r') {
|
} else if (firstChar == 'r') {
|
||||||
primitiveConnections[i] = dataSet.getPrimitiveById(id, OsmPrimitiveType.RELATION);
|
primitiveConnections[i] = dataSet.getPrimitiveById(id, OsmPrimitiveType.RELATION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return primitiveConnections;
|
return primitiveConnections;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a node to a way
|
* Add a node to a way
|
||||||
*
|
*
|
||||||
* @param toAddNode The node to add
|
* @param toAddNode The node to add
|
||||||
* @param way The way to add the node to
|
* @param way The way to add the node to
|
||||||
* @param first The first node in a waysegment (the node is between this and
|
* @param first The first node in a waysegment (the node is between this and
|
||||||
* the second node)
|
* the second node)
|
||||||
* @param second The second node in a waysegemnt
|
* @param second The second node in a waysegemnt
|
||||||
*/
|
*/
|
||||||
public static void addNodesToWay(Node toAddNode, Way way, Node first, Node second) {
|
public static void addNodesToWay(Node toAddNode, Way way, Node first, Node second) {
|
||||||
int index = Math.max(way.getNodes().indexOf(first), way.getNodes().indexOf(second));
|
int index = Math.max(way.getNodes().indexOf(first), way.getNodes().indexOf(second));
|
||||||
way.addNode(index, toAddNode);
|
way.addNode(index, toAddNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void replaceNode(Node original, Node newNode) {
|
public static void replaceNode(Node original, Node newNode) {
|
||||||
for (OsmPrimitive primitive : original.getReferrers()) {
|
for (OsmPrimitive primitive : original.getReferrers()) {
|
||||||
if (primitive instanceof Way) {
|
if (primitive instanceof Way) {
|
||||||
Way way = (Way) primitive;
|
Way way = (Way) primitive;
|
||||||
List<Integer> indexes = new ArrayList<>();
|
List<Integer> indexes = new ArrayList<>();
|
||||||
List<Node> nodes = way.getNodes();
|
List<Node> nodes = way.getNodes();
|
||||||
for (int i = 0; i < nodes.size(); i++) {
|
for (int i = 0; i < nodes.size(); i++) {
|
||||||
if (nodes.get(i).equals(original)) {
|
if (nodes.get(i).equals(original)) {
|
||||||
indexes.add(i);
|
indexes.add(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (way.getNodes().contains(original)) {
|
while (way.getNodes().contains(original)) {
|
||||||
way.removeNode(original);
|
way.removeNode(original);
|
||||||
}
|
}
|
||||||
for (int index : indexes) {
|
for (int index : indexes) {
|
||||||
way.addNode(index, newNode);
|
way.addNode(index, newNode);
|
||||||
}
|
}
|
||||||
} else if (primitive instanceof Relation) {
|
} else if (primitive instanceof Relation) {
|
||||||
List<Pair<Integer, RelationMember>> replaceMembers = new ArrayList<>();
|
List<Pair<Integer, RelationMember>> replaceMembers = new ArrayList<>();
|
||||||
Relation relation = (Relation) primitive;
|
Relation relation = (Relation) primitive;
|
||||||
List<RelationMember> relationMembers = relation.getMembers();
|
List<RelationMember> relationMembers = relation.getMembers();
|
||||||
for (int i = 0; i < relationMembers.size(); i++) {
|
for (int i = 0; i < relationMembers.size(); i++) {
|
||||||
RelationMember member = relationMembers.get(i);
|
RelationMember member = relationMembers.get(i);
|
||||||
if (member.getMember().equals(original)) {
|
if (member.getMember().equals(original)) {
|
||||||
replaceMembers.add(new Pair<>(i, new RelationMember(member.getRole(), newNode)));
|
replaceMembers.add(new Pair<>(i, new RelationMember(member.getRole(), newNode)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
relation.removeMembersFor(original);
|
relation.removeMembersFor(original);
|
||||||
for (Pair<Integer, RelationMember> pair : replaceMembers) {
|
for (Pair<Integer, RelationMember> pair : replaceMembers) {
|
||||||
relation.addMember(pair.a, pair.b);
|
relation.addMember(pair.a, pair.b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
original.getDataSet().removePrimitive(original);
|
original.getDataSet().removePrimitive(original);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move primitives from one dataset to another
|
* Move primitives from one dataset to another
|
||||||
*
|
*
|
||||||
* @param to The receiving dataset
|
* @param to The receiving dataset
|
||||||
* @param from The sending dataset
|
* @param from The sending dataset
|
||||||
* @param selection The primitives to move
|
* @param selection The primitives to move
|
||||||
* @return true if the primitives have moved datasets
|
* @return true if the primitives have moved datasets
|
||||||
*/
|
*/
|
||||||
public Collection<? extends OsmPrimitive> moveCollection(DataSet from, DataSet to,
|
public Collection<? extends OsmPrimitive> moveCollection(DataSet from, DataSet to,
|
||||||
Collection<OsmPrimitive> selection) {
|
Collection<OsmPrimitive> selection) {
|
||||||
if (from == null || to.isLocked() || from.isLocked()) {
|
if (from == null || to.isLocked() || from.isLocked()) {
|
||||||
Logging.error("RapiD: Cannot move primitives from {0} to {1}", from, to);
|
Logging.error("RapiD: Cannot move primitives from {0} to {1}", from, to);
|
||||||
return Collections.emptySet();
|
return Collections.emptySet();
|
||||||
}
|
}
|
||||||
Collection<OsmPrimitive> originalSelection = from.getSelected();
|
Collection<OsmPrimitive> originalSelection = from.getSelected();
|
||||||
from.setSelected(selection);
|
from.setSelected(selection);
|
||||||
MergeSourceBuildingVisitor mergeBuilder = new MergeSourceBuildingVisitor(from);
|
MergeSourceBuildingVisitor mergeBuilder = new MergeSourceBuildingVisitor(from);
|
||||||
List<PrimitiveData> primitiveDataList = mergeBuilder.build().allPrimitives().stream().map(OsmPrimitive::save)
|
List<PrimitiveData> primitiveDataList = mergeBuilder.build().allPrimitives().stream().map(OsmPrimitive::save)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
from.setSelected(originalSelection);
|
from.setSelected(originalSelection);
|
||||||
addPrimitivesCommand = new AddPrimitivesCommand(primitiveDataList, primitiveDataList, to);
|
addPrimitivesCommand = new AddPrimitivesCommand(primitiveDataList, primitiveDataList, to);
|
||||||
addPrimitivesCommand.executeCommand();
|
addPrimitivesCommand.executeCommand();
|
||||||
return addPrimitivesCommand.getParticipatingPrimitives();
|
return addPrimitivesCommand.getParticipatingPrimitives();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDescriptionText() {
|
public String getDescriptionText() {
|
||||||
return tr("Add object from RapiD");
|
return tr("Add object from RapiD");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
|
public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
|
||||||
Collection<OsmPrimitive> added) {
|
Collection<OsmPrimitive> added) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,187 +35,187 @@ import org.openstreetmap.josm.tools.Logging;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public final class RapiDDataUtils {
|
public final class RapiDDataUtils {
|
||||||
public static final String DEFAULT_RAPID_API = "https://www.facebook.com/maps/ml_roads?conflate_with_osm=true&theme=ml_road_vector&collaborator=fbid&token=ASZUVdYpCkd3M6ZrzjXdQzHulqRMnxdlkeBJWEKOeTUoY_Gwm9fuEd2YObLrClgDB_xfavizBsh0oDfTWTF7Zb4C&hash=ASYM8LPNy8k1XoJiI7A&result_type=road_building_vector_xml&bbox={bbox}";
|
public static final String DEFAULT_RAPID_API = "https://www.facebook.com/maps/ml_roads?conflate_with_osm=true&theme=ml_road_vector&collaborator=fbid&token=ASZUVdYpCkd3M6ZrzjXdQzHulqRMnxdlkeBJWEKOeTUoY_Gwm9fuEd2YObLrClgDB_xfavizBsh0oDfTWTF7Zb4C&hash=ASYM8LPNy8k1XoJiI7A&result_type=road_building_vector_xml&bbox={bbox}";
|
||||||
|
|
||||||
private RapiDDataUtils() {
|
private RapiDDataUtils() {
|
||||||
// Hide the constructor
|
// Hide the constructor
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a dataset from the API servers using a bbox
|
* Get a dataset from the API servers using a bbox
|
||||||
*
|
*
|
||||||
* @param bbox The bbox from which to get data
|
* @param bbox The bbox from which to get data
|
||||||
* @return A DataSet with data inside the bbox
|
* @return A DataSet with data inside the bbox
|
||||||
*/
|
*/
|
||||||
public static DataSet getData(BBox bbox) {
|
public static DataSet getData(BBox bbox) {
|
||||||
InputStream inputStream = null;
|
InputStream inputStream = null;
|
||||||
DataSet dataSet = new DataSet();
|
DataSet dataSet = new DataSet();
|
||||||
String urlString = getRapiDURL();
|
String urlString = getRapiDURL();
|
||||||
try {
|
try {
|
||||||
final URL url = new URL(urlString.replace("{bbox}", bbox.toStringCSV(",")));
|
final URL url = new URL(urlString.replace("{bbox}", bbox.toStringCSV(",")));
|
||||||
HttpClient client = HttpClient.create(url);
|
HttpClient client = HttpClient.create(url);
|
||||||
StringBuilder defaultUserAgent = new StringBuilder();
|
StringBuilder defaultUserAgent = new StringBuilder();
|
||||||
defaultUserAgent.append(client.getHeaders().get("User-Agent"));
|
defaultUserAgent.append(client.getHeaders().get("User-Agent"));
|
||||||
if (defaultUserAgent.length() == 0) {
|
if (defaultUserAgent.length() == 0) {
|
||||||
defaultUserAgent.append("JOSM");
|
defaultUserAgent.append("JOSM");
|
||||||
}
|
}
|
||||||
defaultUserAgent.append(tr("/ {0} {1}", RapiDPlugin.NAME, RapiDPlugin.getVersionInfo()));
|
defaultUserAgent.append(tr("/ {0} {1}", RapiDPlugin.NAME, RapiDPlugin.getVersionInfo()));
|
||||||
client.setHeader("User-Agent", defaultUserAgent.toString());
|
client.setHeader("User-Agent", defaultUserAgent.toString());
|
||||||
Logging.debug("{0}: Getting {1}", RapiDPlugin.NAME, client.getURL().toString());
|
Logging.debug("{0}: Getting {1}", RapiDPlugin.NAME, client.getURL().toString());
|
||||||
Response response = client.connect();
|
Response response = client.connect();
|
||||||
inputStream = response.getContent();
|
inputStream = response.getContent();
|
||||||
dataSet.mergeFrom(OsmReader.parseDataSet(inputStream, null));
|
dataSet.mergeFrom(OsmReader.parseDataSet(inputStream, null));
|
||||||
response.disconnect();
|
response.disconnect();
|
||||||
} catch (UnsupportedOperationException | IllegalDataException | IOException e) {
|
} catch (UnsupportedOperationException | IllegalDataException | IOException e) {
|
||||||
Logging.debug(e);
|
Logging.debug(e);
|
||||||
} finally {
|
} finally {
|
||||||
if (inputStream != null) {
|
if (inputStream != null) {
|
||||||
try {
|
try {
|
||||||
inputStream.close();
|
inputStream.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Logging.debug(e);
|
Logging.debug(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return dataSet;
|
return dataSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add specified source tags to objects without a source tag that also have a
|
* Add specified source tags to objects without a source tag that also have a
|
||||||
* specific key
|
* specific key
|
||||||
*
|
*
|
||||||
* @param dataSet The {#link DataSet} to look through
|
* @param dataSet The {#link DataSet} to look through
|
||||||
* @param primaryKey The primary key that must be in the {@link OsmPrimitive}
|
* @param primaryKey The primary key that must be in the {@link OsmPrimitive}
|
||||||
* @param source The specified source value (not tag)
|
* @param source The specified source value (not tag)
|
||||||
*/
|
*/
|
||||||
public static void addSourceTags(DataSet dataSet, String primaryKey, String source) {
|
public static void addSourceTags(DataSet dataSet, String primaryKey, String source) {
|
||||||
dataSet.allPrimitives().stream().filter(p -> p.hasKey(primaryKey) && !p.hasKey("source")).forEach(p -> {
|
dataSet.allPrimitives().stream().filter(p -> p.hasKey(primaryKey) && !p.hasKey("source")).forEach(p -> {
|
||||||
p.put("source", source);
|
p.put("source", source);
|
||||||
p.save();
|
p.save();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove primitives and their children from a dataset.
|
* Remove primitives and their children from a dataset.
|
||||||
*
|
*
|
||||||
* @param primitives The primitives to remove
|
* @param primitives The primitives to remove
|
||||||
*/
|
*/
|
||||||
public static void removePrimitivesFromDataSet(Collection<OsmPrimitive> primitives) {
|
public static void removePrimitivesFromDataSet(Collection<OsmPrimitive> primitives) {
|
||||||
for (OsmPrimitive primitive : primitives) {
|
for (OsmPrimitive primitive : primitives) {
|
||||||
if (primitive instanceof Relation) {
|
if (primitive instanceof Relation) {
|
||||||
removePrimitivesFromDataSet(((Relation) primitive).getMemberPrimitives());
|
removePrimitivesFromDataSet(((Relation) primitive).getMemberPrimitives());
|
||||||
} else if (primitive instanceof Way) {
|
} else if (primitive instanceof Way) {
|
||||||
for (Node node : ((Way) primitive).getNodes()) {
|
for (Node node : ((Way) primitive).getNodes()) {
|
||||||
DataSet ds = node.getDataSet();
|
DataSet ds = node.getDataSet();
|
||||||
if (ds != null) {
|
if (ds != null) {
|
||||||
ds.removePrimitive(node);
|
ds.removePrimitive(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DataSet ds = primitive.getDataSet();
|
DataSet ds = primitive.getDataSet();
|
||||||
if (ds != null) {
|
if (ds != null) {
|
||||||
ds.removePrimitive(primitive);
|
ds.removePrimitive(primitive);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add primitives and their children to a collection
|
* Add primitives and their children to a collection
|
||||||
*
|
*
|
||||||
* @param collection A collection to add the primitives to
|
* @param collection A collection to add the primitives to
|
||||||
* @param primitives The primitives to add to the collection
|
* @param primitives The primitives to add to the collection
|
||||||
*/
|
*/
|
||||||
public static void addPrimitivesToCollection(Collection<OsmPrimitive> collection,
|
public static void addPrimitivesToCollection(Collection<OsmPrimitive> collection,
|
||||||
Collection<OsmPrimitive> primitives) {
|
Collection<OsmPrimitive> primitives) {
|
||||||
Collection<OsmPrimitive> temporaryCollection = new TreeSet<>();
|
Collection<OsmPrimitive> temporaryCollection = new TreeSet<>();
|
||||||
for (OsmPrimitive primitive : primitives) {
|
for (OsmPrimitive primitive : primitives) {
|
||||||
if (primitive instanceof Way) {
|
if (primitive instanceof Way) {
|
||||||
temporaryCollection.addAll(((Way) primitive).getNodes());
|
temporaryCollection.addAll(((Way) primitive).getNodes());
|
||||||
} else if (primitive instanceof Relation) {
|
} else if (primitive instanceof Relation) {
|
||||||
addPrimitivesToCollection(temporaryCollection, ((Relation) primitive).getMemberPrimitives());
|
addPrimitivesToCollection(temporaryCollection, ((Relation) primitive).getMemberPrimitives());
|
||||||
}
|
}
|
||||||
temporaryCollection.add(primitive);
|
temporaryCollection.add(primitive);
|
||||||
}
|
}
|
||||||
collection.addAll(temporaryCollection);
|
collection.addAll(temporaryCollection);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current RapiD url
|
* Get the current RapiD url
|
||||||
*
|
*
|
||||||
* @return A RapiD url
|
* @return A RapiD url
|
||||||
*/
|
*/
|
||||||
public static String getRapiDURL() {
|
public static String getRapiDURL() {
|
||||||
List<String> urls = getRapiDURLs();
|
List<String> urls = getRapiDURLs();
|
||||||
String url = Config.getPref().get(RapiDPlugin.NAME.concat(".current_api"), DEFAULT_RAPID_API);
|
String url = Config.getPref().get(RapiDPlugin.NAME.concat(".current_api"), DEFAULT_RAPID_API);
|
||||||
if (!urls.contains(url)) {
|
if (!urls.contains(url)) {
|
||||||
url = DEFAULT_RAPID_API;
|
url = DEFAULT_RAPID_API;
|
||||||
setRapiDUrl(DEFAULT_RAPID_API);
|
setRapiDUrl(DEFAULT_RAPID_API);
|
||||||
}
|
}
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the RapiD url
|
* Set the RapiD url
|
||||||
*
|
*
|
||||||
* @param url The url to set as the default
|
* @param url The url to set as the default
|
||||||
*/
|
*/
|
||||||
public static void setRapiDUrl(String url) {
|
public static void setRapiDUrl(String url) {
|
||||||
List<String> urls = getRapiDURLs();
|
List<String> urls = getRapiDURLs();
|
||||||
if (!urls.contains(url)) {
|
if (!urls.contains(url)) {
|
||||||
urls.add(url);
|
urls.add(url);
|
||||||
setRapiDURLs(urls);
|
setRapiDURLs(urls);
|
||||||
}
|
}
|
||||||
Config.getPref().put(RapiDPlugin.NAME.concat(".current_api"), url);
|
Config.getPref().put(RapiDPlugin.NAME.concat(".current_api"), url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the RapiD urls
|
* Set the RapiD urls
|
||||||
*
|
*
|
||||||
* @param urls A list of URLs
|
* @param urls A list of URLs
|
||||||
*/
|
*/
|
||||||
public static void setRapiDURLs(List<String> urls) {
|
public static void setRapiDURLs(List<String> urls) {
|
||||||
Config.getPref().putList(RapiDPlugin.NAME.concat(".apis"), urls);
|
Config.getPref().putList(RapiDPlugin.NAME.concat(".apis"), urls);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the RapiD urls (or the default)
|
* Get the RapiD urls (or the default)
|
||||||
*
|
*
|
||||||
* @return The urls for RapiD endpoints
|
* @return The urls for RapiD endpoints
|
||||||
*/
|
*/
|
||||||
public static List<String> getRapiDURLs() {
|
public static List<String> getRapiDURLs() {
|
||||||
return Config.getPref().getList(RapiDPlugin.NAME.concat(".apis"),
|
return Config.getPref().getList(RapiDPlugin.NAME.concat(".apis"),
|
||||||
new ArrayList<>(Arrays.asList(DEFAULT_RAPID_API)));
|
new ArrayList<>(Arrays.asList(DEFAULT_RAPID_API)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a paintstyle from the jar (TODO)
|
* Add a paintstyle from the jar (TODO)
|
||||||
*/
|
*/
|
||||||
public static void addRapiDPaintStyles() {
|
public static void addRapiDPaintStyles() {
|
||||||
// TODO figure out how to use the one in the jar file
|
// TODO figure out how to use the one in the jar file
|
||||||
ExtendedSourceEntry rapid = new ExtendedSourceEntry(SourceType.MAP_PAINT_STYLE, "rapid.mapcss",
|
ExtendedSourceEntry rapid = new ExtendedSourceEntry(SourceType.MAP_PAINT_STYLE, "rapid.mapcss",
|
||||||
"https://gitlab.com/smocktaylor/rapid/raw/master/src/resources/styles/standard/rapid.mapcss");
|
"https://gitlab.com/smocktaylor/rapid/raw/master/src/resources/styles/standard/rapid.mapcss");
|
||||||
List<SourceEntry> paintStyles = MapPaintPrefHelper.INSTANCE.get();
|
List<SourceEntry> paintStyles = MapPaintPrefHelper.INSTANCE.get();
|
||||||
for (SourceEntry paintStyle : paintStyles) {
|
for (SourceEntry paintStyle : paintStyles) {
|
||||||
if (rapid.url.equals(paintStyle.url))
|
if (rapid.url.equals(paintStyle.url))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
paintStyles.add(rapid);
|
paintStyles.add(rapid);
|
||||||
MapPaintPrefHelper.INSTANCE.put(paintStyles);
|
MapPaintPrefHelper.INSTANCE.put(paintStyles);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set whether or not a we switch from the RapiD layer to an OSM data layer
|
* Set whether or not a we switch from the RapiD layer to an OSM data layer
|
||||||
*
|
*
|
||||||
* @param selected true if we are going to switch layers
|
* @param selected true if we are going to switch layers
|
||||||
*/
|
*/
|
||||||
public static void setSwitchLayers(boolean selected) {
|
public static void setSwitchLayers(boolean selected) {
|
||||||
Config.getPref().putBoolean(RapiDPlugin.NAME.concat(".autoswitchlayers"), selected);
|
Config.getPref().putBoolean(RapiDPlugin.NAME.concat(".autoswitchlayers"), selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {@code true} if we want to automatically switch layers
|
* @return {@code true} if we want to automatically switch layers
|
||||||
*/
|
*/
|
||||||
public static boolean getSwitchLayers() {
|
public static boolean getSwitchLayers() {
|
||||||
return Config.getPref().getBoolean(RapiDPlugin.NAME.concat(".autoswitchlayers"), true);
|
return Config.getPref().getBoolean(RapiDPlugin.NAME.concat(".autoswitchlayers"), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,16 +12,16 @@ import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
||||||
*/
|
*/
|
||||||
public class RapiDLayer extends OsmDataLayer {
|
public class RapiDLayer extends OsmDataLayer {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new RapiD layer
|
* Create a new RapiD layer
|
||||||
* @param data OSM data from rapid
|
* @param data OSM data from rapid
|
||||||
* @param name Layer name
|
* @param name Layer name
|
||||||
* @param associatedFile an associated file (can be null)
|
* @param associatedFile an associated file (can be null)
|
||||||
*/
|
*/
|
||||||
public RapiDLayer(DataSet data, String name, File associatedFile) {
|
public RapiDLayer(DataSet data, String name, File associatedFile) {
|
||||||
super(data, name, associatedFile);
|
super(data, name, associatedFile);
|
||||||
this.lock();
|
this.lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override only JOSM > 15323
|
// @Override only JOSM > 15323
|
||||||
public String getChangesetSourceTag() {
|
public String getChangesetSourceTag() {
|
||||||
|
|
|
@ -17,55 +17,55 @@ import org.openstreetmap.josm.plugins.rapid.RapiDPlugin;
|
||||||
import org.openstreetmap.josm.tools.Shortcut;
|
import org.openstreetmap.josm.tools.Shortcut;
|
||||||
|
|
||||||
public class RapiDMoveAction extends JosmAction {
|
public class RapiDMoveAction extends JosmAction {
|
||||||
/** UID for abstract action */
|
/** UID for abstract action */
|
||||||
private static final long serialVersionUID = 319374598;
|
private static final long serialVersionUID = 319374598;
|
||||||
|
|
||||||
public RapiDMoveAction() {
|
public RapiDMoveAction() {
|
||||||
super(tr("Add from ".concat(RapiDPlugin.NAME)), null, tr("Add data from RapiD"), Shortcut.registerShortcut(
|
super(tr("Add from ".concat(RapiDPlugin.NAME)), null, tr("Add data from RapiD"), Shortcut.registerShortcut(
|
||||||
"data:rapidadd", tr("Rapid: {0}", tr("Add selected data")), KeyEvent.VK_A, Shortcut.SHIFT), true);
|
"data:rapidadd", tr("Rapid: {0}", tr("Add selected data")), KeyEvent.VK_A, Shortcut.SHIFT), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent event) {
|
public void actionPerformed(ActionEvent event) {
|
||||||
for (RapiDLayer rapid : MainApplication.getLayerManager().getLayersOfType(RapiDLayer.class)) {
|
for (RapiDLayer rapid : MainApplication.getLayerManager().getLayersOfType(RapiDLayer.class)) {
|
||||||
List<OsmDataLayer> osmLayers = MainApplication.getLayerManager().getLayersOfType(OsmDataLayer.class);
|
List<OsmDataLayer> osmLayers = MainApplication.getLayerManager().getLayersOfType(OsmDataLayer.class);
|
||||||
OsmDataLayer editLayer = null;
|
OsmDataLayer editLayer = null;
|
||||||
Collection<OsmPrimitive> selected = rapid.getDataSet().getSelected();
|
Collection<OsmPrimitive> selected = rapid.getDataSet().getSelected();
|
||||||
for (OsmDataLayer osmLayer : osmLayers) {
|
for (OsmDataLayer osmLayer : osmLayers) {
|
||||||
if (!osmLayer.isLocked() && osmLayer.isVisible() && osmLayer.isUploadable()
|
if (!osmLayer.isLocked() && osmLayer.isVisible() && osmLayer.isUploadable()
|
||||||
&& osmLayer.getClass().equals(OsmDataLayer.class)) {
|
&& osmLayer.getClass().equals(OsmDataLayer.class)) {
|
||||||
editLayer = osmLayer;
|
editLayer = osmLayer;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (editLayer != null) {
|
if (editLayer != null) {
|
||||||
RapiDAddCommand command = new RapiDAddCommand(rapid, editLayer, selected);
|
RapiDAddCommand command = new RapiDAddCommand(rapid, editLayer, selected);
|
||||||
UndoRedoHandler.getInstance().add(command);
|
UndoRedoHandler.getInstance().add(command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateEnabledState() {
|
protected void updateEnabledState() {
|
||||||
setEnabled(checkIfActionEnabled());
|
setEnabled(checkIfActionEnabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
|
protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
|
||||||
if (selection == null || selection.isEmpty()) {
|
if (selection == null || selection.isEmpty()) {
|
||||||
setEnabled(false);
|
setEnabled(false);
|
||||||
} else {
|
} else {
|
||||||
setEnabled(checkIfActionEnabled());
|
setEnabled(checkIfActionEnabled());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkIfActionEnabled() {
|
private boolean checkIfActionEnabled() {
|
||||||
Layer active = getLayerManager().getActiveLayer();
|
Layer active = getLayerManager().getActiveLayer();
|
||||||
if (active instanceof RapiDLayer) {
|
if (active instanceof RapiDLayer) {
|
||||||
RapiDLayer rapid = (RapiDLayer) active;
|
RapiDLayer rapid = (RapiDLayer) active;
|
||||||
Collection<OsmPrimitive> selection = rapid.getDataSet().getAllSelected();
|
Collection<OsmPrimitive> selection = rapid.getDataSet().getAllSelected();
|
||||||
return (selection != null && !selection.isEmpty());
|
return (selection != null && !selection.isEmpty());
|
||||||
} else
|
} else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,74 +16,74 @@ import org.openstreetmap.josm.plugins.rapid.backend.RapiDAddCommand;
|
||||||
import org.openstreetmap.josm.testutils.JOSMTestRules;
|
import org.openstreetmap.josm.testutils.JOSMTestRules;
|
||||||
|
|
||||||
public class RapiDAddComandTest {
|
public class RapiDAddComandTest {
|
||||||
@Rule
|
@Rule
|
||||||
public JOSMTestRules test = new JOSMTestRules();
|
public JOSMTestRules test = new JOSMTestRules();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMoveCollection() {
|
public void testMoveCollection() {
|
||||||
DataSet ds1 = new DataSet();
|
DataSet ds1 = new DataSet();
|
||||||
DataSet ds2 = new DataSet();
|
DataSet ds2 = new DataSet();
|
||||||
Way way1 = TestUtils.newWay("highway=residential", new Node(new LatLon(0, 0)), new Node(new LatLon(0, 0.1)));
|
Way way1 = TestUtils.newWay("highway=residential", new Node(new LatLon(0, 0)), new Node(new LatLon(0, 0.1)));
|
||||||
Way way2 = TestUtils.newWay("highway=residential", new Node(new LatLon(-0.1, -0.2)), way1.firstNode());
|
Way way2 = TestUtils.newWay("highway=residential", new Node(new LatLon(-0.1, -0.2)), way1.firstNode());
|
||||||
Way way3 = TestUtils.newWay("highway=residential", new Node(new LatLon(65, 65)), new Node(new LatLon(66, 66)));
|
Way way3 = TestUtils.newWay("highway=residential", new Node(new LatLon(65, 65)), new Node(new LatLon(66, 66)));
|
||||||
for (Way way : Arrays.asList(way1, way2, way3)) {
|
for (Way way : Arrays.asList(way1, way2, way3)) {
|
||||||
for (Node node : way.getNodes()) {
|
for (Node node : way.getNodes()) {
|
||||||
if (!ds1.containsNode(node)) {
|
if (!ds1.containsNode(node)) {
|
||||||
ds1.addPrimitive(node);
|
ds1.addPrimitive(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!ds1.containsWay(way)) {
|
if (!ds1.containsWay(way)) {
|
||||||
ds1.addPrimitive(way);
|
ds1.addPrimitive(way);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ds1.lock();
|
ds1.lock();
|
||||||
RapiDAddCommand command = new RapiDAddCommand(ds1, ds2, Arrays.asList(way1, way2));
|
RapiDAddCommand command = new RapiDAddCommand(ds1, ds2, Arrays.asList(way1, way2));
|
||||||
command.executeCommand();
|
command.executeCommand();
|
||||||
Assert.assertTrue(ds2.containsWay(way1));
|
Assert.assertTrue(ds2.containsWay(way1));
|
||||||
Assert.assertTrue(ds2.containsNode(way1.firstNode()));
|
Assert.assertTrue(ds2.containsNode(way1.firstNode()));
|
||||||
Assert.assertTrue(ds2.containsNode(way1.lastNode()));
|
Assert.assertTrue(ds2.containsNode(way1.lastNode()));
|
||||||
Assert.assertFalse(ds1.containsWay(way1));
|
Assert.assertFalse(ds1.containsWay(way1));
|
||||||
Assert.assertTrue(ds2.containsWay(way2));
|
Assert.assertTrue(ds2.containsWay(way2));
|
||||||
Assert.assertTrue(ds2.containsNode(way2.firstNode()));
|
Assert.assertTrue(ds2.containsNode(way2.firstNode()));
|
||||||
Assert.assertTrue(ds2.containsNode(way2.lastNode()));
|
Assert.assertTrue(ds2.containsNode(way2.lastNode()));
|
||||||
Assert.assertFalse(ds1.containsWay(way2));
|
Assert.assertFalse(ds1.containsWay(way2));
|
||||||
|
|
||||||
Assert.assertFalse(ds2.containsWay(way3));
|
Assert.assertFalse(ds2.containsWay(way3));
|
||||||
command = new RapiDAddCommand(ds1, ds2, Arrays.asList(way3));
|
command = new RapiDAddCommand(ds1, ds2, Arrays.asList(way3));
|
||||||
command.executeCommand();
|
command.executeCommand();
|
||||||
Assert.assertTrue(ds2.containsWay(way3));
|
Assert.assertTrue(ds2.containsWay(way3));
|
||||||
Assert.assertTrue(ds2.containsNode(way3.firstNode()));
|
Assert.assertTrue(ds2.containsNode(way3.firstNode()));
|
||||||
Assert.assertTrue(ds2.containsNode(way3.lastNode()));
|
Assert.assertTrue(ds2.containsNode(way3.lastNode()));
|
||||||
Assert.assertFalse(ds1.containsWay(way3));
|
Assert.assertFalse(ds1.containsWay(way3));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateConnections() {
|
public void testCreateConnections() {
|
||||||
DataSet ds1 = new DataSet();
|
DataSet ds1 = new DataSet();
|
||||||
Way way1 = TestUtils.newWay("highway=residential", new Node(new LatLon(0, 0)), new Node(new LatLon(0, 0.15)));
|
Way way1 = TestUtils.newWay("highway=residential", new Node(new LatLon(0, 0)), new Node(new LatLon(0, 0.15)));
|
||||||
Way way2 = TestUtils.newWay("highway=residential", new Node(new LatLon(0, 0.05)),
|
Way way2 = TestUtils.newWay("highway=residential", new Node(new LatLon(0, 0.05)),
|
||||||
new Node(new LatLon(0.05, 0.2)));
|
new Node(new LatLon(0.05, 0.2)));
|
||||||
way2.firstNode().put("conn",
|
way2.firstNode().put("conn",
|
||||||
"w".concat(Long.toString(way1.getUniqueId())).concat(",n")
|
"w".concat(Long.toString(way1.getUniqueId())).concat(",n")
|
||||||
.concat(Long.toString(way1.firstNode().getUniqueId())).concat(",n")
|
.concat(Long.toString(way1.firstNode().getUniqueId())).concat(",n")
|
||||||
.concat(Long.toString(way1.lastNode().getUniqueId())));
|
.concat(Long.toString(way1.lastNode().getUniqueId())));
|
||||||
way1.getNodes().forEach(node -> ds1.addPrimitive(node));
|
way1.getNodes().forEach(node -> ds1.addPrimitive(node));
|
||||||
way2.getNodes().forEach(node -> ds1.addPrimitive(node));
|
way2.getNodes().forEach(node -> ds1.addPrimitive(node));
|
||||||
ds1.addPrimitive(way2);
|
ds1.addPrimitive(way2);
|
||||||
ds1.addPrimitive(way1);
|
ds1.addPrimitive(way1);
|
||||||
RapiDAddCommand.createConnections(ds1, Collections.singletonList(way2.firstNode()));
|
RapiDAddCommand.createConnections(ds1, Collections.singletonList(way2.firstNode()));
|
||||||
Assert.assertEquals(3, way1.getNodesCount());
|
Assert.assertEquals(3, way1.getNodesCount());
|
||||||
Assert.assertFalse(way1.isFirstLastNode(way2.firstNode()));
|
Assert.assertFalse(way1.isFirstLastNode(way2.firstNode()));
|
||||||
|
|
||||||
Way way3 = TestUtils.newWay("highway=residential", new Node(new LatLon(0, 0)),
|
Way way3 = TestUtils.newWay("highway=residential", new Node(new LatLon(0, 0)),
|
||||||
new Node(new LatLon(-0.1, -0.1)));
|
new Node(new LatLon(-0.1, -0.1)));
|
||||||
way3.firstNode().put("dupe", "n".concat(Long.toString(way1.firstNode().getUniqueId())));
|
way3.firstNode().put("dupe", "n".concat(Long.toString(way1.firstNode().getUniqueId())));
|
||||||
way3.getNodes().forEach(node -> ds1.addPrimitive(node));
|
way3.getNodes().forEach(node -> ds1.addPrimitive(node));
|
||||||
ds1.addPrimitive(way3);
|
ds1.addPrimitive(way3);
|
||||||
Node way3Node1 = way3.firstNode();
|
Node way3Node1 = way3.firstNode();
|
||||||
RapiDAddCommand.createConnections(ds1, Collections.singletonList(way3.firstNode()));
|
RapiDAddCommand.createConnections(ds1, Collections.singletonList(way3.firstNode()));
|
||||||
Assert.assertNotEquals(way3Node1, way3.firstNode());
|
Assert.assertNotEquals(way3Node1, way3.firstNode());
|
||||||
Assert.assertEquals(way1.firstNode(), way3.firstNode());
|
Assert.assertEquals(way1.firstNode(), way3.firstNode());
|
||||||
Assert.assertFalse(ds1.containsNode(way3Node1));
|
Assert.assertFalse(ds1.containsNode(way3Node1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue