[android] #3317 #3239 - SpriteFactory Singleton, added different custom markers to InfoWindowActivity
This commit is contained in:
BIN
platform/android/MapboxGLAndroidSDKTestApp/src/main/assets/commercial-24.png
Executable file
BIN
platform/android/MapboxGLAndroidSDKTestApp/src/main/assets/commercial-24.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 308 B |
Binary file not shown.
|
After Width: | Height: | Size: 729 B |
BIN
platform/android/MapboxGLAndroidSDKTestApp/src/main/assets/town-hall-24.png
Executable file
BIN
platform/android/MapboxGLAndroidSDKTestApp/src/main/assets/town-hall-24.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 552 B |
@@ -1,21 +1,25 @@
|
||||
package com.mapbox.mapboxsdk.testapp;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.mapbox.mapboxsdk.annotations.Marker;
|
||||
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
|
||||
import com.mapbox.mapboxsdk.constants.Style;
|
||||
import com.mapbox.mapboxsdk.annotations.SpriteFactory;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.utils.ApiAccess;
|
||||
import com.mapbox.mapboxsdk.views.MapView;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
public class InfoWindowActivity extends AppCompatActivity {
|
||||
|
||||
private MapView mMapView;
|
||||
private Marker mCustomMarker;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -41,16 +45,38 @@ public class InfoWindowActivity extends AppCompatActivity {
|
||||
mMapView.addMarker(new MarkerOptions()
|
||||
.title("Intersection")
|
||||
.snippet("H St NW with 15th St NW")
|
||||
.icon(SpriteFactory.getInstance(this).fromAsset("london-underground-24.png"))
|
||||
.position(new LatLng(38.9002073, -77.03364419)));
|
||||
|
||||
mMapView.addMarker(new MarkerOptions()
|
||||
.title("White House")
|
||||
.snippet("The official residence and principal workplace of the President of the United States, located at 1600 Pennsylvania Avenue NW in Washington, D.C. It has been the residence of every U.S. president since John Adams in 1800.")
|
||||
.icon(mMapView.getSpriteFactory().fromAsset("town-hall-24.png"))
|
||||
.position(new LatLng(38.897705003219784, -77.03655168667463)));
|
||||
|
||||
mMapView.addMarker(new MarkerOptions().title("Intersection")
|
||||
.snippet("E St NW with 17th St NW")
|
||||
.icon(mMapView.getSpriteFactory().fromAsset("commercial-24.png"))
|
||||
.position(new LatLng(38.8954236, -77.0394623)));
|
||||
|
||||
final DecimalFormat formatter = new DecimalFormat("#.#####");
|
||||
mMapView.setOnMapLongClickListener(new MapView.OnMapLongClickListener() {
|
||||
@Override
|
||||
public void onMapLongClick(@NonNull LatLng point) {
|
||||
|
||||
// Remove previous added marker
|
||||
if (mCustomMarker != null) {
|
||||
mMapView.removeAnnotation(mCustomMarker);
|
||||
mCustomMarker = null;
|
||||
}
|
||||
|
||||
// Add marker on long click location with default marker image
|
||||
mCustomMarker = mMapView.addMarker(new MarkerOptions()
|
||||
.title("Custom Marker")
|
||||
.snippet(formatter.format(point.getLatitude()) + ", " + formatter.format(point.getLongitude()))
|
||||
.position(point));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -45,7 +45,7 @@ public class InfoWindowAdapterActivity extends AppCompatActivity {
|
||||
mMapView.setAccessToken(ApiAccess.getToken(this));
|
||||
mMapView.onCreate(savedInstanceState);
|
||||
|
||||
mSpriteFactory = new SpriteFactory(mMapView);
|
||||
mSpriteFactory = SpriteFactory.getInstance(this);
|
||||
mIconDrawable = ContextCompat.getDrawable(this, R.drawable.ic_location_city_24dp);
|
||||
|
||||
mMapView.setInfoWindowAdapter(new MapView.InfoWindowAdapter() {
|
||||
|
||||
Reference in New Issue
Block a user