This commit is contained in:
Nicholas Hallahan
2015-07-16 17:38:23 -07:00
parent 0df1d64823
commit e84e13a85a
3 changed files with 183 additions and 0 deletions

View File

@@ -0,0 +1 @@
{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[-122.28813171386719,38.617406963286136],[-122.26959228515624,38.6833657775237],[-122.18238830566406,38.55568323796419],[-122.10617065429688,38.51378825951165],[-122.11509704589845,38.50465406475561],[-122.18307495117188,38.542795073979015],[-122.19955444335938,38.496593518947556],[-122.28813171386719,38.617406963286136]]]}}]}

View File

@@ -26,6 +26,8 @@ import android.widget.TextView;
import com.mapbox.mapboxgl.annotations.Marker;
import com.mapbox.mapboxgl.annotations.MarkerOptions;
import com.mapbox.mapboxgl.annotations.Polygon;
import com.mapbox.mapboxgl.annotations.PolygonOptions;
import com.mapbox.mapboxgl.annotations.Polyline;
import com.mapbox.mapboxgl.annotations.PolylineOptions;
import com.mapbox.mapboxgl.geometry.LatLng;
@@ -277,6 +279,7 @@ public class MainActivity extends ActionBarActivity {
mIsMarkersOn = true;
addMarkers();
addPolyline();
addPolygon();
}
} else {
if (mIsMarkersOn) {
@@ -311,6 +314,23 @@ public class MainActivity extends ActionBarActivity {
}
}
private void addPolygon() {
String geojsonStr = null;
try {
geojsonStr = Util.loadStringFromAssets(this, "small_polygon.geojson");
LatLng[] latLngs = Util.parseGeoJSONCoordinates(geojsonStr);
MapView map = mMapFragment.getMap();
Polygon polygon = map.addPolygon(new PolygonOptions()
.add(new LatLng(0, 0), new LatLng(0, 5), new LatLng(3, 5), new LatLng(0, 0))
.strokeColor(Color.MAGENTA)
.fillColor(Color.BLUE));
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}
private void removeAnnotations() {
mMapFragment.getMap().removeAnnotations();
}