diff --git a/android/src/main/java/com/mapbox/reactnativemapboxgl/ReactNativeMapboxGLManager.java b/android/src/main/java/com/mapbox/reactnativemapboxgl/ReactNativeMapboxGLManager.java index 494086b..a2cf1ea 100644 --- a/android/src/main/java/com/mapbox/reactnativemapboxgl/ReactNativeMapboxGLManager.java +++ b/android/src/main/java/com/mapbox/reactnativemapboxgl/ReactNativeMapboxGLManager.java @@ -62,9 +62,9 @@ public class ReactNativeMapboxGLManager extends SimpleViewManager { public static final String PROP_COMPASS_IS_HIDDEN = "compassIsHidden"; public static final String PROP_LOGO_IS_HIDDEN = "logoIsHidden"; public static final String PROP_ATTRIBUTION_BUTTON_IS_HIDDEN = "attributionButtonIsHidden"; + private static String APPLICATION_ID; private MapView mapView; - @Override public String getName() { return REACT_CLASS; @@ -74,6 +74,7 @@ public class ReactNativeMapboxGLManager extends SimpleViewManager { public MapView createViewInstance(ThemedReactContext context) { mapView = new MapView(context, "pk.foo"); mapView.onCreate(null); + APPLICATION_ID = context.getPackageName(); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); return mapView; @@ -104,6 +105,13 @@ public class ReactNativeMapboxGLManager extends SimpleViewManager { return new BitmapDrawable(view.getResources(), x); } + public static Drawable drawableFromDrawableName(MapView view, String drawableName) { + Bitmap x; + int resID = view.getResources().getIdentifier(drawableName, "drawable", APPLICATION_ID); + x = BitmapFactory.decodeResource(view.getResources(), resID); + return new BitmapDrawable(view.getResources(), x); + } + @ReactProp(name = PROP_ANNOTATIONS) public void setAnnotationClear(MapView view, @Nullable ReadableArray value) { setAnnotations(view, value, true); @@ -138,7 +146,12 @@ public class ReactNativeMapboxGLManager extends SimpleViewManager { ReadableMap annotationImage = annotation.getMap("annotationImage"); String annotationURL = annotationImage.getString("url"); try { - Drawable image = drawableFromUrl(mapView, annotationURL); + Drawable image; + if (annotationURL.startsWith("image!")) { + image = drawableFromDrawableName(mapView, annotationURL.replace("image!", "")); + } else { + image = drawableFromUrl(mapView, annotationURL); + } IconFactory iconFactory = view.getIconFactory(); Icon icon = iconFactory.fromDrawable(image); marker.icon(icon);