Skip to content

Commit

Permalink
#45 FPListener in MapActivity and FPAtlas is a MapListener
Browse files Browse the repository at this point in the history
  • Loading branch information
hallahan committed Apr 21, 2016
1 parent d4c878c commit 9b4fb89
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.fieldpapers.listeners;

public interface FPListener {

void onMapCenterPageChangeMessage(String msg);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -26,6 +34,8 @@ public class FPAtlas {
private JSONObject geoJson;
private String title;

private Activity activity;

private Quadtree spatialIndex = new Quadtree();
private Map<String, FPPage> pages = new HashMap<>();

Expand All @@ -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();
}

/**
Expand Down Expand Up @@ -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) {

}

}
25 changes: 24 additions & 1 deletion app/src/main/java/org/redcross/openmapkit/MapActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -142,6 +145,8 @@ protected void onCreate(Bundle savedInstanceState) {
// initialize basemap object
basemap = new Basemap(this);

initializeFP();

initializeOsmXml();

// add user location toggle button
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -789,4 +807,9 @@ private boolean isAppInstalled(String uri) {
return app_installed;
}

@Override
public void onMapCenterPageChangeMessage(String msg) {

}

}

0 comments on commit 9b4fb89

Please sign in to comment.