-
Notifications
You must be signed in to change notification settings - Fork 493
Add symbol listener activity #1000
Changes from 7 commits
78150a2
f1428a9
56c1e29
8d9ba70
0beb4f2
f1848e5
ed6bf26
6a90f43
48e3584
5807497
bfef200
ec2b72b
c061caa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
package com.mapbox.mapboxandroiddemo.examples.plugins; | ||
|
||
import android.animation.ValueAnimator; | ||
import android.os.Bundle; | ||
import android.support.annotation.NonNull; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.widget.Toast; | ||
|
||
import com.mapbox.mapboxandroiddemo.R; | ||
import com.mapbox.mapboxsdk.Mapbox; | ||
import com.mapbox.mapboxsdk.geometry.LatLng; | ||
import com.mapbox.mapboxsdk.maps.MapView; | ||
import com.mapbox.mapboxsdk.maps.MapboxMap; | ||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; | ||
import com.mapbox.mapboxsdk.maps.Style; | ||
import com.mapbox.mapboxsdk.plugins.annotation.OnSymbolDragListener; | ||
import com.mapbox.mapboxsdk.plugins.annotation.OnSymbolLongClickListener; | ||
import com.mapbox.mapboxsdk.plugins.annotation.SymbolManager; | ||
import com.mapbox.mapboxsdk.plugins.annotation.SymbolOptions; | ||
import com.mapbox.mapboxsdk.plugins.annotation.Symbol; | ||
import com.mapbox.mapboxsdk.plugins.annotation.OnSymbolClickListener; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Change symbol icon by pressing on icon | ||
*/ | ||
public class SymbolListenerActivity extends AppCompatActivity implements | ||
OnMapReadyCallback { | ||
|
||
private MapView mapView; | ||
private MapboxMap mapboxMap; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can delete this. Field can be converted to a local variable (on line 62). |
||
private static final String LOG = "SymbolListenerActivity"; | ||
private static final String MAKI_ICON_CAFE = "cafe-15"; | ||
private static final String MAKI_ICON_HARBOR = "harbor-15"; | ||
private static final String MAKI_ICON_AIRPORT = "airport-15"; | ||
private SymbolManager symbolManager; | ||
private Symbol symbol; | ||
private final List<ValueAnimator> animators = new ArrayList<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can delete this. You're not using it anywhere in the example. |
||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
// Mapbox access token is configured here. This needs to be called either in your application | ||
// object or in the same activity which contains the mapview. | ||
Mapbox.getInstance(this, getString(R.string.access_token)); | ||
|
||
// This contains the MapView in XML and needs to be called after the access token is configured. | ||
setContentView(R.layout.activity_annotation_plugin_symbol_activity); | ||
|
||
mapView = findViewById(R.id.mapView); | ||
mapView.onCreate(savedInstanceState); | ||
mapView.getMapAsync(this); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: delete this blank line 😬 |
||
} | ||
|
||
@Override | ||
public void onMapReady(@NonNull final MapboxMap mapboxMap) { | ||
|
||
this.mapboxMap = mapboxMap; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can delete this. You don't use |
||
mapboxMap.setStyle(Style.DARK, new Style.OnStyleLoaded() { | ||
@Override | ||
public void onStyleLoaded(@NonNull Style style) { | ||
|
||
// Set up a SymbolManager instance | ||
symbolManager = new SymbolManager(mapView, mapboxMap, style); | ||
|
||
symbolManager.setIconAllowOverlap(true); | ||
symbolManager.setTextAllowOverlap(true); | ||
|
||
// Add symbol at specified lat/lon | ||
symbol = symbolManager.create(new SymbolOptions() | ||
.withLatLng(new LatLng(60.169091, 24.939876)) | ||
.withIconImage(MAKI_ICON_HARBOR) | ||
.withIconSize(2.0f) | ||
.setDraggable(true)); | ||
|
||
// Add click listener and change the symbol to a cafe icon on click | ||
symbolManager.addClickListener(new OnSymbolClickListener() { | ||
@Override | ||
public void onAnnotationClick(Symbol symbol) { | ||
Toast.makeText(SymbolListenerActivity.this, | ||
String.format("Symbol clicked"), | ||
Toast.LENGTH_SHORT).show(); | ||
symbol.setIconImage(MAKI_ICON_CAFE); | ||
symbolManager.update(symbol); | ||
} | ||
}); | ||
|
||
// Add long click listener and change the symbol to an airport icon on long click | ||
symbolManager.addLongClickListener((new OnSymbolLongClickListener() { | ||
@Override | ||
public void onAnnotationLongClick(Symbol symbol) { | ||
Toast.makeText(SymbolListenerActivity.this, | ||
String.format("Symbol long clicked"), | ||
Toast.LENGTH_SHORT).show(); | ||
symbol.setIconImage(MAKI_ICON_AIRPORT); | ||
symbolManager.update(symbol); | ||
} | ||
})); | ||
|
||
symbolManager.addDragListener(new OnSymbolDragListener() { | ||
@Override | ||
public void onAnnotationDragStarted(Symbol annotation) { | ||
langsmith marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
@Override | ||
public void onAnnotationDrag(Symbol symbol) { | ||
} | ||
langsmith marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@Override | ||
public void onAnnotationDragFinished(Symbol annotation) { | ||
} | ||
langsmith marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void onResume() { | ||
super.onResume(); | ||
mapView.onResume(); | ||
} | ||
|
||
@Override | ||
protected void onStart() { | ||
super.onStart(); | ||
mapView.onStart(); | ||
} | ||
|
||
@Override | ||
protected void onStop() { | ||
super.onStop(); | ||
mapView.onStop(); | ||
} | ||
|
||
@Override | ||
public void onPause() { | ||
super.onPause(); | ||
mapView.onPause(); | ||
} | ||
|
||
@Override | ||
public void onLowMemory() { | ||
super.onLowMemory(); | ||
mapView.onLowMemory(); | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
mapView.onDestroy(); | ||
} | ||
|
||
@Override | ||
protected void onSaveInstanceState(Bundle outState) { | ||
super.onSaveInstanceState(outState); | ||
mapView.onSaveInstanceState(outState); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:mapbox="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<com.mapbox.mapboxsdk.maps.MapView | ||
android:id="@+id/mapView" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
mapbox:mapbox_cameraTargetLng="24.939876" | ||
mapbox:mapbox_cameraTargetLat="60.169091" | ||
mapbox:mapbox_cameraZoom="12" | ||
/> | ||
|
||
</android.support.design.widget.CoordinatorLayout> |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -81,6 +81,7 @@ | |||||
<string name="activity_plugins_building_plugin_description">Use the building plugin to easily display 3D building height</string> | ||||||
<string name="activity_plugins_geojson_plugin_description">Easily retrieve GeoJSON data from a url, asset, or path</string> | ||||||
<string name="activity_plugins_places_plugin_description">Add location search ("geocoding") functionality and UI to search for any place in the world</string> | ||||||
<string name="activity_plugins_symbol_listener_description">Listen for Symbol interaction using the Annotations plugin and built-in listeners</string> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
<string name="activity_plugins_localization_plugin_description">Use the plugin to automatically change map label text to the language set on the device.</string> | ||||||
<string name="activity_plugins_place_picker_plugin_description">Use the place picker function of the Places Plugin to choose a specific location in the world.</string> | ||||||
<string name="activity_plugins_markerview_plugin_description">Create a marker with an Android-system View.</string> | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need this
compileOptions
section anymore. I tried removing it and the example works just fine for me.