[android] #5237 - Enabled Updates To InfoWindow's Title and Snippet
This commit is contained in:
@@ -23,6 +23,7 @@ public abstract class Annotation implements Comparable<Annotation> {
|
||||
*/
|
||||
private long id = -1; // -1 unless added to a MapView
|
||||
protected MapboxMap mapboxMap;
|
||||
protected MapView mapView;
|
||||
|
||||
protected Annotation() {
|
||||
}
|
||||
@@ -68,6 +69,22 @@ public abstract class Annotation implements Comparable<Annotation> {
|
||||
return mapboxMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Don not use this method. Used internally by the SDK.
|
||||
*/
|
||||
public void setMapView(MapView mapView) {
|
||||
this.mapView = mapView;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the associated MapView
|
||||
*
|
||||
* @return The MapView
|
||||
*/
|
||||
protected MapView getMapView() {
|
||||
return mapView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(@NonNull Annotation annotation) {
|
||||
if (id < annotation.getId()) {
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.mapbox.mapboxsdk.annotations;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.View;
|
||||
|
||||
import com.mapbox.mapboxsdk.R;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
@@ -91,8 +90,9 @@ public class Marker extends Annotation {
|
||||
}
|
||||
}
|
||||
|
||||
void setSnippet(String snippet) {
|
||||
public void setSnippet(String snippet) {
|
||||
this.snippet = snippet;
|
||||
refreshInfoWindowContent();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,8 +112,25 @@ public class Marker extends Annotation {
|
||||
return icon;
|
||||
}
|
||||
|
||||
void setTitle(String title) {
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
refreshInfoWindowContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update only for default Marker's InfoWindow content for Title and Snippet
|
||||
*/
|
||||
private void refreshInfoWindowContent() {
|
||||
if (isInfoWindowShown() && mapView != null && mapboxMap != null && mapboxMap.getInfoWindowAdapter() == null) {
|
||||
InfoWindow infoWindow = getInfoWindow(mapView);
|
||||
if (mapView.getContext() != null) {
|
||||
infoWindow.adaptDefaultMarker(this, mapboxMap, mapView);
|
||||
}
|
||||
MapboxMap map = getMapboxMap();
|
||||
if (map != null) {
|
||||
map.updateMarker(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,6 +138,7 @@ public class Marker extends Annotation {
|
||||
*/
|
||||
public InfoWindow showInfoWindow(@NonNull MapboxMap mapboxMap, @NonNull MapView mapView) {
|
||||
setMapboxMap(mapboxMap);
|
||||
setMapView(mapView);
|
||||
MapboxMap.InfoWindowAdapter infoWindowAdapter = getMapboxMap().getInfoWindowAdapter();
|
||||
if (infoWindowAdapter != null) {
|
||||
// end developer is using a custom InfoWindowAdapter
|
||||
|
||||
@@ -9,7 +9,6 @@ import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
||||
import com.mapbox.mapboxsdk.annotations.IconFactory;
|
||||
import com.mapbox.mapboxsdk.annotations.Marker;
|
||||
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
|
||||
@@ -58,12 +57,13 @@ public class DynamicMarkerChangeActivity extends AppCompatActivity {
|
||||
// Create marker
|
||||
MarkerOptions markerOptions = new MarkerOptions()
|
||||
.position(LAT_LNG_CHELSEA)
|
||||
.icon(mIconFactory.fromResource(R.drawable.ic_chelsea));
|
||||
.icon(mIconFactory.fromResource(R.drawable.ic_chelsea))
|
||||
.title(getString(R.string.dynamic_marker_chelsea_title))
|
||||
.snippet(getString(R.string.dynamic_marker_chelsea_snippet));
|
||||
mMarker = mapboxMap.addMarker(markerOptions);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||
fab.setColorFilter(ContextCompat.getColor(this, R.color.primary));
|
||||
fab.setOnClickListener(new View.OnClickListener() {
|
||||
@@ -84,6 +84,8 @@ public class DynamicMarkerChangeActivity extends AppCompatActivity {
|
||||
// update marker
|
||||
mMarker.setPosition(first ? LAT_LNG_CHELSEA : LAT_LNG_ARSENAL);
|
||||
mMarker.setIcon(mIconFactory.fromResource(first ? R.drawable.ic_chelsea : R.drawable.ic_arsenal));
|
||||
mMarker.setTitle(first ? getString(R.string.dynamic_marker_chelsea_title) : getString(R.string.dynamic_marker_arsenal_title));
|
||||
mMarker.setSnippet(first ? getString(R.string.dynamic_marker_chelsea_snippet) : getString(R.string.dynamic_marker_arsenal_snippet));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -154,4 +154,9 @@
|
||||
|
||||
<string name="geocoder_instructions">Tap Map To Geocode Where Black Marker Is Currently Located</string>
|
||||
|
||||
<string name="dynamic_marker_chelsea_title">Chelsea</string>
|
||||
<string name="dynamic_marker_chelsea_snippet">Stamford Bridge</string>
|
||||
<string name="dynamic_marker_arsenal_title">Arsenal</string>
|
||||
<string name="dynamic_marker_arsenal_snippet">Emirates Stadium</string>
|
||||
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user