map updated to 6

This commit is contained in:
2023-12-06 11:16:17 +05:30
parent 8d1c84d9fb
commit fa0587178f
19 changed files with 631 additions and 596 deletions

View File

@ -1,8 +1,9 @@
import 'dart:io';
import 'dart:typed_data';
import 'package:camera_camera/camera_camera.dart';
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:geojson/geojson.dart';
import 'package:geojson_vi/geojson_vi.dart';
import 'package:geolocator/geolocator.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart';
@ -26,7 +27,8 @@ import 'dart:async';
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
import 'package:rogapp/widgets/debug_widget.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:gallery_saver/gallery_saver.dart';
import 'package:image_gallery_saver/image_gallery_saver.dart';
class DestinationController extends GetxController {
late LocationSettings locationSettings;
@ -79,10 +81,9 @@ class DestinationController extends GetxController {
return DateFormat('yyyy-MM-dd HH:mm:ss').format(datetime);
}
Destination festuretoDestination(GeoJsonFeature fs) {
GeoJsonMultiPoint mp = fs.geometry as GeoJsonMultiPoint;
LatLng pt = LatLng(mp.geoSerie!.geoPoints[0].latitude,
mp.geoSerie!.geoPoints[0].longitude);
Destination festuretoDestination(GeoJSONFeature fs) {
GeoJSONMultiPoint mp = fs.geometry as GeoJSONMultiPoint;
LatLng pt = LatLng(mp.coordinates[0][1], mp.coordinates[0][0]);
//print("----- ${indexController.currentFeature[0].properties} -----");
@ -112,7 +113,7 @@ class DestinationController extends GetxController {
tags: fs.properties!["tags"]);
}
Future<void> startTimerLocation(GeoJsonFeature fs, double distance) async {
Future<void> startTimerLocation(GeoJSONFeature fs, double distance) async {
//print("---- in startTimer ----");
// print("---- is in rog is $is_in_rog ----");
double checkinRadious = fs.properties!['checkin_radius'] ?? double.infinity;
@ -570,32 +571,23 @@ class DestinationController extends GetxController {
// created_at: DateTime.now().microsecondsSinceEpoch);
// await db.insertGps(gps_data);
for (GeoJsonFeature fs in indexController.locations[0].collection) {
GeoJsonMultiPoint mp = fs.geometry as GeoJsonMultiPoint;
LatLng pt = LatLng(mp.geoSerie!.geoPoints[0].latitude,
mp.geoSerie!.geoPoints[0].longitude);
indexController.locations[0].features.forEach((fs) async {
GeoJSONMultiPoint mp = fs!.geometry as GeoJSONMultiPoint;
LatLng pt = LatLng(mp.coordinates[0][1], mp.coordinates[0][0]);
double latFs = pt.latitude;
double lonFs = pt.longitude;
var distanceFs = const Distance();
//print("--- points : ${pt.latitude}, ${pt.longitude} ----");
//print("--- points : ${pt.latitude}, ${pt.longitude} ----");
double distFs = distanceFs.as(
LengthUnit.Meter, LatLng(latFs, lonFs), LatLng(la, ln));
Destination des = festuretoDestination(fs);
//print(
// "--- position is ---- ${position.longitude}, --- ${position.longitude}----");
//print("--- distFs ---- $distFs, --- ${des.checkin_radious}----");
if (distFs <= des.checkin_radious! && skipGps == false) {
//print("--- 789 ---- $skip_gps----");
//near a location
//print("---- before call startTimerLocation ----");
await startTimerLocation(fs, distFs);
break;
// Note: You cannot break out of forEach. If you need to stop processing, you might have to reconsider using forEach.
}
}
});
if (gps_push_started == false) {
pushGPStoServer();
}
@ -644,11 +636,21 @@ class DestinationController extends GetxController {
populateDestinations();
}
_saveImageFromPath(String imagePath) async {
// Read the image file from the given path
File imageFile = File(imagePath);
Uint8List imageBytes = await imageFile.readAsBytes();
// Save the image to the gallery
final result = await ImageGallerySaver.saveImage(imageBytes);
print(result);
}
Future<void> makeBuyPoint(Destination destination, String imageurl) async {
DatabaseHelper db = DatabaseHelper.instance;
await db.updateBuyPoint(destination, imageurl);
populateDestinations();
await GallerySaver.saveImage(imageurl);
await _saveImageFromPath(imageurl);
if (indexController.currentUser.isNotEmpty) {
double cpNum = destination.cp!;
@ -690,7 +692,7 @@ class DestinationController extends GetxController {
// print("~~~~ inserted into db ~~~~");
}
await GallerySaver.saveImage(imageurl);
await _saveImageFromPath(imageurl);
populateDestinations();
@ -740,14 +742,23 @@ class DestinationController extends GetxController {
double distanceToStart() {
//print("=== gfs len == ${indexController.locations[0].collection.length}");
GeoJsonFeature gfs = indexController.locations[0].collection
.firstWhere((element) => festuretoDestination(element).cp == -1);
double distanceToDest = double.infinity;
if (indexController.locations[0].features.isEmpty) {
return distanceToDest;
}
GeoJSONFeature? gfs = indexController.locations[0].features.firstWhere(
(element) => festuretoDestination(element!).cp == -1,
orElse: () => null, // Provide a null value if no element is found
);
if (gfs == null) {
return distanceToDest;
}
Destination des = festuretoDestination(gfs);
//print("=== gfs == ${des.toMap()}");
double distanceToDest = double.infinity;
var distance = const Distance();
distanceToDest = distance.as(LengthUnit.Meter,
LatLng(currentLat, currentLon), LatLng(des.lat!, des.lon!));
@ -761,8 +772,14 @@ class DestinationController extends GetxController {
return 500;
}
Destination? ds;
GeoJsonFeature gfs = indexController.locations[0].collection
.firstWhere((element) => festuretoDestination(element).cp == -1);
GeoJSONFeature? gfs = indexController.locations[0].features.firstWhere(
(element) => festuretoDestination(element!).cp == -1,
orElse: () => null, // Provide a null value if no element is found
);
if (gfs == null) {
return _retValue;
}
ds = festuretoDestination(gfs);
var distance = const Distance();

View File

@ -1,7 +1,7 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_map/plugin_api.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_location_marker/flutter_map_location_marker.dart';
import 'package:flutter_map_marker_popup/flutter_map_marker_popup.dart';
import 'package:flutter_polyline_points/flutter_polyline_points.dart';
@ -42,64 +42,61 @@ class DestinationMapPage extends StatelessWidget {
//print("^^^^ $d ^^^^");
Marker m = Marker(
point: LatLng(d.lat!, d.lon!),
anchorPos: AnchorPos.align(AnchorAlign.center),
builder: (cts) {
return InkWell(
onTap: () {
//print("-- Destination is --- ${d.name} ------");
if (indexController.currentDestinationFeature.isNotEmpty) {
indexController.currentDestinationFeature.clear();
}
indexController.currentDestinationFeature.add(d);
//indexController.getAction();
alignment: Alignment.topCenter,
child: InkWell(
onTap: () {
//print("-- Destination is --- ${d.name} ------");
if (indexController.currentDestinationFeature.isNotEmpty) {
indexController.currentDestinationFeature.clear();
}
indexController.currentDestinationFeature.add(d);
//indexController.getAction();
showModalBottomSheet(
context: Get.context!,
isScrollControlled: true,
constraints: BoxConstraints.loose(
Size(Get.width, Get.height * 0.85)),
builder: ((context) => BottomSheetNew(
destination: d,
))).whenComplete(() {
//print("---- set skip gps to false -----");
destinationController.skipGps = false;
});
},
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
width: 20,
height: 20,
decoration: BoxDecoration(
color: Colors.red,
shape: BoxShape.circle,
border: Border.all(
color: Colors.white,
width:
d.checkin_radious != null ? d.checkin_radious! : 1,
),
),
child: Center(
child: Text(
(i + 1).toString(),
style: const TextStyle(color: Colors.white),
),
showModalBottomSheet(
context: Get.context!,
isScrollControlled: true,
constraints:
BoxConstraints.loose(Size(Get.width, Get.height * 0.85)),
builder: ((context) => BottomSheetNew(
destination: d,
))).whenComplete(() {
//print("---- set skip gps to false -----");
destinationController.skipGps = false;
});
},
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
width: 20,
height: 20,
decoration: BoxDecoration(
color: Colors.red,
shape: BoxShape.circle,
border: Border.all(
color: Colors.white,
width: d.checkin_radious != null ? d.checkin_radious! : 1,
),
),
Container(
color: Colors.yellow,
child: Text(
TextUtils.getDisplayText(d),
style: const TextStyle(
fontSize: 15.0,
fontWeight: FontWeight.bold,
overflow: TextOverflow.visible),
)),
],
),
);
});
child: Center(
child: Text(
(i + 1).toString(),
style: const TextStyle(color: Colors.white),
),
),
),
Container(
color: Colors.yellow,
child: Text(
TextUtils.getDisplayText(d),
style: const TextStyle(
fontSize: 15.0,
fontWeight: FontWeight.bold,
overflow: TextOverflow.visible),
)),
],
),
));
pts.add(m);
}

View File

@ -126,19 +126,11 @@ class _GpsPageState extends State<GpsPage> {
MarkerLayer(
markers: gpsData.map((i) {
return Marker(
anchorPos: AnchorPos.exactly(Anchor(108.0, 18.0)),
height: 32.0,
width: 120.0,
point: LatLng(i.lat, i.lon),
builder: (ctx) {
return getMarkerShape(i);
// return Container(
// width: 40,
// height: 40,
// color: Colors.orange,
// );
},
);
alignment: Alignment.topCenter,
height: 32.0,
width: 120.0,
point: LatLng(i.lat, i.lon),
child: getMarkerShape(i));
}).toList(),
)
],

View File

@ -4,9 +4,8 @@ import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map/plugin_api.dart';
import 'package:flutter_polyline_points/flutter_polyline_points.dart';
import 'package:geojson/geojson.dart';
import 'package:geojson_vi/geojson_vi.dart';
import 'package:get/get.dart';
import 'package:latlong2/latlong.dart';
import 'package:rogapp/model/destination.dart';
@ -18,8 +17,8 @@ import 'package:rogapp/utils/database_helper.dart';
import 'package:shared_preferences/shared_preferences.dart';
class IndexController extends GetxController {
List<GeoJsonFeatureCollection> locations = <GeoJsonFeatureCollection>[].obs;
List<GeoJsonFeature> currentFeature = <GeoJsonFeature>[].obs;
List<GeoJSONFeatureCollection> locations = <GeoJSONFeatureCollection>[].obs;
List<GeoJSONFeature> currentFeature = <GeoJSONFeature>[].obs;
List<Destination> currentDestinationFeature = <Destination>[].obs;
List<dynamic> perfectures = <dynamic>[].obs;
List<LatLngBounds> currentBound = <LatLngBounds>[].obs;
@ -311,7 +310,7 @@ class IndexController extends GetxController {
if (value == null) {
return;
}
if (value.collection.isEmpty) {
if (value.features.isEmpty) {
if (showPopup == false) {
return;
}
@ -328,7 +327,7 @@ class IndexController extends GetxController {
showPopup = false;
//Get.showSnackbar(GetSnackBar(message: "Too many points, please zoom in",));
}
if (value.collection.isNotEmpty) {
if (value.features.isNotEmpty) {
////print("---- added---");
locations.add(value);
}
@ -340,15 +339,18 @@ class IndexController extends GetxController {
currentBound.add(bounds);
}
GeoJsonFeature? getFeatureForLatLong(double lat, double long) {
GeoJSONFeature? getFeatureForLatLong(double lat, double long) {
if (locations.isNotEmpty) {
for (GeoJsonFeature i in locations[0].collection) {
GeoJsonMultiPoint p = i.geometry as GeoJsonMultiPoint;
if (p.geoSerie!.geoPoints[0].latitude == lat &&
p.geoSerie!.geoPoints[0].longitude == long) {
return i;
GeoJSONFeature? foundFeature;
locations[0].features.forEach((i) {
GeoJSONMultiPoint p = i!.geometry as GeoJSONMultiPoint;
if (p.coordinates[0][1] == lat && p.coordinates[0][0] == long) {
foundFeature = i;
}
}
});
return foundFeature;
}
return null;
}

View File

@ -1,23 +1,21 @@
import 'package:geojson/geojson.dart';
import 'package:geojson_vi/geojson_vi.dart';
import 'package:get/get.dart';
import 'package:rogapp/pages/index/index_controller.dart';
class SearchBarController extends GetxController {
List<GeoJSONFeature> searchResults = <GeoJSONFeature>[].obs;
List<GeoJsonFeature> searchResults = <GeoJsonFeature>[].obs;
@override
@override
void onInit() {
IndexController indexController = Get.find<IndexController>();
if(indexController.locations.isNotEmpty){
for(int i=0; i<= indexController.locations[0].collection.length - 1; i++){
GeoJsonFeature p = indexController.locations[0].collection[i];
if (indexController.locations.isNotEmpty) {
for (int i = 0;
i <= indexController.locations[0].features.length - 1;
i++) {
GeoJSONFeature p = indexController.locations[0].features[i]!;
searchResults.add(p);
}
}
super.onInit();
}
}
}

View File

@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_typeahead/flutter_typeahead.dart';
import 'package:geojson/geojson.dart';
import 'package:geojson_vi/geojson_vi.dart';
import 'package:get/get.dart';
import 'package:rogapp/model/destination.dart';
import 'package:rogapp/pages/destination/destination_controller.dart';
@ -48,46 +48,32 @@ class SearchPage extends StatelessWidget {
//title: const CupertinoSearchTextField(),
),
body: SingleChildScrollView(
child: TypeAheadField(
textFieldConfiguration: TextFieldConfiguration(
autofocus: true,
style: DefaultTextStyle.of(context).style.copyWith(
fontStyle: FontStyle.normal,
fontSize: 15.0,
),
decoration: InputDecoration(
border: const OutlineInputBorder(),
hintText: "検索",
prefixIcon: const Icon(Icons.search),
suffixIcon: IconButton(
icon: const Icon(Icons.clear),
onPressed: () {
// clear the text field
},
),
),
),
suggestionsCallback: (pattern) async {
return searchController.searchResults.where(
(GeoJsonFeature element) => element.properties!["location_name"]
.toString()
.contains(pattern));
//return await
},
itemBuilder: (context, GeoJsonFeature suggestion) {
return ListTile(
title: Text(suggestion.properties!["location_name"]),
subtitle: suggestion.properties!["category"] != null
? Text(suggestion.properties!["category"])
: const Text(""),
//leading: getImage(index),
);
},
onSuggestionSelected: (GeoJsonFeature suggestion) {
child: TypeAheadField<GeoJSONFeature>(
// textFieldConfiguration: TextFieldConfiguration(
// autofocus: true,
// style: DefaultTextStyle.of(context).style.copyWith(
// fontStyle: FontStyle.normal,
// fontSize: 15.0,
// ),
// decoration: InputDecoration(
// border: const OutlineInputBorder(),
// hintText: "検索",
// prefixIcon: const Icon(Icons.search),
// suffixIcon: IconButton(
// icon: const Icon(Icons.clear),
// onPressed: () {
// // clear the text field
// },
// ),
// ),
// ),
onSelected: (GeoJSONFeature suggestion) {
indexController.currentFeature.clear();
indexController.currentFeature.add(suggestion);
DestinationController destinationController = Get.find<DestinationController>();
Destination des = destinationController.festuretoDestination(suggestion);
DestinationController destinationController =
Get.find<DestinationController>();
Destination des =
destinationController.festuretoDestination(suggestion);
Get.back();
showModalBottomSheet(
constraints:
@ -95,7 +81,28 @@ class SearchPage extends StatelessWidget {
isScrollControlled: true,
context: context,
//builder: (context) => BottomSheetWidget(),
builder: ((context) => BottomSheetNew(destination: des,)));
builder: ((context) => BottomSheetNew(
destination: des,
)));
},
suggestionsCallback: (pattern) async {
return searchController.searchResults
.where((GeoJSONFeature element) => element
.properties!["location_name"]
.toString()
.contains(pattern))
.toList();
//return await
},
itemBuilder: (context, GeoJSONFeature suggestion) {
return ListTile(
title: Text(suggestion.properties!["location_name"]),
subtitle: suggestion.properties!["category"] != null
? Text(suggestion.properties!["category"])
: const Text(""),
//leading: getImage(index),
);
},
),
),