0%

arcgis android 开发

Android Studio 项目配置

首先配置项目gradle

1
2
3
4
5
6
7
8
allprojects {
repositories {
...
maven {
url 'https://esri.jfrog.io/artifactory/arcgis'
}
}
}

然后配置模块gradle

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
android {
buildFeatures {
viewBinding true
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
}
dependencies {
implementation 'com.esri.arcgisruntime:arcgis-android:100.12.0'
}

然后更改manifests
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<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/Theme.TestArcGIS3D">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

三维部分

必要元素

scene 和 camera

1
2
3
4
5
6
7
val scene = ArcGISScene(Basemap.createImagery())
sceneView.scene = scene
val cameraLocation = Point(86.5, 28.5, 15000.0, SpatialReferences.getWgs84())
// Camera(location, heading, pitch, roll)
val camera = Camera(cameraLocation, 344.0, 72.0, 0.0)
this.camera = camera
sceneView.setViewpointCamera(camera)

加载自定义底图

1
2
3
4
5
val rasterFilePath = Environment.getExternalStorageDirectory().path + "/raster/google.tif"
val raster = Raster(rasterFilePath)
val rasterLayer = RasterLayer(raster)
val map = Basemap(rasterLayer)
scene.basemap = map

加载自定义dem

由于是loadable接口子类,需要设置回调来加载

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
val path = Environment.getExternalStorageDirectory().path + "/raster/test.tif"
val filePaths = ArrayList<String>()
filePaths.add(path)

try {
with(RasterElevationSource(filePaths)) {
this.addLoadStatusChangedListener { loadStatusChangedEvent ->
if ( loadStatusChangedEvent.newLoadStatus == LoadStatus.LOADED ){
sceneView.scene.baseSurface.elevationSources.add(this)
Log.d(tag, "loaded dem")
} else if (loadStatusChangedEvent.newLoadStatus == LoadStatus.FAILED_TO_LOAD) {
Log.d(tag, "load dem failed")
}
}
this.loadAsync()
}
} catch (e: IllegalAccessException) {
Log.d(tag, "load dem failed")
}

添加点

有五种放置方式分别是
- DRAPED_FLAT
- DRAPED_BILLBOARDED
- RELATIVE
- ABSOLUTE
- RELATIVE_TO_SCENE

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
val sceneRelatedPoint = Point(
86.5,28.5, 70.0,
this.camera.location.spatialReference
)
val triangleSymbol = SimpleMarkerSymbol(SimpleMarkerSymbol.Style.TRIANGLE, Color.RED, 10f)
val drapedFlatText = TextSymbol(
15F, "DRAPED FLAT", Color.MAGENTA, TextSymbol.HorizontalAlignment.LEFT,
TextSymbol.VerticalAlignment.TOP
).apply {
offsetY = 20f
}
val drapedFlatOverlay = GraphicsOverlay().apply {
sceneProperties.surfacePlacement = LayerSceneProperties.SurfacePlacement.DRAPED_FLAT
graphics.addAll(
arrayOf(
Graphic(surfaceRelatedPoint, triangleSymbol),
Graphic(surfaceRelatedPoint, drapedFlatText)
)
)
}
sceneView.graphicsOverlays.addAll(
arrayOf(
drapedFlatOverlay,
)
)

其他待完善