mirror of
https://github.com/status-im/react-native-mapbox-gl.git
synced 2026-08-30 20:41:08 +00:00
Fix loading of local android resources (#323)
Implement local images for Android
This commit is contained in:
committed by
Bobby Sudekum
parent
5b0a3cfa45
commit
b621df7de1
+15
-2
@@ -62,9 +62,9 @@ public class ReactNativeMapboxGLManager extends SimpleViewManager<MapView> {
|
||||
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<MapView> {
|
||||
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<MapView> {
|
||||
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<MapView> {
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user