summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobrun Van Nuland <tobrun.van.nuland@gmail.com>2017-09-29 10:20:50 +0200
committerTobrun <tobrun@mapbox.com>2017-10-04 15:20:46 +0200
commit6a846ce5a8ff1d62f4eafa3ef5bd0427096ca9e6 (patch)
treed52483c0bdbfd092b6bb4f22579a993c9908218e
parent42b4818f16f98a14fd14853ad10b0fdd742cd1f1 (diff)
downloadqtlocation-mapboxgl-6a846ce5a8ff1d62f4eafa3ef5bd0427096ca9e6.tar.gz
[android] - update symbol layer example with changing symbol location
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/ZoomFunctionSymbolLayerActivity.java41
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_symbols.xml8
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/actions.xml1
3 files changed, 42 insertions, 8 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/ZoomFunctionSymbolLayerActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/ZoomFunctionSymbolLayerActivity.java
index cd741a85b6..95c3929c1d 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/ZoomFunctionSymbolLayerActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/ZoomFunctionSymbolLayerActivity.java
@@ -4,6 +4,8 @@ import android.graphics.PointF;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
+import android.view.Menu;
+import android.view.MenuItem;
import com.google.gson.JsonObject;
import com.mapbox.mapboxsdk.geometry.LatLng;
@@ -48,6 +50,9 @@ public class ZoomFunctionSymbolLayerActivity extends AppCompatActivity {
private MapboxMap mapboxMap;
private GeoJsonSource source;
+ private boolean isInitialPosition = true;
+ private boolean isSelected = false;
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -59,15 +64,15 @@ public class ZoomFunctionSymbolLayerActivity extends AppCompatActivity {
@Override
public void onMapReady(@NonNull final MapboxMap map) {
mapboxMap = map;
- updateSource(false);
+ updateSource();
addLayer();
addMapClickListener();
}
});
}
- private void updateSource(boolean selected) {
- FeatureCollection featureCollection = createFeatureCollection(selected);
+ private void updateSource() {
+ FeatureCollection featureCollection = createFeatureCollection();
if (source != null) {
source.setGeoJson(featureCollection);
} else {
@@ -76,11 +81,15 @@ public class ZoomFunctionSymbolLayerActivity extends AppCompatActivity {
}
}
- private FeatureCollection createFeatureCollection(boolean selected) {
- Point point = Point.fromCoordinates(Position.fromCoordinates(-74.016181, 40.701745));
+ private FeatureCollection createFeatureCollection() {
+ Position position = isInitialPosition
+ ? Position.fromCoordinates(-74.01618140, 40.701745)
+ : Position.fromCoordinates(-73.988097, 40.749864);
+
+ Point point = Point.fromCoordinates(position);
Feature feature = Feature.fromGeometry(point);
JsonObject properties = new JsonObject();
- properties.addProperty(KEY_PROPERTY_SELECTED, selected);
+ properties.addProperty(KEY_PROPERTY_SELECTED, isSelected);
feature.setProperties(properties);
return FeatureCollection.fromFeatures(new Feature[] {feature});
}
@@ -118,8 +127,9 @@ public class ZoomFunctionSymbolLayerActivity extends AppCompatActivity {
List<Feature> featureList = mapboxMap.queryRenderedFeatures(screenPoint, LAYER_ID);
if (!featureList.isEmpty()) {
Feature feature = featureList.get(0);
- boolean isSelected = feature.getBooleanProperty(KEY_PROPERTY_SELECTED);
- updateSource(!isSelected);
+ boolean selectedNow = feature.getBooleanProperty(KEY_PROPERTY_SELECTED);
+ isSelected = !selectedNow;
+ updateSource();
} else {
Timber.e("No features found");
}
@@ -128,6 +138,21 @@ public class ZoomFunctionSymbolLayerActivity extends AppCompatActivity {
}
@Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.menu_symbols, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if (mapboxMap != null && item.getItemId() == R.id.menu_action_change_location) {
+ isInitialPosition = !isInitialPosition;
+ updateSource();
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
+ @Override
protected void onStart() {
super.onStart();
mapView.onStart();
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_symbols.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_symbols.xml
new file mode 100644
index 0000000000..3e5c8ab14c
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/menu/menu_symbols.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto">
+ <item
+ android:id="@+id/menu_action_change_location"
+ android:title="@string/menuitem_change_location"
+ app:showAsAction="never"/>
+</menu>
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/actions.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/actions.xml
index 865baede0e..4ca19def71 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/actions.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/actions.xml
@@ -11,6 +11,7 @@
<string name="menuitem_title_change_location_source_mock">Change to mock location source</string>
<string name="menuitem_title_change_location_source_null">Reset location source to null</string>
<string name="menuitem_change_icon_overlap">Toggle icon overlap</string>
+ <string name="menuitem_change_location">Change location</string>
<string name="button_camera_move">Move</string>
<string name="button_camera_ease">Ease</string>
<string name="button_camera_animate">Animate</string>