Skip to content

Commit

Permalink
Merge branch 'mapillary_date_filtering'
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpoole committed Oct 25, 2023
2 parents adf173f + 5bfcdf4 commit a1062b5
Show file tree
Hide file tree
Showing 19 changed files with 426 additions and 50 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ dependencies {
implementation "androidx.appcompat:appcompat-resources:1.6.1"
implementation "androidx.recyclerview:recyclerview:1.1.0"
implementation "androidx.preference:preference:1.1.0"
implementation "com.google.android.material:material:1.3.0"
implementation "com.google.android.material:material:1.8.0"
implementation "androidx.annotation:annotation:1.1.0"
implementation "androidx.core:core:1.7.0"
implementation "androidx.exifinterface:exifinterface:1.3.6"
Expand All @@ -623,7 +623,7 @@ dependencies {

//non-Android google
implementation 'com.google.protobuf:protobuf-java:3.12.2'
implementation "com.google.code.gson:gson:2.8.9"
implementation "com.google.code.gson:gson:2.10.1"
implementation "com.google.protobuf:protobuf-java:$googleProtobufVersion"
implementation 'com.google.openlocationcode:openlocationcode:1.0.4'

Expand Down
5 changes: 5 additions & 0 deletions documentation/docs/help/en/Main map display.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ The layer dialog supports the following actions on the layer entries:
* __Change style__ Show the layer styling dialog (disabled if a style has been loaded).
* __Load style__ Load a mapbox-gl style.
* __Reset style__ Reset the style to the default.
* Mapillary layer (additionally to _Mapbox Vector Tile layers_):
* __Set date range ...__ Select start and end date to filter Mapillary data on. Note that this functionality depends on some specifics of the loaded Mapbox GL style.
* GeoJSON layers:
* __Change style__ Show the layer styling dialog.
* __Info__ Display some information on the contents.
Expand Down Expand Up @@ -91,6 +93,9 @@ The layer dialog supports the following actions on the layer entries:
* __Add GeoJSON layer__ Loads a GeoJSON layer from a file in to a new GeoJSON layer.
* __Add background imagery layer__ Adds a tile based imagery layer from the internal configuration, which can be from ELI or JOSM, or a custom imagery layer.
* __Add overlay imagery layer__ As above but assumes that the layer is partially transparent.
* __Enable photo layer__ Enables the photo layer this will display clickable icons for photos that will start an internal or external viewer. Which photos can be displayed depends strongly on your Android version and settings [Advanced preferences](Advanced%20preferences.md).
* __Enable bookmark layer__ Enables a layer displaying saved bookmarks.
* __Enable Mapillary layer__ Enables the Mapillay layer.
* __Add layer from GPX file__ Adds a layer from a GPX file on device.
* __Download GPX track__ Download a GPX [track that you have previously uploaded to the OSM website](https://www.openstreetmap.org/traces/mine), and create a layer from it. Note that only GPX tracks with their starting point in the area currently displayed will be available for selection, this is a limitation of the current OSM API.
* __Add custom imagery__ Adds a custom imagery configuration, this can then be used just
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package de.blau.android.layer.mapillary;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;

import org.junit.After;
Expand All @@ -19,18 +22,23 @@
import android.app.Instrumentation.ActivityMonitor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Build;
import androidx.annotation.NonNull;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.rule.ActivityTestRule;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObject2;
import de.blau.android.App;
import de.blau.android.LayerUtils;
import de.blau.android.Logic;
import de.blau.android.Main;
import de.blau.android.Map;
import de.blau.android.MockTileServer;
import de.blau.android.R;
import de.blau.android.TestUtils;
import de.blau.android.dialogs.DateRangeDialog;
import de.blau.android.layer.LayerDialogTest;
import de.blau.android.layer.LayerType;
import de.blau.android.photos.MapillaryViewerActivity;
import de.blau.android.prefs.AdvancedPrefDatabase;
Expand Down Expand Up @@ -71,9 +79,9 @@ public void setup() {

assertNotNull(main);
TestUtils.grantPermissons(device);

LayerUtils.removeLayer(main, LayerType.MAPILLARY);
tileServer = MockTileServer.setupTileServer(main, "mapillary.mbt", true, LayerType.MAPILLARY, TileType.MVT,
de.blau.android.layer.mapillary.MapOverlay.MAPILLARY_TILES_ID);
de.blau.android.layer.mapillary.MapillaryOverlay.MAPILLARY_TILES_ID);

mockApiServer = new MockWebServerPlus();
HttpUrl mockApiBaseUrl = mockApiServer.server().url("/");
Expand Down Expand Up @@ -110,14 +118,15 @@ public void teardown() {
} catch (IOException | NullPointerException e) {
// ignore
}
LayerUtils.removeLayer(main, LayerType.MAPILLARY);
try (TileLayerDatabase tlDb = new TileLayerDatabase(main); SQLiteDatabase db = tlDb.getWritableDatabase()) {
TileLayerDatabase.deleteLayerWithId(db, de.blau.android.layer.mapillary.MapOverlay.MAPILLARY_TILES_ID);
TileLayerDatabase.deleteLayerWithId(db, de.blau.android.layer.mapillary.MapillaryOverlay.MAPILLARY_TILES_ID);
}
instrumentation.waitForIdleSync();
}

/**
* Add mapillary layer
* Add mapillary layer and click on one image
*/
@Test
public void mapillaryLayer() {
Expand All @@ -126,7 +135,7 @@ public void mapillaryLayer() {
imageResponse.setResponseCode(200);
imageResponse.setBody("{\"thumb_2048_url\": \"" + mockImagesBaseUrl.toString() + "\",\"computed_geometry\": {\"type\": \"Point\",\"coordinates\": ["
+ "8.407748800863,47.412813485744]" + "},\"id\": \"178993950747668\"}");
de.blau.android.layer.mapillary.MapOverlay layer = (MapOverlay) map.getLayer(LayerType.MAPILLARY);
de.blau.android.layer.mapillary.MapillaryOverlay layer = (MapillaryOverlay) map.getLayer(LayerType.MAPILLARY);
assertNotNull(layer);
layer.flushCaches(main); // forces the layer to retrieve everything

Expand Down Expand Up @@ -183,4 +192,35 @@ public void mapillaryLayer() {
}
}
}

/**
* Add mapillary layer and click on one image that should be filtered away
*
* Unluckily there doesn't seem to be an easy way to drag the sliders
*/
@Test
public void mapillaryLayerFilter() {
TestUtils.unlock(device);
TestUtils.sleep();

UiObject2 menuButton = TestUtils.getLayerButton(device, "Mapillary", LayerDialogTest.MENU_BUTTON);
menuButton.click();
assertTrue(TestUtils.clickText(device, false, main.getString(R.string.layer_set_date_range), true, false));
assertTrue(TestUtils.findText(device, false, main.getString(R.string.date_range_title)));
assertTrue(TestUtils.clickText(device, false, main.getString(R.string.okay), true, false));
assertTrue(TestUtils.clickText(device, false, main.getString(R.string.Done), true, false));
MapillaryOverlay layer = (MapillaryOverlay) map.getLayer(LayerType.MAPILLARY);
layer.setDateRange(0L, 0L);
layer.invalidate();
//
map.getViewBox().moveTo(map, (int) (8.407748800863 * 1E7), (int) (47.412813485744 * 1E7));
map.invalidate();
TestUtils.zoomToLevel(device, main, 22);
TestUtils.clickAtCoordinates(device, map, 8.407748800863, 47.412813485744, true); // nothing should happen
if (TestUtils.clickText(device, false, "OK", true)) {
TestUtils.clickAtCoordinates(device, map, 8.407748800863, 47.412813485744, true);
}
assertFalse(TestUtils.clickMenuButton(device, main.getString(R.string.share), false, true));
}

}
8 changes: 8 additions & 0 deletions src/main/assets/help/en/Main map display.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ <h3>Layer control</h3>
<li><strong>Reset style</strong> Reset the style to the default.</li>
</ul>
</li>
<li>Mapillary layer (additionally to <em>Mapbox Vector Tile layers</em>):
<ul>
<li><strong>Set date range ...</strong> Select start and end date to filter Mapillary data on. Note that this functionality depends on some specifics of the loaded Mapbox GL style.</li>
</ul>
</li>
<li>GeoJSON layers:
<ul>
<li><strong>Change style</strong> Show the layer styling dialog.</li>
Expand Down Expand Up @@ -111,6 +116,9 @@ <h3>Layer control</h3>
<li><strong>Add GeoJSON layer</strong> Loads a GeoJSON layer from a file in to a new GeoJSON layer.</li>
<li><strong>Add background imagery layer</strong> Adds a tile based imagery layer from the internal configuration, which can be from ELI or JOSM, or a custom imagery layer.</li>
<li><strong>Add overlay imagery layer</strong> As above but assumes that the layer is partially transparent.</li>
<li><strong>Enable photo layer</strong> Enables the photo layer this will display clickable icons for photos that will start an internal or external viewer. Which photos can be displayed depends strongly on your Android version and settings <a href="Advanced%20preferences.md">Advanced preferences</a>.</li>
<li><strong>Enable bookmark layer</strong> Enables a layer displaying saved bookmarks.</li>
<li><strong>Enable Mapillary layer</strong> Enables the Mapillay layer.</li>
<li><strong>Add layer from GPX file</strong> Adds a layer from a GPX file on device.</li>
<li><strong>Download GPX track</strong> Download a GPX <a href="https://www.openstreetmap.org/traces/mine">track that you have previously uploaded to the OSM website</a>, and create a layer from it. Note that only GPX tracks with their starting point in the area currently displayed will be available for selection, this is a limitation of the current OSM API.</li>
<li><strong>Add custom imagery</strong> Adds a custom imagery configuration, this can then be used just as any tile based imagery source, the entries can be managed in the <a href="Preferences.md">preferences</a>.</li>
Expand Down
41 changes: 40 additions & 1 deletion src/main/assets/mapillary-style.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@
"id": "overview",
"type": "line",
"source-layer": "overview",
"filter": [
"all",
[
">=",
"captured_at",
0
],
[
"<=",
"captured_at",
0
]
],
"maxzoom": 13,
"paint": {
"line-opacity": 1,
Expand Down Expand Up @@ -33,6 +46,19 @@
"id": "sequence",
"type": "line",
"source-layer": "sequence",
"filter": [
"all",
[
">=",
"captured_at",
0
],
[
"<=",
"captured_at",
0
]
],
"minzoom": 14,
"paint": {
"line-opacity": 1,
Expand Down Expand Up @@ -60,6 +86,19 @@
"id": "image",
"type": "symbol",
"source-layer": "image",
"filter": [
"all",
[
">=",
"captured_at",
0
],
[
"<=",
"captured_at",
0
]
],
"minzoom": 19,
"layout": {
"icon-image": "arrow",
Expand Down Expand Up @@ -92,7 +131,7 @@
"paint": {
"icon-color": "rgba(200, 100, 0, 1)"
}
}
}
],
"id": "mapillary"
}
2 changes: 1 addition & 1 deletion src/main/java/de/blau/android/DisambiguationMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private Type typeFromObject(@NonNull ClickedObject<?> clicked) {
return Type.GPX;
}
if (object instanceof de.blau.android.util.mvt.VectorTileDecoder.Feature) {
return clicked.getLayer() instanceof de.blau.android.layer.mapillary.MapOverlay ? Type.MAPILLARY : Type.MVT;
return clicked.getLayer() instanceof de.blau.android.layer.mapillary.MapillaryOverlay ? Type.MAPILLARY : Type.MVT;
}
if (object instanceof Photo) {
return Type.IMAGE;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/de/blau/android/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -1044,15 +1044,15 @@ private void processIntents() {
}
break;
case ACTION_MAPILLARY_SELECT:
final de.blau.android.layer.mapillary.MapOverlay mapillaryLayer = map != null
? (de.blau.android.layer.mapillary.MapOverlay) map.getLayer(LayerType.MAPILLARY)
final de.blau.android.layer.mapillary.MapillaryOverlay mapillaryLayer = map != null
? (de.blau.android.layer.mapillary.MapillaryOverlay) map.getLayer(LayerType.MAPILLARY)
: null;
if (mapillaryLayer != null) {
double[] coords = intent.getDoubleArrayExtra(de.blau.android.layer.mapillary.MapOverlay.COORDINATES_KEY);
double[] coords = intent.getDoubleArrayExtra(de.blau.android.layer.mapillary.MapillaryOverlay.COORDINATES_KEY);
if (coords != null) {
map.getViewBox().moveTo(map, (int) (coords[1] * 1E7), (int) (coords[0] * 1E7));
}
mapillaryLayer.select(intent.getIntExtra(de.blau.android.layer.mapillary.MapOverlay.SET_POSITION_KEY, 0));
mapillaryLayer.select(intent.getIntExtra(de.blau.android.layer.mapillary.MapillaryOverlay.SET_POSITION_KEY, 0));
}
break;
case ACTION_MAP_UPDATE:
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/blau/android/Map.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public void setUpLayers(@NonNull Context ctx) {
}
break;
case MAPILLARY:
layer = new de.blau.android.layer.mapillary.MapOverlay(this);
layer = new de.blau.android.layer.mapillary.MapillaryOverlay(this);
break;
case BOOKMARKS:
layer = new de.blau.android.layer.bookmarks.MapOverlay(this);
Expand Down
Loading

0 comments on commit a1062b5

Please sign in to comment.