?1、上一节讲了arcgis for android 入门与提高(二)显示二维地图https://blog.csdn.net/HB_Programmer/article/details/119985752,接下来看看如何显示三维地图。
2、基于Android Studio,我们打开AndroidManifest.xml,添加网络权限和三维控件支持:
<uses-permission android:name="android.permission.INTERNET" />
<uses-feature android:glEsVersion="0x00030000" android:required="true" />
3、在activity_main.xml新建SceneView
<com.esri.arcgisruntime.mapping.view.SceneView
android:id="@+id/sceneView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
4、导入包
import com.esri.arcgisruntime.mapping.ArcGISScene;
import com.esri.arcgisruntime.mapping.ArcGISTiledElevationSource;
import com.esri.arcgisruntime.mapping.Basemap;
import com.esri.arcgisruntime.mapping.view.Camera;
import com.esri.arcgisruntime.mapping.view.SceneView;
5、核心代码:?
ArcGISScene scene = new ArcGISScene();
scene.setBasemap(Basemap.createImagery());
//scene.setBasemap(Basemap.createTopographic());
mSceneView = findViewById(R.id.sceneView);
mSceneView.setScene(scene);
ArcGISTiledElevationSource elevationSource = new ArcGISTiledElevationSource("https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer");
scene.getBaseSurface().getElevationSources().add(elevationSource);
Camera camera = new Camera(33.2, 112.1, 300000, 0.0, 10.0, 0.0);
mSceneView.setViewpointCamera(camera);
@Override
protected void onPause() {
super.onPause();
// pause SceneView
mSceneView.pause();
}
@Override
protected void onResume() {
super.onResume();
// resume SceneView
mSceneView.resume();
}
@Override protected void onDestroy() {
super.onDestroy();
// dispose SceneView
mSceneView.dispose();
}
6、完整代码:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android3dscene">
<uses-permission android:name="android.permission.INTERNET" />
<uses-feature android:glEsVersion="0x00030000" android:required="true" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.esri.arcgisruntime.mapping.view.SceneView
android:id="@+id/sceneView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
package com.example.android3dscene;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.esri.arcgisruntime.mapping.ArcGISScene;
import com.esri.arcgisruntime.mapping.ArcGISTiledElevationSource;
import com.esri.arcgisruntime.mapping.Basemap;
import com.esri.arcgisruntime.mapping.view.Camera;
import com.esri.arcgisruntime.mapping.view.SceneView;
public class MainActivity extends AppCompatActivity {
private SceneView mSceneView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArcGISScene scene = new ArcGISScene();
scene.setBasemap(Basemap.createImagery());
//scene.setBasemap(Basemap.createTopographic());
mSceneView = findViewById(R.id.sceneView);
mSceneView.setScene(scene);
ArcGISTiledElevationSource elevationSource = new ArcGISTiledElevationSource("https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer");
scene.getBaseSurface().getElevationSources().add(elevationSource);
Camera camera = new Camera(33.2, 112.1, 300000, 0.0, 10.0, 0.0);
mSceneView.setViewpointCamera(camera);
}
@Override
protected void onPause() {
super.onPause();
mSceneView.pause();
}
@Override
protected void onResume() {
super.onResume();
mSceneView.resume();
}
@Override
protected void onDestroy() {
super.onDestroy();
mSceneView.dispose();
}
}
?7、效果
?8、下一节讲解?arcgis for android 入门与提高(四)去掉属性标记和水印
欢迎订阅专栏!
|