From 934fa4933cf694cd835780b898b0ef0e51a74020 Mon Sep 17 00:00:00 2001 From: Asheem Mamoowala Date: Thu, 2 Nov 2017 14:09:54 -0700 Subject: [android] Add Grid source sample for Custom Geometry Source --- .../src/main/AndroidManifest.xml | 12 +- .../testapp/activity/style/GridSourceActivity.java | 151 +++++++++++++++++++++ .../src/main/res/layout/activity_grid_source.xml | 17 +++ .../src/main/res/values/descriptions.xml | 3 +- .../src/main/res/values/strings.xml | 1 + 5 files changed, 182 insertions(+), 2 deletions(-) create mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/GridSourceActivity.java create mode 100644 platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_grid_source.xml diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml index ee26f39f57..2ced75fc75 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml @@ -595,7 +595,17 @@ android:name="android.support.PARENT_ACTIVITY" android:value=".activity.FeatureOverviewActivity"/> - + + + + features = new ArrayList<>(); + double gridSpacing; + if (zoom >= 13) { + gridSpacing = 0.01; + } else if (zoom >= 11) { + gridSpacing = 0.05; + } else if (zoom == 10) { + gridSpacing = .1; + } else if (zoom == 9) { + gridSpacing = 0.25; + } else if (zoom == 8) { + gridSpacing = 0.5; + } else if (zoom >= 6) { + gridSpacing = 1; + } else if (zoom == 5) { + gridSpacing = 2; + } else if (zoom >= 4) { + gridSpacing = 5; + } else if (zoom == 2) { + gridSpacing = 10; + } else { + gridSpacing = 20; + } + + List gridLines = new ArrayList(); + for (double y = Math.ceil(bounds.getLatNorth() / gridSpacing) * gridSpacing; + y >= Math.floor(bounds.getLatSouth() / gridSpacing) * gridSpacing; y -= gridSpacing) { + gridLines.add(Arrays.asList(Position.fromCoordinates(bounds.getLonWest(), y), + Position.fromCoordinates(bounds.getLonEast(), y))); + } + features.add(Feature.fromGeometry(MultiLineString.fromCoordinates(gridLines))); + + gridLines = new ArrayList(); + for (double x = Math.floor(bounds.getLonWest() / gridSpacing) * gridSpacing; + x <= Math.ceil(bounds.getLonEast() / gridSpacing) * gridSpacing; x += gridSpacing) { + gridLines.add(Arrays.asList(Position.fromCoordinates(x, bounds.getLatSouth()), + Position.fromCoordinates(x, bounds.getLatNorth()))); + } + features.add(Feature.fromGeometry(MultiLineString.fromCoordinates(gridLines))); + + return FeatureCollection.fromFeatures(features); + } + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_grid_source); + + mapView = (MapView) findViewById(R.id.mapView); + mapView.onCreate(savedInstanceState); + mapView.getMapAsync(this); + } + + @Override + public void onMapReady(@NonNull final MapboxMap map) { + mapboxMap = map; + + // add source + CustomGeometrySource source = new CustomGeometrySource(ID_GRID_SOURCE, new GridProvider()); + mapboxMap.addSource(source); + + // add layer + LineLayer layer = new LineLayer(ID_GRID_LAYER, ID_GRID_SOURCE); + layer.setProperties( + lineColor(Color.parseColor("#000000")) + ); + + mapboxMap.addLayer(layer); + } + + @Override + protected void onStart() { + super.onStart(); + mapView.onStart(); + } + + @Override + public void onResume() { + super.onResume(); + mapView.onResume(); + } + + @Override + public void onPause() { + super.onPause(); + mapView.onPause(); + } + + @Override + protected void onStop() { + super.onStop(); + mapView.onStop(); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + mapView.onDestroy(); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + mapView.onSaveInstanceState(outState); + } + +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_grid_source.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_grid_source.xml new file mode 100644 index 0000000000..26b40b9ab6 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_grid_source.xml @@ -0,0 +1,17 @@ + + + + + + diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml index 33d9638712..d0aab04d93 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml @@ -43,7 +43,7 @@ Query rendered feature properties on click Count all rendered features in box Count all rendered symbols in box - Hightligh buildings in box + Highlight buildings in box Query source for features Shows a simple map Logs map change events to Logcat @@ -67,4 +67,5 @@ Use TextureView to render the map Resize a map rendered on a TextureView Animate a map rendered on a TextureView + Example Custom Geometry Source \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml index 15a916fac9..b2bae9279f 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml @@ -1,4 +1,5 @@ Mapbox Android SDK TestApp + Grid Source -- cgit v1.2.1