kopia lustrzana https://github.com/JOSM/MapWithAI
Initial work on detecting tasking manager bounds
Signed-off-by: Taylor Smock <taylor.smock@kaart.com>pull/1/head
rodzic
d30933a8f5
commit
76d5c547b9
|
@ -0,0 +1,69 @@
|
||||||
|
// License: GPL. For details, see LICENSE file.
|
||||||
|
package org.openstreetmap.josm.plugins.rapid.backend;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import org.openstreetmap.josm.data.Bounds;
|
||||||
|
import org.openstreetmap.josm.data.osm.BBox;
|
||||||
|
import org.openstreetmap.josm.gui.MainApplication;
|
||||||
|
import org.openstreetmap.josm.gui.layer.GpxLayer;
|
||||||
|
import org.openstreetmap.josm.gui.layer.Layer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Taylor Smock
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class DetectTaskingManager {
|
||||||
|
public static final List<Pattern> patterns = new ArrayList<>();
|
||||||
|
static {
|
||||||
|
patterns.add(Pattern.compile("^Task Boundaries.*$"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private DetectTaskingManager() {
|
||||||
|
// Hide since this is going to be a static class
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return True if there is a tasking manager layer
|
||||||
|
*/
|
||||||
|
public static boolean hasTaskingManagerLayer() {
|
||||||
|
return getTaskingManagerLayer() != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return A {@link Layer} that matches a pattern defined in
|
||||||
|
* {@link DetectTaskingManager#patterns} or {@code null}.
|
||||||
|
*/
|
||||||
|
public static Layer getTaskingManagerLayer() {
|
||||||
|
Layer returnLayer = null;
|
||||||
|
List<Layer> layers = MainApplication.getLayerManager().getLayers();
|
||||||
|
for (Pattern pattern : patterns) {
|
||||||
|
Optional<Layer> layer = layers.parallelStream()
|
||||||
|
.filter(tlayer -> pattern.matcher(tlayer.getName()).matches())
|
||||||
|
.findFirst();
|
||||||
|
if (layer.isPresent()) {
|
||||||
|
returnLayer = layer.get();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return returnLayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return A {@link Bound} made from a tasking manager layer, or one that is not
|
||||||
|
* valid.
|
||||||
|
*/
|
||||||
|
public static BBox getTaskingManagerBBox() {
|
||||||
|
BBox returnBBox = new BBox();
|
||||||
|
Layer layer = getTaskingManagerLayer();
|
||||||
|
if (layer instanceof GpxLayer) {
|
||||||
|
GpxLayer gpxLayer = (GpxLayer) layer;
|
||||||
|
List<Bounds> bounds = gpxLayer.data.getDataSourceBounds();
|
||||||
|
bounds.forEach(bound -> returnBBox.add(bound.toBBox()));
|
||||||
|
}
|
||||||
|
return returnBBox;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
// License: GPL. For details, see LICENSE file.
|
||||||
|
package org.openstreetmap.josm.plugins.rapid.backend;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.openstreetmap.josm.data.coor.LatLon;
|
||||||
|
import org.openstreetmap.josm.data.gpx.GpxData;
|
||||||
|
import org.openstreetmap.josm.data.gpx.WayPoint;
|
||||||
|
import org.openstreetmap.josm.data.osm.BBox;
|
||||||
|
import org.openstreetmap.josm.gui.MainApplication;
|
||||||
|
import org.openstreetmap.josm.gui.layer.GpxLayer;
|
||||||
|
import org.openstreetmap.josm.testutils.JOSMTestRules;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Taylor Smock
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class DetectTaskingManagerTest {
|
||||||
|
private static final String LAYER_NAME = "Task Boundaries";
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public JOSMTestRules test = new JOSMTestRules().preferences().main().projection();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHasTaskingManagerLayer() {
|
||||||
|
Assert.assertFalse(DetectTaskingManager.hasTaskingManagerLayer());
|
||||||
|
MainApplication.getLayerManager().addLayer(new GpxLayer(new GpxData()));
|
||||||
|
Assert.assertFalse(DetectTaskingManager.hasTaskingManagerLayer());
|
||||||
|
MainApplication.getLayerManager().addLayer(new GpxLayer(new GpxData(), LAYER_NAME));
|
||||||
|
Assert.assertTrue(DetectTaskingManager.hasTaskingManagerLayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetTaskingManagerLayer() {
|
||||||
|
Assert.assertNull(DetectTaskingManager.getTaskingManagerLayer());
|
||||||
|
GpxLayer layer = new GpxLayer(new GpxData(), LAYER_NAME);
|
||||||
|
MainApplication.getLayerManager().addLayer(layer);
|
||||||
|
Assert.assertSame(layer, DetectTaskingManager.getTaskingManagerLayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetTaskingManagerBounds() {
|
||||||
|
Assert.assertFalse(DetectTaskingManager.getTaskingManagerBBox().isInWorld());
|
||||||
|
|
||||||
|
GpxLayer layer = new GpxLayer(new GpxData(), LAYER_NAME);
|
||||||
|
layer.data.addWaypoint(new WayPoint(new LatLon(0, 0)));
|
||||||
|
MainApplication.getLayerManager().addLayer(layer);
|
||||||
|
Assert.assertEquals(0, DetectTaskingManager.getTaskingManagerBBox().height(), 0.000001);
|
||||||
|
Assert.assertEquals(0, DetectTaskingManager.getTaskingManagerBBox().width(), 0.000001);
|
||||||
|
|
||||||
|
layer.data.addWaypoint(new WayPoint(new LatLon(1, 1)));
|
||||||
|
BBox bbox = DetectTaskingManager.getTaskingManagerBBox();
|
||||||
|
Assert.assertTrue(bbox.isInWorld());
|
||||||
|
Assert.assertTrue(bbox.getBottomRight().equalsEpsilon(new LatLon(1, 0)));
|
||||||
|
Assert.assertTrue(bbox.getTopLeft().equalsEpsilon(new LatLon(1, 0)));
|
||||||
|
}
|
||||||
|
}
|
Ładowanie…
Reference in New Issue