LoginPage #54

Merged
maen0574 merged 7 commits from LoginPage into master 2022-05-30 17:09:44 +02:00
7 changed files with 134 additions and 41 deletions
Showing only changes of commit fefdd965b9 - Show all commits

File diff suppressed because one or more lines are too long

View File

@ -67,22 +67,12 @@ class MapState extends State<Map> {
@override
void initState() {
initialize();
//_getUserLocation();
_getUserLocation();
super.initState();
}
initialize() {
hiddenVenues.addAll(globals.VENUES);
/*List<Venue> allVenues = globals.VENUES;
for (var venue in allVenues) {
Marker marker = Marker(
markerId: MarkerId(venue.venueID.toString()),
position: venue.position,
onTap: () => createBottomDrawer(venue),
icon: venue.drawIconColor(),
);
markersList.add(marker);
}*/
}
void createBottomSheet(String venueName) async {
@ -153,6 +143,7 @@ class MapState extends State<Map> {
];
@override
Widget build(BuildContext context) {
_currentCameraPosition = _stockholmCity;
return Scaffold(
appBar: AppBar(
centerTitle: true,
@ -165,6 +156,10 @@ class MapState extends State<Map> {
body: Stack (
children: [
GoogleMap(
cameraTargetBounds: CameraTargetBounds(LatLngBounds(
northeast: const LatLng(59.3474696569038, 18.1001602476002147),
southwest: const LatLng(59.297332547922636, 17.999522500277884))),
minMaxZoomPreference: MinMaxZoomPreference(12.5, 18.5),
onCameraMove: (CameraPosition camera){
_currentCameraPosition = camera;
},
@ -176,11 +171,13 @@ class MapState extends State<Map> {
mapType: MapType.normal,
myLocationEnabled: true,
initialCameraPosition: _stockholmCity,
markers: closeByMarkersList.map((e) => e).toSet(),
compassEnabled: true,
onMapCreated: (GoogleMapController controller) {
_controller.complete(controller);
setAllMarkersAsInvisible();
addMarkersInRange();
_controller.complete(controller);
},
markers: closeByMarkersList.map((e) => e).toSet(),
onTap: (LatLng) {
closeBottomSheetIfOpen();
},
@ -332,10 +329,10 @@ class MapState extends State<Map> {
Future<void> _gotoLocation(double lat, double lng) async {
final GoogleMapController controller = await _controller.future;
controller.animateCamera(CameraUpdate.newCameraPosition(
CameraPosition(target: LatLng(lat, lng), zoom: 15)));
CameraPosition(target: LatLng(lat, lng), zoom: 14.5)));
}
Widget _boxes(double lat, double lng, String resturantName) {
Widget _boxes(double lat, double lng, String restaurantName) {
return GestureDetector(
onTap: () {
_gotoLocation(lat, lng);
@ -363,7 +360,7 @@ class MapState extends State<Map> {
Container(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(resturantName),
child: Text(restaurantName),
),
)
],
@ -380,30 +377,33 @@ class MapState extends State<Map> {
bearing: 0,
target: LatLng(latlng.latitude, latlng.longitude),
//tilt: 59.440717697143555,
zoom: 14.4746)));
zoom: 15.4746)));
}
void removeMarkersOutOfRange() {
for(int i = 0; i<closeByMarkersList.length; i++){
Marker marker = closeByMarkersList[i];
globals.venueAlreadyAdded(globals.getVenueByID(int.parse(marker.markerId.value))!.venueName);
if(marker.position.longitude - _currentCameraPosition.target.longitude > 0.02 || marker.position.latitude - _currentCameraPosition.target.latitude > 0.02){
closeByMarkersList.remove(marker);
globals.getVenueByID(int.parse(marker.markerId.toString()))?.isShownOnMap = false;
globals.getVenueByID(int.parse(marker.markerId.value))?.isShownOnMap = false;
//print(globals.getVenueByID(int.parse(marker.markerId.value))!.venueName + " " + globals.getVenueByID(int.parse(marker.markerId.value))!.venueID.toString());
i--;
}
}
}
void addMarkersInRange() {
for(int i = 0; i<hiddenVenues.length; i++){
if(!hiddenVenues[i].isShownOnMap && (hiddenVenues[i].position.longitude - _currentCameraPosition.target.longitude < 0.02 && hiddenVenues[i].position.latitude - _currentCameraPosition.target.latitude < 0.02)){
for(int i = 0; i< globals.VENUES.length; i++){
print(hiddenVenues[i].venueName + " " + hiddenVenues[i].venueID.toString());
if(!globals.VENUES[i].isShownOnMap && (globals.VENUES[i].position.longitude - _currentCameraPosition.target.longitude < 0.02 && globals.VENUES[i].position.latitude - _currentCameraPosition.target.latitude < 0.02)){
Marker marker = Marker(
markerId: MarkerId(hiddenVenues[i].venueID.toString()),
position: hiddenVenues[i].position,
onTap: () => createBottomDrawer(hiddenVenues[i]),
icon: hiddenVenues[i].drawIconColor()
markerId: MarkerId(globals.VENUES[i].venueID.toString()),
position: globals.VENUES[i].position,
onTap: () => createBottomDrawer(globals.VENUES[i]),
icon: globals.VENUES[i].drawIconColor()
);
hiddenVenues[i].isShownOnMap = true;
globals.VENUES[i].isShownOnMap = true;
closeByMarkersList.add(marker);
}
}
@ -545,11 +545,16 @@ class MapState extends State<Map> {
}
closeBottomSheetIfOpen() {
print(_bottomSheetIsOpen);
if (_bottomSheetIsOpen) {
Navigator.pop(context);
}
}
void setAllMarkersAsInvisible() {
for(Venue venue in hiddenVenues){
venue.isShownOnMap = false;
}
}
/*
Future<void> _handelPressButton() async {
Prediction? p = await PlacesAutocomplete.show(

View File

@ -25,11 +25,10 @@ class ShadowDetector {
final lng = pos.longitude.toString();
final response = await get(Uri.parse('https://node.sacalerts.com/og-image/loc@$lat,$lng,14.82137z,$dateInMilliseconds'));
var responseAsString = response.body.toString();
//print(response);
//print(responseAsString);
//print(responseAsString[responseAsString.length - 2]);
if(responseAsString[responseAsString.length - 2] == 1) {
venue.inShade = true;
}else{
venue.inShade = false;
}
venuesInShade.add(venue);
}
@ -44,9 +43,6 @@ class ShadowDetector {
final dateInMilliseconds = DateTime.now().millisecondsSinceEpoch.toString() + 't';
final response = await get(Uri.parse('https://node.sacalerts.com/og-image/loc@$lat,$lng,14.82137z,$dateInMilliseconds'));
var responseAsString = response.body.toString();
//print(response);
//print(responseAsString);
//print(responseAsString[responseAsString.length - 2]);
if(responseAsString[responseAsString.length - 2] == 1) {
venue.inShade = true;
}
@ -54,4 +50,25 @@ class ShadowDetector {
venue.inShade = false;
}
}
Future evaluateShadowsForOneOutdoorSeatingArea (OutdoorSeatingArea osa) async {
final nw = osa.northPoint.toString() + "," + osa.westPoint.toString();
final sw = osa.southPoint.toString() + "," + osa.westPoint.toString();
final se = osa.southPoint.toString() + "," + osa.eastPoint.toString();
final ne = osa.northPoint.toString() + "," + osa.eastPoint.toString();
List<String> points = [nw, sw, se, ne];
osa.shadowPercent = 0;
final dateInMilliseconds = DateTime.now().millisecondsSinceEpoch.toString() + 't';
for(var point in points){
final response = await get(Uri.parse('https://node.sacalerts.com/og-image/loc@$point,14.82137z,$dateInMilliseconds'));
var responseAsString = response.body.toString();
if(responseAsString[responseAsString.length - 2] == 1) {
osa.shadowPercent += 25;
}
}
}
}

View File

@ -12,6 +12,7 @@ class Venue {
bool inShade = false;
bool isShownOnMap = false;
DateTime? lastUpdated;
OutdoorSeatingArea? outdoorSeatingArea;
Venue(this.venueID, this.venueName, this.venueAddress, this.venueStreetNo,
this.position);
@ -55,12 +56,14 @@ class Venue {
}
BitmapDescriptor drawIconColor() {
if(outdoorSeatingArea != null){
return outdoorSeatingArea!.getMarker();
}
if (lastUpdated == null || lastUpdated!.difference(DateTime.now()).inMinutes > 30) {
ShadowDetector SD = ShadowDetector();
SD.evaluateShadowsForOneVenue(this);
lastUpdated = DateTime.now();
}
print("Skugga " + inShade.toString());
if (inShade) {
return BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueAzure);
@ -85,6 +88,10 @@ class Venue {
return position;
}
void assignSeatingArea(OutdoorSeatingArea outdoorSeatingArea){
this.outdoorSeatingArea = outdoorSeatingArea;
}
Widget getIcon(BuildContext context) {
if (venueName.toLowerCase().contains('estau')) {
return const Icon(Icons.restaurant);
@ -115,4 +122,39 @@ class Venue {
}
}
class OutdoorSeatingArea {
double northPoint;
double eastPoint;
double westPoint;
double southPoint;
bool shadowIsCalculated = false;
late int shadowPercent;
OutdoorSeatingArea({
required this.northPoint, required this.eastPoint, required this.westPoint, required this.southPoint
});
int calculateShadow(){
if(!shadowIsCalculated){
ShadowDetector SD = ShadowDetector();
SD.evaluateShadowsForOneOutdoorSeatingArea(this);
shadowIsCalculated = true;
}
return shadowPercent;
}
BitmapDescriptor getMarker() {
calculateShadow();
if(shadowPercent < 26){
return BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueGreen);
}else if(shadowPercent < 51){
return BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueAzure);
}else if(shadowPercent < 76){
return BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueOrange);
}
return BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueRed);
}
}
enum VenueType { cafe, restaurant, bar }

View File

@ -28,4 +28,13 @@ Venue? getVenueByID(int searchedVenueID){
return V;
}
}return null;
}
bool venueAlreadyAdded(String venueName){
for(var V in VENUES){
if(V.venueName.compareTo(venueName) == 0){
return true;
}
}
return false;
}

View File

@ -24,8 +24,9 @@ import 'globals.dart' as globals;
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
//await loadAllVenues();
//await fetchWeather();
await loadAllVenues();
await fetchWeather();
await loadAllVenuesSQL();
runApp(MyApp());
}
@ -33,14 +34,13 @@ void main() async {
Future fetchWeather() async {
WeatherData tempWeather = WeatherData(0, 0);
Uri weatherDataURI = Uri.parse(
'https://group-4-75.pvt.dsv.su.se/target/weather-0.0.2-SNAPSHOT.war/weather');
'https://group-4-75.pvt.dsv.su.se/target/info.war/weather');
final response = await http.get(weatherDataURI);
if (response.statusCode == 200) {
var data = json.decode(response.body);
tempWeather = WeatherData.fromJson(data);
print(data);
globals.forecast = tempWeather;
} else {
@ -67,7 +67,7 @@ class MyApp extends StatelessWidget {
Future loadAllVenues() async {
Uri venueDataURI = Uri.parse(
'https://group-4-75.pvt.dsv.su.se/target/weather-0.0.4-SNAPSHOT.war/venue');
'https://group-4-75.pvt.dsv.su.se/target/info.war/venue');
final response = await http.get(venueDataURI);
@ -88,7 +88,9 @@ void addVenues(http.Response response) {
addValidVenues(data, _allVenuesTemp);
for (Venue venue in _allVenuesTemp) {
globals.VENUES.add(venue);
if(!globals.venueAlreadyAdded(venue.venueName)){
globals.VENUES.add(venue);
}
}
}
@ -113,3 +115,21 @@ void addValidVenues(data, List<dynamic> _allVenuesTemp) {
}
}
}
Future<void> loadAllVenuesSQL() async{
var db = mysql();
await db.getConnection().then((conn) async {
String sql = "select venueName, venueID, latitude, longitude from maen0574.venue";
await conn.query(sql).then((results){
for(var row in results){
globals.VENUES.add(Venue(row[1], row[0], "Dalagatan", "2", LatLng(row[2], row[3])));
}
});
sql = "select venueID, north, east, west, south from maen0574.seatingArea";
await conn.query(sql).then((results){
for(var row in results){
globals.getVenueByID(row[0])?.assignSeatingArea(OutdoorSeatingArea(northPoint: row[1], eastPoint: row[2], westPoint: row[3], southPoint: row[4]));
}
});
});
}

View File

@ -48,7 +48,7 @@ class _VenuePageState extends State<VenuePage> {
currentWeather = tempWeather;
Uri weatherDataURI = Uri.parse(
'https://group-4-75.pvt.dsv.su.se/target/weather-0.0.4-SNAPSHOT.war/weather');
'https://group-4-75.pvt.dsv.su.se/target/info.war/weather');
final response = await http.get(weatherDataURI);