[android] #3276 - remove Marker View implementation
This commit is contained in:
@@ -5,22 +5,29 @@ import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
|
||||
import com.mapbox.mapboxsdk.annotations.Marker;
|
||||
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.testapp.model.annotations.CountryMarker;
|
||||
import com.mapbox.mapboxsdk.testapp.utils.GeoParseUtil;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
|
||||
@@ -58,6 +65,8 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
mMapboxMap = mapboxMap;
|
||||
|
||||
mMapboxMap.setMarkerViewAdapter(new TextAdapter(BulkMarkerActivity.this));
|
||||
|
||||
if (actionBar != null) {
|
||||
ArrayAdapter<CharSequence> spinnerAdapter = ArrayAdapter.createFromResource(actionBar.getThemedContext(), R.array.bulk_marker_list, android.R.layout.simple_spinner_item);
|
||||
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
@@ -67,9 +76,38 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private static class TextAdapter implements MapboxMap.MarkerViewAdapter<Marker> {
|
||||
|
||||
private LayoutInflater inflater;
|
||||
|
||||
public TextAdapter(@NonNull Context context) {
|
||||
this.inflater = LayoutInflater.from(context);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View getView(@NonNull Marker marker, @Nullable View convertView, @NonNull ViewGroup parent) {
|
||||
ViewHolder viewHolder;
|
||||
if (convertView == null) {
|
||||
viewHolder = new ViewHolder();
|
||||
convertView = inflater.inflate(R.layout.view_text_marker, parent, false);
|
||||
viewHolder.title = (TextView) convertView.findViewById(R.id.textView);
|
||||
convertView.setTag(viewHolder);
|
||||
} else {
|
||||
viewHolder = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
viewHolder.title.setText(marker.getTitle());
|
||||
return convertView;
|
||||
}
|
||||
|
||||
private static class ViewHolder {
|
||||
TextView title;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
int markersAmount = Integer.valueOf(getResources().getStringArray(R.array.bulk_marker_list)[position]);
|
||||
@@ -155,7 +193,7 @@ public class BulkMarkerActivity extends AppCompatActivity implements AdapterView
|
||||
location = locations.get(i);
|
||||
markerOptions.add(new MarkerOptions()
|
||||
.position(location)
|
||||
.title("Marker")
|
||||
.title(String.valueOf(i))
|
||||
.snippet(formatter.format(location.getLatitude()) + ", " + formatter.format(location.getLongitude())));
|
||||
}
|
||||
|
||||
|
||||
@@ -57,12 +57,12 @@ public class ViewMarkerActivity extends AppCompatActivity implements OnMapReadyC
|
||||
public void onMapReady(final MapboxMap mapboxMap) {
|
||||
|
||||
// Add country markers
|
||||
List<BaseMarkerOptions> countries = new ArrayList<>();
|
||||
final List<BaseMarkerOptions> countries = new ArrayList<>();
|
||||
countries.add(new CountryMarkerOptions().title("China").abbrevName("ch").flagRes(R.drawable.ic_china).position(new LatLng(31.230416, 121.473701)));
|
||||
countries.add(new CountryMarkerOptions().title("United States").abbrevName("us").flagRes(R.drawable.ic_us).position(new LatLng(38.907192, -77.036871)));
|
||||
countries.add(new CountryMarkerOptions().title("Brazil").abbrevName("br").flagRes(R.drawable.ic_brazil).position(new LatLng(-15.798200, -47.922363)));
|
||||
countries.add(new CountryMarkerOptions().title("Germany").abbrevName("de").flagRes(R.drawable.ic_germany).position(new LatLng(52.520007, 13.404954)));
|
||||
mapboxMap.addMarkers(countries);
|
||||
final List<Marker> markers = mapboxMap.addMarkers(countries);
|
||||
|
||||
// Add view marker adapter
|
||||
mapboxMap.setMarkerViewAdapter(new CountryAdapter(this));
|
||||
@@ -72,6 +72,13 @@ public class ViewMarkerActivity extends AppCompatActivity implements OnMapReadyC
|
||||
Log.d(MapboxConstants.TAG, "Country clicked " + ((CountryMarker) marker).getAbbrevName());
|
||||
}
|
||||
});
|
||||
|
||||
findViewById(R.id.fab).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mapboxMap.removeAnnotation(markers.get(2));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -27,10 +27,19 @@
|
||||
<com.mapbox.mapboxsdk.maps.MapView
|
||||
android:id="@id/mapView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:access_token="@string/mapbox_access_token"
|
||||
app:style_url="@string/style_light"
|
||||
app:zoom="1" />
|
||||
app:zoom="1"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@id/fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end|bottom"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:src="@drawable/ic_layers_24dp"
|
||||
app:backgroundTint="@color/primary" />
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/mapbox_green">
|
||||
|
||||
<TextView
|
||||
android:id="@id/textView"
|
||||
android:layout_width="wrap_content"
|
||||
android:textColor="@android:color/white"
|
||||
android:layout_height="wrap_content"
|
||||
android:textStyle="bold"
|
||||
android:padding="4dp"
|
||||
android:layout_centerInParent="true" />
|
||||
|
||||
</RelativeLayout>
|
||||
Reference in New Issue
Block a user