-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/// Support for doing something awesome. | ||
/// | ||
/// More dartdocs go here. | ||
library; | ||
|
||
export 'src/cesium_3d_native_base.dart'; | ||
|
||
// TODO: Export any libraries intended for clients of this package. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// TODO: Put public facing types in this file. | ||
|
||
/// Checks if you are awesome. Spoiler: you are. | ||
class Awesome { | ||
bool get isAwesome => true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
class CesiumIonAsset { | ||
final int id; | ||
final String type; | ||
final String name; | ||
final String description; | ||
final int bytes; | ||
final String attribution; | ||
final DateTime dateAdded; | ||
final bool exportable; | ||
final String status; | ||
final int percentComplete; | ||
final bool archivable; | ||
|
||
CesiumIonAsset({ | ||
required this.id, | ||
required this.type, | ||
required this.name, | ||
required this.description, | ||
required this.bytes, | ||
required this.attribution, | ||
required this.dateAdded, | ||
required this.exportable, | ||
required this.status, | ||
required this.percentComplete, | ||
required this.archivable, | ||
}); | ||
|
||
factory CesiumIonAsset.fromJson(Map<String, dynamic> json) { | ||
return CesiumIonAsset( | ||
id: json['id'], | ||
type: json['type'], | ||
name: json['name'], | ||
description: json['description'], | ||
bytes: json['bytes'], | ||
attribution: json['attribution'], | ||
dateAdded: DateTime.parse(json['dateAdded']), | ||
exportable: json['exportable'], | ||
status: json['status'], | ||
percentComplete: json['percentComplete'], | ||
archivable: json['archivable'], | ||
); | ||
} | ||
|
||
Map<String, dynamic> toJson() { | ||
return { | ||
'id': id, | ||
'type': type, | ||
'name': name, | ||
'description': description, | ||
'bytes': bytes, | ||
'attribution': attribution, | ||
'dateAdded': dateAdded.toIso8601String(), | ||
'exportable': exportable, | ||
'status': status, | ||
'percentComplete': percentComplete, | ||
'archivable': archivable, | ||
}; | ||
} | ||
|
||
@override | ||
String toString() { | ||
return 'CesiumIonAsset(id: $id, type: $type, name: $name, status: $status, percentComplete: $percentComplete)'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import 'dart:convert'; | ||
import 'package:cesium_3d_native/src/ion/CesiumIonAsset.dart'; | ||
import 'package:http/http.dart' as http; | ||
|
||
class CesiumIonClient { | ||
final String accessToken; | ||
final String baseUrl = 'https://api.cesium.com/v1'; | ||
|
||
CesiumIonClient(this.accessToken); | ||
|
||
Future<List<CesiumIonAsset>> listAssets() async { | ||
final response = await http.get( | ||
Uri.parse('$baseUrl/assets'), | ||
headers: {'Authorization': 'Bearer $accessToken'}, | ||
); | ||
|
||
if (response.statusCode == 200) { | ||
final Map<String, dynamic> data = json.decode(response.body); | ||
return (data['items'] as List) | ||
.map((item) => CesiumIonAsset.fromJson(item)) | ||
.toList(); | ||
} else { | ||
throw Exception('Failed to load assets: ${response.statusCode}'); | ||
} | ||
} | ||
|
||
Future<CesiumIonAsset> getAsset(int assetId) async { | ||
final response = await http.get( | ||
Uri.parse('$baseUrl/assets/$assetId'), | ||
headers: {'Authorization': 'Bearer $accessToken'}, | ||
); | ||
|
||
if (response.statusCode == 200) { | ||
return CesiumIonAsset.fromJson(json.decode(response.body)); | ||
} else { | ||
throw Exception('Failed to fetch asset: ${response.statusCode}'); | ||
} | ||
} | ||
|
||
Future<CesiumIonAsset> createAsset(Map<String, dynamic> assetData) async { | ||
final response = await http.post( | ||
Uri.parse('$baseUrl/assets'), | ||
headers: { | ||
'Authorization': 'Bearer $accessToken', | ||
'Content-Type': 'application/json', | ||
}, | ||
body: json.encode(assetData), | ||
); | ||
|
||
if (response.statusCode == 200) { | ||
return CesiumIonAsset.fromJson(json.decode(response.body)['assetMetadata']); | ||
} else { | ||
throw Exception('Failed to create asset: ${response.statusCode}'); | ||
} | ||
} | ||
|
||
Future<void> waitUntilReady(int assetId) async { | ||
while (true) { | ||
final asset = await getAsset(assetId); | ||
if (asset.status == 'COMPLETE') { | ||
print('Asset tiled successfully'); | ||
print('View in ion: https://ion.cesium.com/assets/${asset.id}'); | ||
break; | ||
} else if (asset.status == 'DATA_ERROR') { | ||
throw Exception('ion detected a problem with the uploaded data.'); | ||
} else if (asset.status == 'ERROR') { | ||
throw Exception('An unknown tiling error occurred, please contact [email protected].'); | ||
} else { | ||
if (asset.status == 'NOT_STARTED') { | ||
print('Tiling pipeline initializing.'); | ||
} else { // IN_PROGRESS | ||
print('Asset is ${asset.percentComplete}% complete.'); | ||
} | ||
await Future.delayed(Duration(seconds: 10)); | ||
} | ||
} | ||
} | ||
} |