Hello,
I need to load some FeatureLayers and FeatureTables stored in a Geodatbase saved on the device, to my scene,
but when I try to add them to my scene I have an Exception that says "Object is already owned", but I have cleared
the collections before trying add and I don't understand why I have this error.
My code to load the data is:
try {
var geoDb = Geodatabase(fullPath)
geoDb.addDoneLoadingListener {
try {
if(geoDb.loadStatus == LoadStatus.LOADED){
for(geoDbFeatureTable in geoDb.geodatabaseFeatureTables){
val featureLayer = FeatureLayer(geoDbFeatureTable)
//featureTables.add(geoDbFeature)
//val featureLayer = FeatureLayer(geoDbFeature)
featureTables.add(geoDbFeatureTable)
try{
FeatureLayerUtils().setGraphicLayer(featureLayer, layer)
featureLayers.add(featureLayer)
}
catch (e: InterruptedException){
Log.e("LOGERROR", "Error identifying resuts: " + e.message)
}
catch (e : ExecutionException){
Log.e("LOGERROR", "Error identifying results: " + e.message)
}
// Aggiornamento del Bounding Box
FeatureLayerUtils().updateBoundingBox(featureLayer, layer, arSceneView.originCamera.location)
featureLayer.sceneProperties.altitudeOffset = layer.defaultObjectY.toDouble()
featureLayer.sceneProperties.surfacePlacement = LayerSceneProperties.SurfacePlacement.RELATIVE
featureLayer.isVisible = layer.visible
featureLayersPair[layer] = featureLayer
featureLayers.add(featureLayer)
layerBoundingBoxPair[layer] = FeatureLayerUtils().createBoundingBox(arSceneView.originCamera.location, layer.maxDistanceFromOrigin.toDouble())
}
try {
arSceneView.sceneView.scene.tables.clear()
arSceneView.sceneView.scene.operationalLayers.clear()
arSceneView.sceneView.scene.tables.addAll(featureTables)
arSceneView.sceneView.scene.operationalLayers.addAll(featureLayers)
viewModel.setTables(featureLayers)
val tablesToFilter: Spinner = binding.assets.findViewById(R.id.tablesToFilter)
tablesToFilter.adapter = AssetSpinnerAdapter(applicationContext, featureLayers)
val featureLayer: FeatureLayer = featureLayers[0]
viewModel.setTableFilters(FeatureLayerUtils().getFeatureLayerStringFields(featureLayer))
val fieldFilters: Spinner = binding.assets.findViewById(R.id.fieldFilters)
val editTextSearchAsset: EditText = binding.assets.findViewById(R.id.editTextSearchAsset)
if (viewModel.uiState.value.tableFilters.isEmpty()) {
fieldFilters.visibility = View.GONE
editTextSearchAsset.visibility = View.GONE
} else {
fieldFilters.adapter = AssetFilterSpinnerAdapter(applicationContext, viewModel.uiState.value.tableFilters)
fieldFilters.visibility = View.VISIBLE
editTextSearchAsset.visibility = View.VISIBLE
}
}
catch (e : Exception){
Log.d(TAG, "Error: " + e.message)
}
}
}
catch (e : Exception){
Log.d(TAG, "Error")
}
}
geoDb.loadAsync()
}
catch (e : Error){
Log.d(TAG, "Error")
}Thanks yo all for the support!