mapbox-gl-native icon indicating copy to clipboard operation
mapbox-gl-native copied to clipboard

Mapbox map is not loading, displays 'surface view' in android preview area

Open scrumvisualize opened this issue 10 years ago • 3 comments

*Platform: * Android 2.1.0 *_Mapbox SDK version:_com.mapbox.mapboxsdk:mapbox-android-sdk:4.2.0-beta.1@aar*
**Gradle details :

repositories { mavenCentral() }

dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.1.1' // add the Mapbox SDK dependency below compile ('com.mapbox.mapboxsdk:mapbox-android-sdk:4.2.0-beta.1@aar'){ transitive=true }

} ** _MainActivity.java_

public class MainActivity extends Activity {

private MapView mapView;
private MapboxMap map;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Mapbox access token only needs to be configured once in your app
    MapboxAccountManager.start(this,"token_here");
    // This contains the MapView in XML and needs to be called after the account manager
    setContentView(R.layout.activity_main);
    MapView mapView = (MapView) findViewById(R.id.mapview);
    mapView.onCreate(savedInstanceState);
    mapView.getMapAsync(new OnMapReadyCallback() {

        @Override
        public void onMapReady(MapboxMap mapboxMap) {
            mapboxMap.addMarker(new MarkerOptions()
                    .position(new LatLng(-36.90990, 174.77720))
                    .title("Hello World!")
                    .snippet("Welcome to my marker."));
            // Customize map with markers, polylines, etc.

        }
    });

}

// Add the mapView lifecycle to the activity's lifecycle methods
@Override
public void onResume() {
    super.onResume();
    mapView.onResume();
}

@Override
public void onPause() {
    super.onPause();
    mapView.onPause();
}

@Override
public void onLowMemory() {
    super.onLowMemory();
    mapView.onLowMemory();
}

@Override
protected void onDestroy() {
    super.onDestroy();
    mapView.onDestroy();
}

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    mapView.onSaveInstanceState(outState);
}

}


Steps to trigger behavior

1.Create a simple Mapbox map in Android latest version 2.1.0 as per the Mapbox link [ https://www.mapbox.com/android-sdk/examples/ ] 2.While previewing the map in Android preview screen, it is displaying a grey screen with 'surfaceview' 3.Map is not loading in the Android preview

Expected behavior

Actual behavior

image

scrumvisualize avatar Aug 12 '16 02:08 scrumvisualize

@scrumvisualize

In #5981 I added support for showing a sample image:

screen shot 2016-08-12 at 12 08 53 1

Allowing the map to render is not possible since we aren't actually running on an Android device. We could fallback to using the gl evironement of the development machine but since AS is cross platform this isn't a feasible option.

tobrun avatar Aug 12 '16 16:08 tobrun

@tobrun Seeing https://github.com/mapbox/mapbox-gl-native/pull/6624 made me think of other ways we could improve this:

  1. I see that the preview image is placed inside that SDK in MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/mapview_preview.png. Is there any way we could use a different location so that the preview image doesn't get bundled with the SDK in an app?
  2. Considering that the image is static and doesn't represent any custom styles, would we be saving even more space if we just placed a grayscale map, or a simple grid with a "MapboxMap" label?
  3. I remember there were some technical reasons not to use our static API to draw an actual image representing the selected style? Is this still applying, would it be worth it to ticket it separately to keep track of that possibility?

zugaldia avatar Oct 07 '16 13:10 zugaldia

@zugaldia

  1. I see that the preview image is placed inside that SDK in MapboxGLAndroidSDK/src/main/res/drawable-xxhdpi/mapview_preview.png. Is there any way we could use a different location so that the preview image doesn't get bundled with the SDK in an app?

Not as far as I know. It needs to be bundled as an android resource in the aar so that Android Studio can show it as an ImageView in the Layout Editor. There are multiple ways of resolving this but I think relying on Android BuildType (release/debug) will make most sense. To do this we introduce a separate 0kb image in res/drawable-xxxhdpi-release and place the current one in res/drawable-xxxhdpi-debug. This results in not bundling it in the apk that the end users use.

  1. Considering that the image is static and doesn't represent any custom styles, would we be saving even more space if we just placed a grayscale map, or a simple grid with a "MapboxMap" label?

Yes, we can, LMK your preference.

  1. I remember there were some technical reasons not to use our static API to draw an actual image representing the selected style? Is this still applying, would it be worth it to ticket it separately to keep track of that possibility?

I would love to integrate this but it's a paid API. We would execute a request every time the user would change a configuration eg. update LatLng, Style, etc. and we would end up charging users for developing. We currently have no ticket tracking this but I would be nice to have.

cc @pveugen

tobrun avatar Oct 07 '16 13:10 tobrun