From d1520bf5ff813aae36f94023459cab21df3d87a4 Mon Sep 17 00:00:00 2001 From: Nicholas Hallahan Date: Wed, 20 Apr 2016 18:48:06 -0700 Subject: [PATCH 01/12] #45 getting started with field paper overlay in Mapbox Android SDK Legacy (Deprecated) --- MapboxAndroidSDK/build.gradle | 1 + .../java/org/fieldpapers/model/FPAtlas.java | 54 ++++++++++++++++ .../java/org/fieldpapers/model/FPPage.java | 62 +++++++++++++++++++ .../org/fieldpapers/renderer/FPOverlay.java | 15 +++++ app/app.iml | 2 +- app/build.gradle | 4 +- .../redcross/openmapkit/ExternalStorage.java | 13 ++++ .../openmapkit/deployments/Deployment.java | 1 + 8 files changed, 149 insertions(+), 3 deletions(-) create mode 100644 MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java create mode 100644 MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPPage.java create mode 100644 MapboxAndroidSDK/src/main/java/org/fieldpapers/renderer/FPOverlay.java diff --git a/MapboxAndroidSDK/build.gradle b/MapboxAndroidSDK/build.gradle index 4eb4845..c94c544 100644 --- a/MapboxAndroidSDK/build.gradle +++ b/MapboxAndroidSDK/build.gradle @@ -29,6 +29,7 @@ dependencies { compile 'com.nineoldandroids:library:2.4.0' compile 'com.jakewharton:disklrucache:2.0.2' compile 'commons-codec:commons-codec:1.10' + compile 'commons-io:commons-io:2.4' } android { diff --git a/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java b/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java new file mode 100644 index 0000000..28a676e --- /dev/null +++ b/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java @@ -0,0 +1,54 @@ +package org.fieldpapers.model; + +import com.vividsolutions.jts.index.quadtree.Quadtree; + +import org.apache.commons.io.FileUtils; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +public class FPAtlas { + + private JSONObject geoJson; + private String title; + + private Quadtree spatialIndex = new Quadtree(); + private Map pages = new HashMap<>(); + + public FPAtlas(File fpGeoJSON) throws IOException, JSONException { + String geoJsonStr = FileUtils.readFileToString(fpGeoJSON, "UTF-8"); + geoJson = new JSONObject(geoJsonStr); + parsePages(); + } + + private void parsePages() { + JSONArray features = geoJson.optJSONArray("features"); + if (features == null) return; + int len = features.length(); + // the 3rd feature is the first page + for (int i = 2; i < len; ++i) { + JSONObject o = features.optJSONObject(i); + if (o != null) { + FPPage p = new FPPage(o); + pages.put(p.pageNumber(), p); + spatialIndex.insert(p.envelope(), p); + } + } + } + + public String title() { + if (title != null) return title; + JSONArray features = geoJson.optJSONArray("features"); + if (features == null) return null; + JSONObject properties = features.optJSONObject(0); + title = properties.optString("title"); + return title; + } + + +} \ No newline at end of file diff --git a/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPPage.java b/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPPage.java new file mode 100644 index 0000000..f6402b5 --- /dev/null +++ b/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPPage.java @@ -0,0 +1,62 @@ +package org.fieldpapers.model; + +import com.vividsolutions.jts.geom.Coordinate; +import com.vividsolutions.jts.geom.Envelope; +import com.vividsolutions.jts.geom.Geometry; +import com.vividsolutions.jts.geom.GeometryFactory; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +public class FPPage { + + private JSONObject feature; + private Geometry geom; + private Envelope env; + + private String pageNumber; + private String url; + + private GeometryFactory geometryFactory = new GeometryFactory(); + + public FPPage(JSONObject feature) { + this.feature = feature; + buildGeometry(); + buildEnvelope(); + } + + private void buildGeometry() { + try { + JSONArray coords = feature.getJSONObject("geometry").getJSONArray("coordinates").getJSONArray(0); + int len = coords.length(); + Coordinate[] coordinates = new Coordinate[len]; + for (int i = 0; i < len; ++i) { + JSONArray coord = coords.getJSONArray(i); + double lng = coord.getDouble(0); + double lat = coord.getDouble(1); + coordinates[i] = new Coordinate(lng, lat); + } + geom = geometryFactory.createPolygon(coordinates); + } catch (JSONException e) { + e.printStackTrace(); + } + } + + private void buildEnvelope() { + env = geom.getEnvelopeInternal(); + } + + public String pageNumber() { + + return null; + } + + public Geometry geometry() { + return geom; + } + + public Envelope envelope() { + return env; + } +} diff --git a/MapboxAndroidSDK/src/main/java/org/fieldpapers/renderer/FPOverlay.java b/MapboxAndroidSDK/src/main/java/org/fieldpapers/renderer/FPOverlay.java new file mode 100644 index 0000000..ea48e98 --- /dev/null +++ b/MapboxAndroidSDK/src/main/java/org/fieldpapers/renderer/FPOverlay.java @@ -0,0 +1,15 @@ +package org.fieldpapers.renderer; + +import android.graphics.Canvas; + +import com.mapbox.mapboxsdk.overlay.Overlay; +import com.mapbox.mapboxsdk.views.MapView; + +public class FPOverlay extends Overlay { + + @Override + protected void draw(Canvas c, MapView osmv, boolean shadow) { + + } + +} diff --git a/app/app.iml b/app/app.iml index d620c49..5902d5c 100644 --- a/app/app.iml +++ b/app/app.iml @@ -101,8 +101,8 @@ - + diff --git a/app/build.gradle b/app/build.gradle index ca2d057..677f0fa 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,8 +12,8 @@ android { applicationId "org.redcross.openmapkit" minSdkVersion 16 targetSdkVersion 21 - versionCode 19 - versionName "0.19" + versionCode 20 + versionName "0.20" } buildTypes { release { diff --git a/app/src/main/java/org/redcross/openmapkit/ExternalStorage.java b/app/src/main/java/org/redcross/openmapkit/ExternalStorage.java index 2045d6c..d9ad680 100644 --- a/app/src/main/java/org/redcross/openmapkit/ExternalStorage.java +++ b/app/src/main/java/org/redcross/openmapkit/ExternalStorage.java @@ -228,6 +228,19 @@ public static Set deploymentOSMXmlFiles(String deploymentName) { return osmXmlFiles; } + public static File deploymentFPFile(String deploymentName) { + Set osmXmlFiles = new HashSet<>(); + File storageDir = Environment.getExternalStorageDirectory(); + File deploymentDir = new File(storageDir, APP_DIR + "/" + DEPLOYMENTS_DIR + "/" + deploymentName); + File[] files = deploymentDir.listFiles(); + for (File f : files) { + if (f.getName().equals("fp.geojson")) { + return f; + } + } + return null; + } + public static Set deploymentMBTilesFiles(String deploymentName) { Set mbtilesFiles = new HashSet<>(); File storageDir = Environment.getExternalStorageDirectory(); diff --git a/app/src/main/java/org/redcross/openmapkit/deployments/Deployment.java b/app/src/main/java/org/redcross/openmapkit/deployments/Deployment.java index 66150ca..1077567 100644 --- a/app/src/main/java/org/redcross/openmapkit/deployments/Deployment.java +++ b/app/src/main/java/org/redcross/openmapkit/deployments/Deployment.java @@ -156,6 +156,7 @@ public void addToMap() { } public void addFPToMap() { + File f = ExternalStorage.deploymentFPFile(name()); } From d4c878c0d07846b0f3e2066eaabfcf15dddce3b9 Mon Sep 17 00:00:00 2001 From: Nicholas Hallahan Date: Thu, 21 Apr 2016 10:52:53 -0700 Subject: [PATCH 02/12] #45 FPAtlas build out singleton usage --- .../java/org/fieldpapers/model/FPAtlas.java | 63 ++++++++++++++++--- .../openmapkit/deployments/Deployment.java | 14 ++++- 2 files changed, 69 insertions(+), 8 deletions(-) diff --git a/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java b/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java index 28a676e..89f2362 100644 --- a/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java +++ b/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java @@ -1,5 +1,10 @@ package org.fieldpapers.model; +import android.app.Activity; +import android.content.Context; +import android.content.SharedPreferences; + +import com.mapbox.mapboxsdk.views.MapView; import com.vividsolutions.jts.index.quadtree.Quadtree; import org.apache.commons.io.FileUtils; @@ -14,15 +19,53 @@ public class FPAtlas { + private static final String PREVIOUS_FP_FILE_PATH = "org.redcross.openmapkit.PREVIOUS_FP_FILE_PATH"; + private static File fpGeoJson; + private static FPAtlas atlas; + private JSONObject geoJson; private String title; private Quadtree spatialIndex = new Quadtree(); private Map pages = new HashMap<>(); - public FPAtlas(File fpGeoJSON) throws IOException, JSONException { + public static void load(File fpGeoJSON) throws IOException, JSONException { + /** + * Only load if the file specified is a file not currently loaded. + */ + if (fpGeoJSON.equals(FPAtlas.fpGeoJson)) return; + FPAtlas.fpGeoJson = fpGeoJSON; + atlas = new FPAtlas(fpGeoJSON); + } + + public static void addToMap(Activity activity, MapView mapView) throws IOException, JSONException { + /** + * Deal with SharedPreferences. Use it if we haven't explicitly loaded. Set it if we have. + */ + SharedPreferences preferences = activity.getPreferences(Context.MODE_PRIVATE); + if (fpGeoJson == null) { + String previousFpGeoJsonPath = preferences.getString(PREVIOUS_FP_FILE_PATH, null); + if (previousFpGeoJsonPath == null) return; + load(new File(previousFpGeoJsonPath)); + } else { + SharedPreferences.Editor editor = preferences.edit(); + editor.putString(PREVIOUS_FP_FILE_PATH, fpGeoJson.getAbsolutePath()); + } + + + } + + /** + * Singleton Constructor + * + * @param fpGeoJSON + * @throws IOException + * @throws JSONException + */ + private FPAtlas(File fpGeoJSON) throws IOException, JSONException { String geoJsonStr = FileUtils.readFileToString(fpGeoJSON, "UTF-8"); geoJson = new JSONObject(geoJsonStr); + parseTitle(); parsePages(); } @@ -41,14 +84,20 @@ private void parsePages() { } } + private void parseTitle() { + try { + title = geoJson.getJSONArray("features") + .getJSONObject(0) + .getJSONObject("properties") + .getString("title"); + + } catch (JSONException e) { + e.printStackTrace(); + } + } + public String title() { - if (title != null) return title; - JSONArray features = geoJson.optJSONArray("features"); - if (features == null) return null; - JSONObject properties = features.optJSONObject(0); - title = properties.optString("title"); return title; } - } \ No newline at end of file diff --git a/app/src/main/java/org/redcross/openmapkit/deployments/Deployment.java b/app/src/main/java/org/redcross/openmapkit/deployments/Deployment.java index 1077567..f4f5f9a 100644 --- a/app/src/main/java/org/redcross/openmapkit/deployments/Deployment.java +++ b/app/src/main/java/org/redcross/openmapkit/deployments/Deployment.java @@ -6,7 +6,9 @@ import com.google.common.io.Files; +import org.fieldpapers.model.FPAtlas; import org.json.JSONArray; +import org.json.JSONException; import org.json.JSONObject; import org.redcross.openmapkit.Basemap; import org.redcross.openmapkit.ExternalStorage; @@ -149,6 +151,10 @@ private void addJSONArrayToCollection(Collection list, JSONArray arr } } + /** + * Sets up appropriate files to be added to the map + * once we get back to the MapActivity. + */ public void addToMap() { addMBTilesToMap(); addFPToMap(); @@ -157,7 +163,13 @@ public void addToMap() { public void addFPToMap() { File f = ExternalStorage.deploymentFPFile(name()); - + try { + FPAtlas.load(f); + } catch (IOException e) { + e.printStackTrace(); + } catch (JSONException e) { + e.printStackTrace(); + } } public void addOSMToMap() { From 9b4fb8970c028ba69a46bcc29afea5b88f86fecc Mon Sep 17 00:00:00 2001 From: Nicholas Hallahan Date: Thu, 21 Apr 2016 12:08:06 -0700 Subject: [PATCH 03/12] #45 FPListener in MapActivity and FPAtlas is a MapListener --- .../org/fieldpapers/listeners/FPListener.java | 7 ++ .../java/org/fieldpapers/model/FPAtlas.java | 78 ++++++++++++++++++- .../org/redcross/openmapkit/MapActivity.java | 25 +++++- 3 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 MapboxAndroidSDK/src/main/java/org/fieldpapers/listeners/FPListener.java diff --git a/MapboxAndroidSDK/src/main/java/org/fieldpapers/listeners/FPListener.java b/MapboxAndroidSDK/src/main/java/org/fieldpapers/listeners/FPListener.java new file mode 100644 index 0000000..db8be0b --- /dev/null +++ b/MapboxAndroidSDK/src/main/java/org/fieldpapers/listeners/FPListener.java @@ -0,0 +1,7 @@ +package org.fieldpapers.listeners; + +public interface FPListener { + + void onMapCenterPageChangeMessage(String msg); + +} diff --git a/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java b/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java index 89f2362..e0f1bfc 100644 --- a/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java +++ b/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java @@ -4,10 +4,18 @@ import android.content.Context; import android.content.SharedPreferences; +import com.mapbox.mapboxsdk.api.ILatLng; +import com.mapbox.mapboxsdk.events.MapListener; +import com.mapbox.mapboxsdk.events.RotateEvent; +import com.mapbox.mapboxsdk.events.ScrollEvent; +import com.mapbox.mapboxsdk.events.ZoomEvent; +import com.mapbox.mapboxsdk.overlay.Marker; import com.mapbox.mapboxsdk.views.MapView; +import com.mapbox.mapboxsdk.views.MapViewListener; import com.vividsolutions.jts.index.quadtree.Quadtree; import org.apache.commons.io.FileUtils; +import org.fieldpapers.listeners.FPListener; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -17,7 +25,7 @@ import java.util.HashMap; import java.util.Map; -public class FPAtlas { +public class FPAtlas implements MapViewListener, MapListener { private static final String PREVIOUS_FP_FILE_PATH = "org.redcross.openmapkit.PREVIOUS_FP_FILE_PATH"; private static File fpGeoJson; @@ -26,6 +34,8 @@ public class FPAtlas { private JSONObject geoJson; private String title; + private Activity activity; + private Quadtree spatialIndex = new Quadtree(); private Map pages = new HashMap<>(); @@ -52,7 +62,14 @@ public static void addToMap(Activity activity, MapView mapView) throws IOExcepti editor.putString(PREVIOUS_FP_FILE_PATH, fpGeoJson.getAbsolutePath()); } + if (atlas == null) return; + + atlas.setActivity(activity); + mapView.setMapViewListener(atlas); + mapView.addListener(atlas); +// mapView.getOverlays().add(osmOverlay); +// mapView.invalidate(); } /** @@ -100,4 +117,63 @@ public String title() { return title; } + public void setActivity(Activity activity) { + this.activity = activity; + } + + private FPPage findMapCenterPage() { + + return null; + } + + + /** + * LISTENERS + */ + + @Override + public void onScroll(ScrollEvent event) { + findMapCenterPage(); + } + + @Override + public void onZoom(ZoomEvent event) { + findMapCenterPage(); + } + + @Override + public void onRotate(RotateEvent event) { + findMapCenterPage(); + } + + @Override + public void onShowMarker(MapView pMapView, Marker pMarker) { + + } + + @Override + public void onHideMarker(MapView pMapView, Marker pMarker) { + + } + + @Override + public void onTapMarker(MapView pMapView, Marker pMarker) { + + } + + @Override + public void onLongPressMarker(MapView pMapView, Marker pMarker) { + + } + + @Override + public void onTapMap(MapView pMapView, ILatLng pPosition) { + + } + + @Override + public void onLongPressMap(MapView pMapView, ILatLng pPosition) { + + } + } \ No newline at end of file diff --git a/app/src/main/java/org/redcross/openmapkit/MapActivity.java b/app/src/main/java/org/redcross/openmapkit/MapActivity.java index 9de11db..38d19fc 100644 --- a/app/src/main/java/org/redcross/openmapkit/MapActivity.java +++ b/app/src/main/java/org/redcross/openmapkit/MapActivity.java @@ -41,6 +41,9 @@ import com.spatialdev.osm.model.OSMElement; import com.spatialdev.osm.model.OSMNode; +import org.fieldpapers.listeners.FPListener; +import org.fieldpapers.model.FPAtlas; +import org.json.JSONException; import org.redcross.openmapkit.deployments.DeploymentsActivity; import org.redcross.openmapkit.odkcollect.ODKCollectHandler; import org.redcross.openmapkit.odkcollect.tag.ODKTag; @@ -54,7 +57,7 @@ import java.util.LinkedList; import java.util.Set; -public class MapActivity extends AppCompatActivity implements OSMSelectionListener { +public class MapActivity extends AppCompatActivity implements OSMSelectionListener, FPListener { protected static final String PREVIOUS_LAT = "org.redcross.openmapkit.PREVIOUS_LAT"; protected static final String PREVIOUS_LNG = "org.redcross.openmapkit.PREVIOUS_LNG"; @@ -142,6 +145,8 @@ protected void onCreate(Bundle savedInstanceState) { // initialize basemap object basemap = new Basemap(this); + initializeFP(); + initializeOsmXml(); // add user location toggle button @@ -332,6 +337,19 @@ protected void proportionMapAndList(int topWeight, int bottomWeight) { mBottomLinearLayout.setLayoutParams(new LinearLayout.LayoutParams(bottomLayoutParams.width, bottomLayoutParams.height, bottomWeight)); } + /** + * Adds FieldPapers Overlay to the map (if we have one). + */ + protected void initializeFP() { + try { + FPAtlas.addToMap(this, mapView); + } catch (IOException e) { + e.printStackTrace(); + } catch (JSONException e) { + e.printStackTrace(); + } + } + /** * Loads OSM XML stored on the device. */ @@ -789,4 +807,9 @@ private boolean isAppInstalled(String uri) { return app_installed; } + @Override + public void onMapCenterPageChangeMessage(String msg) { + + } + } From 3470e185fd9d035172c7e4141ccc15e2794b7929 Mon Sep 17 00:00:00 2001 From: Nicholas Hallahan Date: Thu, 21 Apr 2016 14:07:09 -0700 Subject: [PATCH 04/12] #45 Showing Field Papers title and page number that the center of the map is in --- .../java/org/fieldpapers/model/FPAtlas.java | 40 ++++++++++++++++++- .../java/org/fieldpapers/model/FPPage.java | 16 +++++--- .../org/redcross/openmapkit/MapActivity.java | 6 ++- app/src/main/res/layout/activity_map.xml | 12 +++++- 4 files changed, 65 insertions(+), 9 deletions(-) diff --git a/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java b/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java index e0f1bfc..d90dd21 100644 --- a/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java +++ b/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java @@ -9,9 +9,14 @@ import com.mapbox.mapboxsdk.events.RotateEvent; import com.mapbox.mapboxsdk.events.ScrollEvent; import com.mapbox.mapboxsdk.events.ZoomEvent; +import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.overlay.Marker; import com.mapbox.mapboxsdk.views.MapView; import com.mapbox.mapboxsdk.views.MapViewListener; +import com.vividsolutions.jts.geom.Coordinate; +import com.vividsolutions.jts.geom.Envelope; +import com.vividsolutions.jts.geom.Geometry; +import com.vividsolutions.jts.geom.GeometryFactory; import com.vividsolutions.jts.index.quadtree.Quadtree; import org.apache.commons.io.FileUtils; @@ -23,11 +28,14 @@ import java.io.File; import java.io.IOException; import java.util.HashMap; +import java.util.List; import java.util.Map; public class FPAtlas implements MapViewListener, MapListener { private static final String PREVIOUS_FP_FILE_PATH = "org.redcross.openmapkit.PREVIOUS_FP_FILE_PATH"; + public static final GeometryFactory GEOMETRY_FACTORY = new GeometryFactory(); + private static File fpGeoJson; private static FPAtlas atlas; @@ -35,6 +43,7 @@ public class FPAtlas implements MapViewListener, MapListener { private String title; private Activity activity; + private MapView mapView; private Quadtree spatialIndex = new Quadtree(); private Map pages = new HashMap<>(); @@ -65,6 +74,7 @@ public static void addToMap(Activity activity, MapView mapView) throws IOExcepti if (atlas == null) return; atlas.setActivity(activity); + atlas.setMapView(mapView); mapView.setMapViewListener(atlas); mapView.addListener(atlas); @@ -121,11 +131,37 @@ public void setActivity(Activity activity) { this.activity = activity; } - private FPPage findMapCenterPage() { + public void setMapView(MapView mapView) { + this.mapView = mapView; + } - return null; + private void findMapCenterPage() { + LatLng center = mapView.getCenter(); + Coordinate centerCoord = new Coordinate(center.getLongitude(), center.getLatitude()); + Envelope env = new Envelope(centerCoord); + List fpPages = spatialIndex.query(env); + for (Object p : fpPages) { + FPPage page = (FPPage)p; + Geometry pageGeom = page.geometry(); + if (pageGeom.contains(GEOMETRY_FACTORY.createPoint(centerCoord))) { + foundMapCenterPage(page); + } + } } + private void foundMapCenterPage(FPPage page) { + if (activity != null && activity instanceof FPListener) { + String msg = pageMessage(page); + ((FPListener)activity).onMapCenterPageChangeMessage(msg); + } + } + + private String pageMessage(FPPage page) { + return title() + " " + page.pageNumber(); + } + + + /** * LISTENERS diff --git a/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPPage.java b/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPPage.java index f6402b5..b70aadb 100644 --- a/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPPage.java +++ b/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPPage.java @@ -18,10 +18,9 @@ public class FPPage { private String pageNumber; private String url; - private GeometryFactory geometryFactory = new GeometryFactory(); - public FPPage(JSONObject feature) { this.feature = feature; + parsePageNumber(); buildGeometry(); buildEnvelope(); } @@ -37,7 +36,15 @@ private void buildGeometry() { double lat = coord.getDouble(1); coordinates[i] = new Coordinate(lng, lat); } - geom = geometryFactory.createPolygon(coordinates); + geom = FPAtlas.GEOMETRY_FACTORY.createPolygon(coordinates); + } catch (JSONException e) { + e.printStackTrace(); + } + } + + private void parsePageNumber() { + try { + pageNumber = feature.getJSONObject("properties").getString("page_number"); } catch (JSONException e) { e.printStackTrace(); } @@ -48,8 +55,7 @@ private void buildEnvelope() { } public String pageNumber() { - - return null; + return pageNumber; } public Geometry geometry() { diff --git a/app/src/main/java/org/redcross/openmapkit/MapActivity.java b/app/src/main/java/org/redcross/openmapkit/MapActivity.java index 38d19fc..188ab93 100644 --- a/app/src/main/java/org/redcross/openmapkit/MapActivity.java +++ b/app/src/main/java/org/redcross/openmapkit/MapActivity.java @@ -67,6 +67,7 @@ public class MapActivity extends AppCompatActivity implements OSMSelectionListen protected MapView mapView; protected OSMMap osmMap; + protected TextView fieldPapersMsg; protected ListView mTagListView; protected ImageButton mCloseListViewButton; protected ImageButton tagButton; @@ -141,6 +142,9 @@ protected void onCreate(Bundle savedInstanceState) { //get map from layout mapView = (MapView)findViewById(R.id.mapView); + + // get Field Papers Message + fieldPapersMsg = (TextView)findViewById(R.id.fieldPapersMsg); // initialize basemap object basemap = new Basemap(this); @@ -809,7 +813,7 @@ private boolean isAppInstalled(String uri) { @Override public void onMapCenterPageChangeMessage(String msg) { - + fieldPapersMsg.setText(msg); } } diff --git a/app/src/main/res/layout/activity_map.xml b/app/src/main/res/layout/activity_map.xml index 549ce3a..7b9789c 100644 --- a/app/src/main/res/layout/activity_map.xml +++ b/app/src/main/res/layout/activity_map.xml @@ -28,7 +28,17 @@ android:id="@+id/mapView" android:layout_width="fill_parent" android:layout_height="fill_parent" /> - + + + Date: Thu, 21 Apr 2016 15:17:52 -0700 Subject: [PATCH 05/12] #45 Trying out PathOverlay of pages --- .../java/org/fieldpapers/model/FPAtlas.java | 25 ++++++++++----- .../java/org/fieldpapers/model/FPPage.java | 31 ++++++++++++------- 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java b/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java index d90dd21..187a954 100644 --- a/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java +++ b/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java @@ -11,6 +11,8 @@ import com.mapbox.mapboxsdk.events.ZoomEvent; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.overlay.Marker; +import com.mapbox.mapboxsdk.overlay.Overlay; +import com.mapbox.mapboxsdk.overlay.PathOverlay; import com.mapbox.mapboxsdk.views.MapView; import com.mapbox.mapboxsdk.views.MapViewListener; import com.vividsolutions.jts.geom.Coordinate; @@ -27,6 +29,8 @@ import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -69,17 +73,13 @@ public static void addToMap(Activity activity, MapView mapView) throws IOExcepti } else { SharedPreferences.Editor editor = preferences.edit(); editor.putString(PREVIOUS_FP_FILE_PATH, fpGeoJson.getAbsolutePath()); + editor.apply(); } if (atlas == null) return; atlas.setActivity(activity); - atlas.setMapView(mapView); - - mapView.setMapViewListener(atlas); - mapView.addListener(atlas); -// mapView.getOverlays().add(osmOverlay); -// mapView.invalidate(); + atlas.setupMapView(mapView); } /** @@ -131,8 +131,11 @@ public void setActivity(Activity activity) { this.activity = activity; } - public void setMapView(MapView mapView) { + public void setupMapView(MapView mapView) { this.mapView = mapView; + mapView.setMapViewListener(this); + mapView.addListener(this); + addPathOverlaysToMapView(); } private void findMapCenterPage() { @@ -160,6 +163,14 @@ private String pageMessage(FPPage page) { return title() + " " + page.pageNumber(); } + private void addPathOverlaysToMapView() { + List overlays = mapView.getOverlays(); + Collection pagesCollection = pages.values(); + for (FPPage p : pagesCollection) { + overlays.add(p.pathOverlay()); + } + mapView.invalidate(); + } diff --git a/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPPage.java b/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPPage.java index b70aadb..fb425f0 100644 --- a/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPPage.java +++ b/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPPage.java @@ -1,9 +1,11 @@ package org.fieldpapers.model; +import android.graphics.Path; + +import com.mapbox.mapboxsdk.overlay.PathOverlay; import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Envelope; import com.vividsolutions.jts.geom.Geometry; -import com.vividsolutions.jts.geom.GeometryFactory; import org.json.JSONArray; import org.json.JSONException; @@ -14,6 +16,7 @@ public class FPPage { private JSONObject feature; private Geometry geom; private Envelope env; + private PathOverlay pathOverlay; private String pageNumber; private String url; @@ -21,12 +24,21 @@ public class FPPage { public FPPage(JSONObject feature) { this.feature = feature; parsePageNumber(); - buildGeometry(); + buildGeometryAndPathOverlay(); buildEnvelope(); } - private void buildGeometry() { + private void parsePageNumber() { + try { + pageNumber = feature.getJSONObject("properties").getString("page_number"); + } catch (JSONException e) { + e.printStackTrace(); + } + } + + private void buildGeometryAndPathOverlay() { try { + pathOverlay = new PathOverlay(); JSONArray coords = feature.getJSONObject("geometry").getJSONArray("coordinates").getJSONArray(0); int len = coords.length(); Coordinate[] coordinates = new Coordinate[len]; @@ -35,6 +47,7 @@ private void buildGeometry() { double lng = coord.getDouble(0); double lat = coord.getDouble(1); coordinates[i] = new Coordinate(lng, lat); + pathOverlay.addPoint(lat, lng); } geom = FPAtlas.GEOMETRY_FACTORY.createPolygon(coordinates); } catch (JSONException e) { @@ -42,14 +55,6 @@ private void buildGeometry() { } } - private void parsePageNumber() { - try { - pageNumber = feature.getJSONObject("properties").getString("page_number"); - } catch (JSONException e) { - e.printStackTrace(); - } - } - private void buildEnvelope() { env = geom.getEnvelopeInternal(); } @@ -65,4 +70,8 @@ public Geometry geometry() { public Envelope envelope() { return env; } + + public PathOverlay pathOverlay() { + return pathOverlay; + } } From 4a0b2069be2abd67d44c0e858a69c6a2967a1192 Mon Sep 17 00:00:00 2001 From: Nicholas Hallahan Date: Fri, 22 Apr 2016 13:52:12 -0700 Subject: [PATCH 06/12] #45 selected path overlay colors green --- .../com/spatialdev/osm/renderer/OSMLine.java | 28 +++++++++---------- .../java/org/fieldpapers/model/FPAtlas.java | 21 +++++++++++++- .../java/org/fieldpapers/model/FPPage.java | 18 ++++++++++-- 3 files changed, 50 insertions(+), 17 deletions(-) diff --git a/MapboxAndroidSDK/src/main/java/com/spatialdev/osm/renderer/OSMLine.java b/MapboxAndroidSDK/src/main/java/com/spatialdev/osm/renderer/OSMLine.java index eb49bb9..aadf588 100644 --- a/MapboxAndroidSDK/src/main/java/com/spatialdev/osm/renderer/OSMLine.java +++ b/MapboxAndroidSDK/src/main/java/com/spatialdev/osm/renderer/OSMLine.java @@ -13,24 +13,24 @@ public class OSMLine extends OSMPath { // OSM GREEN - private static final int DEFAULT_A = 125; - private static final int DEFAULT_R = 126; - private static final int DEFAULT_G = 188; - private static final int DEFAULT_B = 111; - private static final float DEFAULT_WIDTH = 13.0f; + public static final int DEFAULT_A = 125; + public static final int DEFAULT_R = 126; + public static final int DEFAULT_G = 188; + public static final int DEFAULT_B = 111; + public static final float DEFAULT_WIDTH = 13.0f; // GOLD - private static final int DEFAULT_SELECTED_A = 180; - private static final int DEFAULT_SELECTED_R = 255; - private static final int DEFAULT_SELECTED_G = 140; - private static final int DEFAULT_SELECTED_B = 0; - private static final float DEFAULT_SELECTED_WIDTH = 15.0f; + public static final int DEFAULT_SELECTED_A = 180; + public static final int DEFAULT_SELECTED_R = 255; + public static final int DEFAULT_SELECTED_G = 140; + public static final int DEFAULT_SELECTED_B = 0; + public static final float DEFAULT_SELECTED_WIDTH = 15.0f; // MAROON - private static final int DEFAULT_EDITED_A = 100; - private static final int DEFAULT_EDITED_R = 245; - private static final int DEFAULT_EDITED_G = 17; - private static final int DEFAULT_EDITED_B = 135; + public static final int DEFAULT_EDITED_A = 100; + public static final int DEFAULT_EDITED_R = 245; + public static final int DEFAULT_EDITED_G = 17; + public static final int DEFAULT_EDITED_B = 135; private float width; private int a; diff --git a/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java b/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java index 187a954..aa7f691 100644 --- a/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java +++ b/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java @@ -3,6 +3,7 @@ import android.app.Activity; import android.content.Context; import android.content.SharedPreferences; +import android.graphics.Color; import com.mapbox.mapboxsdk.api.ILatLng; import com.mapbox.mapboxsdk.events.MapListener; @@ -15,6 +16,7 @@ import com.mapbox.mapboxsdk.overlay.PathOverlay; import com.mapbox.mapboxsdk.views.MapView; import com.mapbox.mapboxsdk.views.MapViewListener; +import com.spatialdev.osm.renderer.OSMLine; import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Envelope; import com.vividsolutions.jts.geom.Geometry; @@ -29,7 +31,6 @@ import java.io.File; import java.io.IOException; -import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; @@ -52,6 +53,9 @@ public class FPAtlas implements MapViewListener, MapListener { private Quadtree spatialIndex = new Quadtree(); private Map pages = new HashMap<>(); + private PathOverlay selectedPathOverlay; + + public static void load(File fpGeoJSON) throws IOException, JSONException { /** * Only load if the file specified is a file not currently loaded. @@ -156,6 +160,7 @@ private void foundMapCenterPage(FPPage page) { if (activity != null && activity instanceof FPListener) { String msg = pageMessage(page); ((FPListener)activity).onMapCenterPageChangeMessage(msg); + setSelectedPathOverlay(page); } } @@ -163,8 +168,22 @@ private String pageMessage(FPPage page) { return title() + " " + page.pageNumber(); } + private void setSelectedPathOverlay(FPPage page) { + if (selectedPathOverlay != null) { + selectedPathOverlay.getPaint().setColor(Color.BLACK); + } + PathOverlay pathOverlay = page.pathOverlay(); + pathOverlay.getPaint().setARGB(255, OSMLine.DEFAULT_R, OSMLine.DEFAULT_G, OSMLine.DEFAULT_B); + selectedPathOverlay = pathOverlay; + } + private void addPathOverlaysToMapView() { List overlays = mapView.getOverlays(); + for (Overlay o : overlays) { + if (o instanceof PathOverlay) { + overlays.remove(o); + } + } Collection pagesCollection = pages.values(); for (FPPage p : pagesCollection) { overlays.add(p.pathOverlay()); diff --git a/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPPage.java b/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPPage.java index fb425f0..3e6d313 100644 --- a/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPPage.java +++ b/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPPage.java @@ -1,5 +1,7 @@ package org.fieldpapers.model; +import android.graphics.Color; +import android.graphics.Paint; import android.graphics.Path; import com.mapbox.mapboxsdk.overlay.PathOverlay; @@ -23,14 +25,15 @@ public class FPPage { public FPPage(JSONObject feature) { this.feature = feature; - parsePageNumber(); + parsePageNumberAndUrl(); buildGeometryAndPathOverlay(); buildEnvelope(); } - private void parsePageNumber() { + private void parsePageNumberAndUrl() { try { pageNumber = feature.getJSONObject("properties").getString("page_number"); + url = feature.getJSONObject("properties").getString("url"); } catch (JSONException e) { e.printStackTrace(); } @@ -39,6 +42,9 @@ private void parsePageNumber() { private void buildGeometryAndPathOverlay() { try { pathOverlay = new PathOverlay(); + Paint paint = pathOverlay.getPaint(); + paint.setColor(Color.BLACK); + paint.setStrokeWidth(6.0f); JSONArray coords = feature.getJSONObject("geometry").getJSONArray("coordinates").getJSONArray(0); int len = coords.length(); Coordinate[] coordinates = new Coordinate[len]; @@ -59,10 +65,18 @@ private void buildEnvelope() { env = geom.getEnvelopeInternal(); } + /** + * GETTERS + */ + public String pageNumber() { return pageNumber; } + public String url() { + return url; + } + public Geometry geometry() { return geom; } From 158045edb411741faa0a192113a94fa08890e88f Mon Sep 17 00:00:00 2001 From: Nicholas Hallahan Date: Fri, 22 Apr 2016 14:07:51 -0700 Subject: [PATCH 07/12] #45 puts the selected field paper page overlay in front of the others, but behind the osm overlays --- .../java/org/fieldpapers/model/FPAtlas.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java b/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java index aa7f691..48fb2aa 100644 --- a/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java +++ b/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java @@ -16,7 +16,9 @@ import com.mapbox.mapboxsdk.overlay.PathOverlay; import com.mapbox.mapboxsdk.views.MapView; import com.mapbox.mapboxsdk.views.MapViewListener; +import com.spatialdev.osm.marker.OSMItemizedIconOverlay; import com.spatialdev.osm.renderer.OSMLine; +import com.spatialdev.osm.renderer.OSMOverlay; import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Envelope; import com.vividsolutions.jts.geom.Geometry; @@ -173,6 +175,26 @@ private void setSelectedPathOverlay(FPPage page) { selectedPathOverlay.getPaint().setColor(Color.BLACK); } PathOverlay pathOverlay = page.pathOverlay(); + List overlays = mapView.getOverlays(); + + // Remove overlay to select and then put it in the right place in the list + // so that it is in front of the other PathOverlays but behind the OSM + // overlays. + overlays.remove(pathOverlay); + int len = overlays.size(); + boolean overlayMoved = false; + for (int i = 0; i < len; ++i) { + Overlay o = overlays.get(i); + if (o instanceof OSMOverlay || o instanceof OSMItemizedIconOverlay) { + overlays.add(i-1, pathOverlay); + overlayMoved = true; + break; + } + } + if (!overlayMoved) { + overlays.add(pathOverlay); + } + pathOverlay.getPaint().setARGB(255, OSMLine.DEFAULT_R, OSMLine.DEFAULT_G, OSMLine.DEFAULT_B); selectedPathOverlay = pathOverlay; } From a7b94b740ee9c13ad9b9a1e17a12f8731dfb959c Mon Sep 17 00:00:00 2001 From: Nicholas Hallahan Date: Fri, 22 Apr 2016 15:46:01 -0700 Subject: [PATCH 08/12] #45 Map taps will also select a FP page. Better view for showing the page message too. --- .../main/java/com/spatialdev/osm/OSMMap.java | 7 +++ .../java/org/fieldpapers/model/FPAtlas.java | 44 ++++++++++++++++--- .../java/org/fieldpapers/model/FPPage.java | 2 +- app/src/main/res/layout/activity_map.xml | 22 +++++----- 4 files changed, 56 insertions(+), 19 deletions(-) diff --git a/MapboxAndroidSDK/src/main/java/com/spatialdev/osm/OSMMap.java b/MapboxAndroidSDK/src/main/java/com/spatialdev/osm/OSMMap.java index c470ec0..e2e0f86 100644 --- a/MapboxAndroidSDK/src/main/java/com/spatialdev/osm/OSMMap.java +++ b/MapboxAndroidSDK/src/main/java/com/spatialdev/osm/OSMMap.java @@ -28,6 +28,8 @@ import com.spatialdev.osm.renderer.OSMOverlay; import com.vividsolutions.jts.geom.Envelope; +import org.fieldpapers.model.FPAtlas; + import java.util.List; public class OSMMap implements MapViewListener, MapListener { @@ -124,6 +126,11 @@ public void onLongPressMarker(MapView pMapView, Marker pMarker) { @Override public void onTapMap(MapView pMapView, ILatLng pPosition) { + FPAtlas atlas = FPAtlas.singleton(); + if (atlas != null) { + atlas.onTapMap(pMapView, pPosition); + } + float zoom = pMapView.getZoomLevel(); OSMElement.deselectAll(); diff --git a/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java b/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java index 48fb2aa..11c7820 100644 --- a/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java +++ b/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java @@ -88,6 +88,10 @@ public static void addToMap(Activity activity, MapView mapView) throws IOExcepti atlas.setupMapView(mapView); } + public static FPAtlas singleton() { + return atlas; + } + /** * Singleton Constructor * @@ -139,26 +143,44 @@ public void setActivity(Activity activity) { public void setupMapView(MapView mapView) { this.mapView = mapView; - mapView.setMapViewListener(this); + + /** + * There can only be one mapViewListener, so we have to reserve + * that privilege to OSMMap. This is ridiculous, but it's a weird + * oversight in the design of the Mapbox Android SDK Legacy. + * + * There can be multiple "listeners", which is a different interface + * that handles things like scroll. Map view listeners handle things like + * tap. Not sure why they are two different things... + * + * We look for the singleton of FPAtlas in OSMMap, and then notify + * onTapMap from there. Sorry. + */ +// mapView.setMapViewListener(this); + mapView.addListener(this); addPathOverlaysToMapView(); } private void findMapCenterPage() { LatLng center = mapView.getCenter(); - Coordinate centerCoord = new Coordinate(center.getLongitude(), center.getLatitude()); - Envelope env = new Envelope(centerCoord); + findPage(center); + } + + private void findPage(ILatLng latLng) { + Coordinate coord = new Coordinate(latLng.getLongitude(), latLng.getLatitude()); + Envelope env = new Envelope(coord); List fpPages = spatialIndex.query(env); for (Object p : fpPages) { FPPage page = (FPPage)p; Geometry pageGeom = page.geometry(); - if (pageGeom.contains(GEOMETRY_FACTORY.createPoint(centerCoord))) { - foundMapCenterPage(page); + if (pageGeom.contains(GEOMETRY_FACTORY.createPoint(coord))) { + foundPage(page); } } } - private void foundMapCenterPage(FPPage page) { + private void foundPage(FPPage page) { if (activity != null && activity instanceof FPListener) { String msg = pageMessage(page); ((FPListener)activity).onMapCenterPageChangeMessage(msg); @@ -254,9 +276,17 @@ public void onLongPressMarker(MapView pMapView, Marker pMarker) { } + /** + * This is not called by an actual map listener. It's called by: + * + * OSMMap#onTapMap + * + * @param pMapView + * @param pPosition + */ @Override public void onTapMap(MapView pMapView, ILatLng pPosition) { - + findPage(pPosition); } @Override diff --git a/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPPage.java b/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPPage.java index 3e6d313..992f4bb 100644 --- a/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPPage.java +++ b/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPPage.java @@ -44,7 +44,7 @@ private void buildGeometryAndPathOverlay() { pathOverlay = new PathOverlay(); Paint paint = pathOverlay.getPaint(); paint.setColor(Color.BLACK); - paint.setStrokeWidth(6.0f); + paint.setStrokeWidth(4.0f); JSONArray coords = feature.getJSONObject("geometry").getJSONArray("coordinates").getJSONArray(0); int len = coords.length(); Coordinate[] coordinates = new Coordinate[len]; diff --git a/app/src/main/res/layout/activity_map.xml b/app/src/main/res/layout/activity_map.xml index 7b9789c..c96f7b3 100644 --- a/app/src/main/res/layout/activity_map.xml +++ b/app/src/main/res/layout/activity_map.xml @@ -13,7 +13,17 @@ android:layout_weight="50" android:orientation="vertical" android:id="@+id/topLinearLayout" > - + + + - - Date: Fri, 22 Apr 2016 18:23:19 -0700 Subject: [PATCH 09/12] #45 Only shows the TextView name of the page when we have one selected --- .../src/main/java/org/fieldpapers/model/FPAtlas.java | 8 ++++++++ .../main/java/org/redcross/openmapkit/MapActivity.java | 7 ++++++- app/src/main/res/layout/activity_map.xml | 3 ++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java b/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java index 11c7820..8c645d1 100644 --- a/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java +++ b/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java @@ -176,8 +176,16 @@ private void findPage(ILatLng latLng) { Geometry pageGeom = page.geometry(); if (pageGeom.contains(GEOMETRY_FACTORY.createPoint(coord))) { foundPage(page); + return; } } + noPageFound(); + } + + private void noPageFound() { + if (activity != null && activity instanceof FPListener) { + ((FPListener)activity).onMapCenterPageChangeMessage(null); + } } private void foundPage(FPPage page) { diff --git a/app/src/main/java/org/redcross/openmapkit/MapActivity.java b/app/src/main/java/org/redcross/openmapkit/MapActivity.java index 188ab93..a53663b 100644 --- a/app/src/main/java/org/redcross/openmapkit/MapActivity.java +++ b/app/src/main/java/org/redcross/openmapkit/MapActivity.java @@ -813,7 +813,12 @@ private boolean isAppInstalled(String uri) { @Override public void onMapCenterPageChangeMessage(String msg) { - fieldPapersMsg.setText(msg); + if (msg != null) { + fieldPapersMsg.setText(msg); + fieldPapersMsg.setVisibility(View.VISIBLE); + } else { + fieldPapersMsg.setVisibility(View.GONE); + } } } diff --git a/app/src/main/res/layout/activity_map.xml b/app/src/main/res/layout/activity_map.xml index c96f7b3..180e8f9 100644 --- a/app/src/main/res/layout/activity_map.xml +++ b/app/src/main/res/layout/activity_map.xml @@ -22,7 +22,8 @@ android:id="@+id/fieldPapersMsg" android:background="@color/black" android:textColor="@color/osm_light_green" - android:paddingLeft="6dp" /> + android:paddingLeft="6dp" + android:visibility="gone" /> Date: Fri, 22 Apr 2016 18:33:10 -0700 Subject: [PATCH 10/12] #45 When we are outside of all of the pages, the selected path overlay gets cleared so that none of the boxes are green --- .../main/java/org/fieldpapers/model/FPAtlas.java | 8 +++++++- .../java/org/fieldpapers/renderer/FPOverlay.java | 15 --------------- 2 files changed, 7 insertions(+), 16 deletions(-) delete mode 100644 MapboxAndroidSDK/src/main/java/org/fieldpapers/renderer/FPOverlay.java diff --git a/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java b/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java index 8c645d1..b2c10d8 100644 --- a/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java +++ b/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java @@ -183,6 +183,7 @@ private void findPage(ILatLng latLng) { } private void noPageFound() { + clearSelectedPathOverlay(); if (activity != null && activity instanceof FPListener) { ((FPListener)activity).onMapCenterPageChangeMessage(null); } @@ -200,10 +201,15 @@ private String pageMessage(FPPage page) { return title() + " " + page.pageNumber(); } - private void setSelectedPathOverlay(FPPage page) { + private void clearSelectedPathOverlay() { if (selectedPathOverlay != null) { selectedPathOverlay.getPaint().setColor(Color.BLACK); + selectedPathOverlay = null; } + } + + private void setSelectedPathOverlay(FPPage page) { + clearSelectedPathOverlay(); PathOverlay pathOverlay = page.pathOverlay(); List overlays = mapView.getOverlays(); diff --git a/MapboxAndroidSDK/src/main/java/org/fieldpapers/renderer/FPOverlay.java b/MapboxAndroidSDK/src/main/java/org/fieldpapers/renderer/FPOverlay.java deleted file mode 100644 index ea48e98..0000000 --- a/MapboxAndroidSDK/src/main/java/org/fieldpapers/renderer/FPOverlay.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.fieldpapers.renderer; - -import android.graphics.Canvas; - -import com.mapbox.mapboxsdk.overlay.Overlay; -import com.mapbox.mapboxsdk.views.MapView; - -public class FPOverlay extends Overlay { - - @Override - protected void draw(Canvas c, MapView osmv, boolean shadow) { - - } - -} From 4f8a8ef4cb246a2b07122989af50ad73e06a1cf9 Mon Sep 17 00:00:00 2001 From: Nicholas Hallahan Date: Fri, 22 Apr 2016 18:59:32 -0700 Subject: [PATCH 11/12] #45 STRTree is performing better - queries only return objects in the envelope derived from a single coordinate. Not sure what's with QuadTree? --- .../src/main/java/org/fieldpapers/model/FPAtlas.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java b/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java index b2c10d8..5bca79a 100644 --- a/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java +++ b/MapboxAndroidSDK/src/main/java/org/fieldpapers/model/FPAtlas.java @@ -23,7 +23,7 @@ import com.vividsolutions.jts.geom.Envelope; import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.GeometryFactory; -import com.vividsolutions.jts.index.quadtree.Quadtree; +import com.vividsolutions.jts.index.strtree.STRtree; import org.apache.commons.io.FileUtils; import org.fieldpapers.listeners.FPListener; @@ -52,7 +52,7 @@ public class FPAtlas implements MapViewListener, MapListener { private Activity activity; private MapView mapView; - private Quadtree spatialIndex = new Quadtree(); + private STRtree spatialIndex = new STRtree(); private Map pages = new HashMap<>(); private PathOverlay selectedPathOverlay; From 9575f58151338cbe0762a83ad8b8f95068216139 Mon Sep 17 00:00:00 2001 From: Nicholas Hallahan Date: Fri, 22 Apr 2016 19:22:51 -0700 Subject: [PATCH 12/12] Closes #119 --- .../src/main/java/com/spatialdev/osm/OSMMap.java | 2 +- .../src/main/java/com/spatialdev/osm/model/JTSModel.java | 7 +++++-- app/src/main/java/org/redcross/openmapkit/MapActivity.java | 6 ++++++ .../main/java/org/redcross/openmapkit/OSMMapBuilder.java | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/MapboxAndroidSDK/src/main/java/com/spatialdev/osm/OSMMap.java b/MapboxAndroidSDK/src/main/java/com/spatialdev/osm/OSMMap.java index e2e0f86..36ba2ce 100644 --- a/MapboxAndroidSDK/src/main/java/com/spatialdev/osm/OSMMap.java +++ b/MapboxAndroidSDK/src/main/java/com/spatialdev/osm/OSMMap.java @@ -35,7 +35,7 @@ public class OSMMap implements MapViewListener, MapListener { // DEBUG MODE - SHOW ENVELOPE AROUND TAP ON MAP - private static final boolean DEBUG = true; + private static final boolean DEBUG = false; private MapView mapView; private JTSModel jtsModel; diff --git a/MapboxAndroidSDK/src/main/java/com/spatialdev/osm/model/JTSModel.java b/MapboxAndroidSDK/src/main/java/com/spatialdev/osm/model/JTSModel.java index 45ca4b9..62cab14 100644 --- a/MapboxAndroidSDK/src/main/java/com/spatialdev/osm/model/JTSModel.java +++ b/MapboxAndroidSDK/src/main/java/com/spatialdev/osm/model/JTSModel.java @@ -166,8 +166,11 @@ public OSMElement queryFromTap(ILatLng latLng, float zoom) { } -// Log.i("queryFromTap closestElement", closestElement.toString()); - return closestElement; + Geometry closestElementGeom = closestElement.getJTSGeom(); + if (closestElementGeom != null && closestElementGeom.intersects(geometryFactory.createPoint(coord))) { + return closestElement; + } + return null; } private Envelope createTapEnvelope(Coordinate coord, double lat, double lng, float zoom) { diff --git a/app/src/main/java/org/redcross/openmapkit/MapActivity.java b/app/src/main/java/org/redcross/openmapkit/MapActivity.java index a53663b..ee2b413 100644 --- a/app/src/main/java/org/redcross/openmapkit/MapActivity.java +++ b/app/src/main/java/org/redcross/openmapkit/MapActivity.java @@ -289,6 +289,12 @@ public void onItemClick(AdapterView parent, View view, int position, long id) */ protected void identifyOSMFeature(OSMElement osmElement) { + // only open it if we render the OSM vectors, + // otherwise it is confusing for the user + if (mapView.getZoomLevel() < OSMMapBuilder.MIN_VECTOR_RENDER_ZOOM) { + return; + } + int numRequiredTags = 0; if (ODKCollectHandler.isODKCollectMode()) { Collection requiredTags = ODKCollectHandler.getODKCollectData().getRequiredTags(); diff --git a/app/src/main/java/org/redcross/openmapkit/OSMMapBuilder.java b/app/src/main/java/org/redcross/openmapkit/OSMMapBuilder.java index d2a69db..318521e 100644 --- a/app/src/main/java/org/redcross/openmapkit/OSMMapBuilder.java +++ b/app/src/main/java/org/redcross/openmapkit/OSMMapBuilder.java @@ -35,7 +35,7 @@ */ public class OSMMapBuilder extends AsyncTask { - private static final float MIN_VECTOR_RENDER_ZOOM = 18; + public static final float MIN_VECTOR_RENDER_ZOOM = 18; private static final String PERSISTED_OSM_FILES = "org.redcross.openmapkit.PERSISTED_OSM_FILES"; private static MapActivity mapActivity;