Merge pull request #580 from neslihanturan/customMapMarkers

Add custom map marker icons
This commit is contained in:
Josephine Lim 2017-05-15 11:05:39 +02:00 committed by GitHub
commit 9a2ab847e7
3 changed files with 13 additions and 4 deletions

View file

@ -2,9 +2,11 @@ package fr.free.nrw.commons.nearby;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.drawable.Icon;
import android.preference.PreferenceManager;
import com.mapbox.mapboxsdk.annotations.Icon;
import com.mapbox.mapboxsdk.annotations.IconFactory;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@ -13,6 +15,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.location.LatLng;
import timber.log.Timber;
@ -86,13 +89,17 @@ public class NearbyController {
*/
public static List<NearbyBaseMarker> loadAttractionsFromLocationToBaseMarkerOptions(
LatLng curLatLng,
List<Place> placeList) {
List<Place> placeList,
Context context) {
List<NearbyBaseMarker> baseMarkerOptionses = new ArrayList<>();
placeList = placeList.subList(0, Math.min(placeList.size(), MAX_RESULTS));
for (Place place: placeList) {
String distance = formatDistanceBetween(curLatLng, place.location);
place.setDistance(distance);
Icon icon = IconFactory.getInstance(context)
.fromResource(R.drawable.custom_map_marker);
NearbyBaseMarker nearbyBaseMarker = new NearbyBaseMarker();
nearbyBaseMarker.title(place.name);
nearbyBaseMarker.position(
@ -100,6 +107,7 @@ public class NearbyController {
place.location.latitude,
place.location.longitude));
nearbyBaseMarker.place(place);
nearbyBaseMarker.icon(icon);
baseMarkerOptionses.add(nearbyBaseMarker);
}

View file

@ -55,8 +55,9 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment {
Type curLatLngType = new TypeToken<fr.free.nrw.commons.location.LatLng>() {}.getType();
curLatLng = gson.fromJson(gsonLatLng, curLatLngType);
baseMarkerOptionses = NearbyController
.loadAttractionsFromLocationToBaseMarkerOptions(curLatLng, placeList);
.loadAttractionsFromLocationToBaseMarkerOptions(curLatLng,
placeList,
getActivity());
}
Mapbox.getInstance(getActivity(),
getString(R.string.mapbox_commons_app_token));

Binary file not shown.

After

Width:  |  Height:  |  Size: 993 B