Skip to content

Commit

Permalink
feat: Tour KML visualizations built
Browse files Browse the repository at this point in the history
  • Loading branch information
AritraBiswas9788 committed Jul 24, 2024
1 parent 3e39831 commit 453b1f7
Show file tree
Hide file tree
Showing 13 changed files with 961 additions and 192 deletions.
Binary file added assets/lottie/addplaces.lottie
Binary file not shown.
Binary file added assets/lottie/orbit_black.lottie
Binary file not shown.
4 changes: 2 additions & 2 deletions lib/components/custom_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:flutter/material.dart';

class CustomDialog extends StatelessWidget {
final Text content;
final Text title;
final Widget content;
final Widget title;
final Color firstColor;
final Color secondColor;
final Widget headerIcon;
Expand Down
211 changes: 163 additions & 48 deletions lib/controllers/tour_controller.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import 'dart:io';
import 'dart:math';

import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart' as getx;
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:super_liquid_galaxy_controller/controllers/api_manager.dart';
import 'package:super_liquid_galaxy_controller/controllers/lg_connection.dart';
import 'package:super_liquid_galaxy_controller/data_class/map_position.dart';
import 'package:super_liquid_galaxy_controller/data_class/place_details_response.dart';
import 'package:super_liquid_galaxy_controller/data_class/place_info.dart';
import 'package:super_liquid_galaxy_controller/data_class/place_response.dart';
import 'package:super_liquid_galaxy_controller/controllers/api_manager.dart';
import 'package:super_liquid_galaxy_controller/utils/constants.dart';
import 'package:super_liquid_galaxy_controller/utils/geo_utils.dart';
import 'package:super_liquid_galaxy_controller/controllers/lg_connection.dart';
import 'package:super_liquid_galaxy_controller/utils/wikidatafetcher.dart';

import '../data_class/coordinate.dart';
import '../data_class/kml_element.dart';
import '../screens/test.dart';
import '../utils/kmlgenerator.dart';

class TourController extends getx.GetxController {
Expand All @@ -30,11 +27,15 @@ class TourController extends getx.GetxController {
MapPosition? lookAtPosition;
List<PlaceInfo> masterList = <PlaceInfo>[];
getx.RxList<PlaceInfo> placeList = <PlaceInfo>[].obs;
final isLoading = false.obs;
final isError = false.obs;
var isLoading = false.obs;
var isError = false.obs;
var isTouring = false.obs;
BuildContext? context;

//Set<String> categories = {};

var tourList = <PlaceInfo>[].obs;

@override
void onInit() {
apiClient = getx.Get.find();
Expand All @@ -57,10 +58,9 @@ class TourController extends getx.GetxController {
Size getScreenSize(BuildContext context) => MediaQuery.of(context).size;

void getPlaceBounds() async {

isLoading.value = true;
isError.value = false;
try{
isLoading.value = true;
isError.value = false;
try {
var queryText = label.value.split('\n').reversed.join(", ");
bool isCountry = label.value.split('\n').where((String str) {
return str.isNotEmpty;
Expand Down Expand Up @@ -97,8 +97,27 @@ class TourController extends getx.GetxController {
places = output.obj;
}
isLoading.value = false;
placeList.addAll(output.places);
masterList.addAll(output.places);

var listPlaces = output.places;
String state =
label.value.substring(label.value.indexOf('\n')).trim().toLowerCase();
String country = label.value
.substring(0, label.value.indexOf('\n'))
.trim()
.toLowerCase();
// print("$state");
// print(country);

for (final p in listPlaces) {
if (!(country.compareTo('') == 0)) {
p.country = country;
}
if (!(state.compareTo('') == 0)) {
p.state = state;
}
}
placeList.addAll(listPlaces);
masterList.addAll(listPlaces);
kmlResponse += output.kml;
if (kmlResponse.compareTo('') == 0) {
return;
Expand Down Expand Up @@ -127,29 +146,24 @@ class TourController extends getx.GetxController {
}
adjustPlaceMarks();
}
}
catch(e)
{
} catch (e) {
isLoading.value = false;
isError.value = true;
}
}

Future<void> runKml(String kmlResponse) async {

print("tapped");
String filename = generateRandomString(7);
await connectionClient.connectToLG();
if(!connectionClient.isConnected.value)
return;
File? file = await connectionClient.makeFile(filename,
kmlResponse);
if (!connectionClient.isConnected.value) return;
File? file = await connectionClient.makeFile(filename, kmlResponse);
print("made successfully");
await connectionClient.kmlFileUpload(
file!, filename);
await connectionClient.kmlFileUpload(file!, filename);
print("uploaded successfully");
await connectionClient.runKml(filename);
}

String generateRandomString(int len) {
var r = Random.secure();
const _chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz_';
Expand All @@ -163,24 +177,24 @@ class TourController extends getx.GetxController {
}

void adjustPlaceMarks() {

const maxLength = 20;
for(var (index,place) in placeList.indexed)
{
String text = place.name;
text = text.trim();
if(text.length >= maxLength)
{
text=text.replaceRange(maxLength,text.length,'...');
}
else
{
text = text + ' '*(maxLength-text.length+3);
}
text = text.substring(0,1).toUpperCase()+text.substring(1);
placeList[index].label = text;
for (var (index, place) in placeList.indexed) {
String text = place.name;
text = text.trim();
if (text.length >= maxLength) {
text = text.replaceRange(maxLength, text.length, '...');
} else {
text = text + ' ' * (maxLength - text.length + 3);
}
placeList.add(PlaceInfo(coordinate: Coordinates(latitude: 0.0, longitude: 0.0), label: "label", address: "address", category: "category", name: "name"));
text = text.substring(0, 1).toUpperCase() + text.substring(1);
placeList[index].label = text;
}
placeList.add(PlaceInfo(
coordinate: Coordinates(latitude: 0.0, longitude: 0.0),
label: "label",
address: "address",
category: "category",
name: "name"));
placeList.removeLast();
masterList.clear();
masterList.addAll(placeList);
Expand All @@ -190,16 +204,117 @@ class TourController extends getx.GetxController {
// wikiDataFetcher.getInfo();
}

void filterList(String query)
{
void filterList(String query) {
placeList.clear();
for(final item in masterList)
{
if(item.label.toLowerCase().contains(query.toLowerCase()) || item.address.toLowerCase().contains(query.toLowerCase()))
{
placeList.add(item);
}
for (final item in masterList) {
if (item.label.toLowerCase().contains(query.toLowerCase()) ||
item.address.toLowerCase().contains(query.toLowerCase())) {
placeList.add(item);
}
}
//adjustPlaceMarks();
}

void addToTourList(PlaceInfo placeOutput) {
tourList.add(placeOutput);
}

void tourButtonPressed() async {
isTouring.value = !isTouring.value;
if (isTouring.value) {
String kml = createTourKml();
await runKml(kml);
await runTour(tourList.value);
} else {
await runKml(kml);
if (lookAtPosition != null) {
await zoomToLocation(lookAtPosition!);
}
}
}

String createTourKml() {
String kml = '';

for (final place in tourList) {
kml += KMLGenerator.getTourPOIKML(place);
}
for (int i = 0; i < tourList.length - 1; i += 1) {
kml += KMLGenerator.addTourPaths(tourList[i], tourList[i + 1]);
}
print(kml);
return KMLGenerator.generateKml('69', kml);
}

Future<void> zoomToPoi(PlaceInfo place) async {
//print("loc");
MapPosition position = MapPosition.fromCameraPosition(
GeoUtils.getBoundsZoomLevel(
[place.coordinate.toLatLngMap(place.coordinate)],
getx.Get.context!.size!));
await connectionClient.flyToInstantWithoutSaving(position);
await connectionClient.cleanBalloon();
print("location req done");
print(position);
}

runTour(List<PlaceInfo> listPoi) async {
List<LatLng> coordsList = [];
for (final place in listPoi) {
coordsList.add(place.coordinate.toLatLngMap(place.coordinate));
if (!isTouring.value) {
return;
}
await zoomToPoi(place);
print("zoomed");
if (!isTouring.value) {
return;
}
MapPosition position = MapPosition.fromCameraPosition(
GeoUtils.getBoundsZoomLevel(
[place.coordinate.toLatLngMap(place.coordinate)],
getx.Get.context!.size!));
await Future.delayed(Duration(seconds: Constants.zoomInDuration));
await startOrbit(position);

MapPosition zoomPosition = MapPosition.fromCameraPosition(
GeoUtils.getBoundsZoomLevel(
coordsList,
getx.Get.context!.size!));
await connectionClient.flyToInstantWithoutSaving(zoomPosition);
isTouring.value = false;
// for (int i = 0; i <= 4; i++) {
// print("orbit$i");
// await startOrbit(position);
// if (!isTouring.value) {
// return;
// }
//}
}



//await runTour(listPoi);
}

Future<void> startOrbit(MapPosition position) async {
position.tilt = 60.0;
for (int i = 0; i <= 360; i += 17) {
if (!isTouring.value) {
return;
}
//print(MapPosition(latitude: position.latitude, longitude: position.longitude, bearing: i.toDouble(), tilt: position.tilt, zoom: position.zoom));
print("orbitReq");
connectionClient.flyToOrbit(MapPosition(
latitude: position.latitude,
longitude: position.longitude,
bearing: i.toDouble(),
tilt: position.tilt,
zoom: position.zoom));
await Future.delayed(const Duration(milliseconds: 1000));
}

return;
//startOrbit(position);
}
}
5 changes: 5 additions & 0 deletions lib/data_class/coordinate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ class Coordinates {
longitude = point.longitude;
}

LatLng toLatLng(Coordinates point)
{
return LatLng(point.latitude, point.longitude);
}

Coordinates.fromLatLngMap(mp.LatLng point) {
latitude = point.latitude;
longitude = point.longitude;
Expand Down
6 changes: 5 additions & 1 deletion lib/data_class/place_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class PlaceInfo {
String category;
String name;

String? state;
String? country;
String? imageLink;
String? description;
String? wikiMediaTag;
Expand All @@ -20,7 +22,9 @@ class PlaceInfo {
required this.category,
required this.name,
this.description,
this.imageLink
this.imageLink,
this.state,
this.country
});
@override
String toString() {
Expand Down
2 changes: 2 additions & 0 deletions lib/generated/assets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Assets {
static const String iconsTest = 'assets/icons/test.jpeg';
static const String iconsTravel = 'assets/icons/travel.png';
static const String iconsVoices = 'assets/icons/voices.png';
static const String lottieAddplaces = 'assets/lottie/addplaces.lottie';
static const String lottieConnected = 'assets/lottie/connected.lottie';
static const String lottieConnectionfailed = 'assets/lottie/connectionfailed.lottie';
static const String lottieFailedconnection = 'assets/lottie/failedconnection.lottie';
Expand All @@ -38,6 +39,7 @@ class Assets {
static const String lottieLoadingPlaces = 'assets/lottie/loading_places.lottie';
static const String lottieLoadingspinner = 'assets/lottie/loadingspinner.lottie';
static const String lottieOrbit = 'assets/lottie/orbit.lottie';
static const String lottieOrbitBlack = 'assets/lottie/orbit_black.lottie';
static const String lottieVoice = 'assets/lottie/voice.lottie';
static const String placeIconsArchaeology = 'assets/place_icons/archaeology.png';
static const String placeIconsCastle = 'assets/place_icons/castle.png';
Expand Down
Loading

0 comments on commit 453b1f7

Please sign in to comment.