提问人:MãĴď 提问时间:7/30/2023 最后编辑:MãĴď 更新时间:7/30/2023 访问量:29
向要素图层添加附件
add attachments to a feature layer
问:
如何从 servicefeature 表中获取 ArcGis 要素以执行添加附件。
我尝试了这个示例,并在此基础上使用不同的要素图层进行构建。https://github.com/Esri/arcgis-maps-sdk-kotlin-samples/tree/main/edit-feature-attachments
我记录了一些消息,例如图像大小,名称以及添加操作是否完成,但是当我检查上传的附件时,没有。我也检查了文档,但没有找到任何有帮助的示例或书面代码。该部门缺乏
这是我尝试的,在尝试上传图像后检查第 3 个屏幕截图。
private fun addFeatureAttachment(selectedImageUri: Uri) {
// display a loading dialog
val dialog = createLoadingDialog("Adding feature attachment").also {
it.show()
}
// create an input stream at the selected URI
contentResolver.openInputStream(selectedImageUri)?.use { imageInputStream ->
// get the byte array of the image input stream
val imageBytes: ByteArray = imageInputStream.readBytes()
// create the attachment name with the current time
val attachmentName = "attachment_${System.currentTimeMillis()}.png"
Log.d("attachment","attachment_${System.currentTimeMillis()}.png")
lifecycleScope.launch {
selectedArcGISFeature?.let { arcGISFeature ->
// add the attachment to the selected feature
arcGISFeature.addAttachment(
name = attachmentName,
contentType = "image/png",
data = imageBytes
).onFailure {
return@launch showError(it.message.toString())
}
// update the feature changes in the loaded service feature table
serviceFeatureTable.updateFeature(arcGISFeature).getOrElse {
return@launch showError(it.message.toString())
}
}
applyServerEdits(dialog)
}
}
}
private suspend fun applyServerEdits(dialog: AlertDialog) {
// close the bottom sheet, as it will be created
// after service changes are made
bottomSheet?.dismiss()
// apply edits to the server
val updatedServerResult = serviceFeatureTable.applyEdits()
updatedServerResult.onSuccess { edits ->
dialog.dismiss()
// check that the feature table was successfully updated
if (edits.isEmpty()) {
showToast("not")
return showError(getString(R.string.failure_edit_results))
}
// if the edits were made successfully, create the bottom sheet to display new changes.
selectedArcGISFeature?.let { createBottomSheet(it) }
}.onFailure {
showError(it.message.toString())
dialog.dismiss()
}
}
fun selectAttachment() {
val mediaIntent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
activityResultLauncher.launch(mediaIntent)
}
```
答: 暂无答案
评论