Runtime for Android加载mspk文件

0
分享 2019-09-17
版权声明:本文为博主原创文章,遵循
CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 本文链接:
https://blog.csdn.net/gislaozhang/article/details/100766380
最近在测试一个问题,如何在Android端加载由ArcGIS Pro制作的mspk,按照常规流程制作之后,发现在Android离线加载这个mspk文件的时候,代码检测加载状态已完成,但是手机端显示是黑色的,模型并没有显示出来。

通过查看官网帮助文档(https://pro.arcgis.com/en/pro-app/tool-reference/data-management/create-mobile-scene-package.htm )发现:
”Currently, ArcGIS Runtime SDK applications only support global scenes in the WGS84 coordinate system.“
也就是说需要在ArcGIS Pro中新建Globe Scene,然后设置空间参考为4326,再生成mspk。如果是local scene的话,runtime是无法加载。
那就去ArcGISPro的Globe Scene生成mspk,如下图:

在AndroidStudio中的代码,直接使用官网示例代码(https://developers.arcgis.com/android/latest/java/sample-code/open-mobile-scene-package/)。
/*
* runtime for android 100.8
*
*/

package com.esri.arcgisruntime.sample.openmobilescenepackage;

import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.esri.arcgisruntime.loadable.LoadStatus;
import com.esri.arcgisruntime.mapping.ArcGISScene;
import com.esri.arcgisruntime.mapping.ArcGISTiledElevationSource;
import com.esri.arcgisruntime.mapping.Basemap;
import com.esri.arcgisruntime.mapping.MobileScenePackage;
import com.esri.arcgisruntime.mapping.Surface;
import com.esri.arcgisruntime.mapping.view.SceneView;

public class MainActivity extends AppCompatActivity {

private static final String TAG = MainActivity.class.getSimpleName();
private SceneView mSceneView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mSceneView = findViewById(R.id.sceneView);
// create a scene and add it to the scene view
ArcGISScene scene = new ArcGISScene(Basemap.createImagery());

// add base surface for elevation data
final Surface surface = new Surface();
ArcGISTiledElevationSource elevationSource = new ArcGISTiledElevationSource(
getString(R.string.elevation_image_service_url));
surface.getElevationSources().add(elevationSource);
scene.setBaseSurface(surface);

// create a mobile scene package from a path to the mspk
MobileScenePackage mobileScenePackage = new MobileScenePackage(
getExternalFilesDir(null) + getString(R.string.philadelphia_mspk));
mobileScenePackage.addDoneLoadingListener(() -> {
if (mobileScenePackage.getLoadStatus() == LoadStatus.LOADED && !mobileScenePackage.getScenes().isEmpty()) {
mSceneView.setScene(mobileScenePackage.getScenes().get(0));
} else {
String error = "Failed to load mobile scene package: " + mobileScenePackage.getLoadError().getMessage();
Toast.makeText(this, error, Toast.LENGTH_LONG).show();
Log.e(TAG, error);
}
});
mobileScenePackage.loadAsync();
}

@Override
protected void onPause() {
mSceneView.pause();
super.onPause();
}

@Override
protected void onResume() {
super.onResume();
mSceneView.resume();
}

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

100.8的官网示例中的android manifest.xml中缺少读取数据的权限,需要自己加上:
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

提示:需要将官网示例中的mspk文件名替换为在ArcGISPro中生成的mspk的文件名。


将mspk文件拷贝到手机指定的路径,例如:
123.png

在这里需要补充的是runtime 100.8中给的读取离线数据的方法是
MobileScenePackage mobileScenePackage = new MobileScenePackage(
getExternalFilesDir(null) + getString(R.string.philadelphia_mspk));
其中的getExternalFilesDir(null)对应的路径是/storage/emulated/0/Android/data/com.esri.arcgisruntime.sample.openmobilescenepackage/files

其中/storage/emulated/0代表手机sdcard的根目录,Android是根目录中的一个文件夹,其它的依次类推。

最终在手机端的加载效果:

参考资料:
https://blog.csdn.net/Kelaker/article/details/80471352​  

 

0 个评论

要回复文章请先登录注册