From 367bbf4b60634661f1e23cecec49288b310f0a24 Mon Sep 17 00:00:00 2001 From: MinUk Date: Fri, 28 Jun 2024 14:03:17 +0900 Subject: [PATCH 1/5] =?UTF-8?q?M3-119=20Rename=20:=20PixelService=EB=A1=9C?= =?UTF-8?q?=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/controllers/map_controller.dart | 4 ++-- ...ndividual_pixel_service.dart => pixel_service.dart} | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) rename lib/service/{individual_pixel_service.dart => pixel_service.dart} (76%) diff --git a/lib/controllers/map_controller.dart b/lib/controllers/map_controller.dart index 3d0e1a09..991b13a1 100644 --- a/lib/controllers/map_controller.dart +++ b/lib/controllers/map_controller.dart @@ -5,10 +5,10 @@ import 'package:get/get.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:location/location.dart'; -import '../service/individual_pixel_service.dart'; +import '../service/pixel_service.dart'; class MapController extends GetxController { - final IndividualPixelService individualPixelService = IndividualPixelService(); + final PixelService individualPixelService = PixelService(); static const String darkMapStylePath = 'assets/map_style/dark_map_style.txt'; static const String userMarkerId = 'USER'; diff --git a/lib/service/individual_pixel_service.dart b/lib/service/pixel_service.dart similarity index 76% rename from lib/service/individual_pixel_service.dart rename to lib/service/pixel_service.dart index eaf7efd3..dec98f89 100644 --- a/lib/service/individual_pixel_service.dart +++ b/lib/service/pixel_service.dart @@ -3,15 +3,15 @@ import 'package:dio/dio.dart'; import '../models/individual_pixel.dart'; import '../utils/dio_service.dart'; -class IndividualPixelService { - static final IndividualPixelService _instance = - IndividualPixelService._internal(); +class PixelService { + static final PixelService _instance = + PixelService._internal(); final Dio dio = DioService().getDio(); - IndividualPixelService._internal(); + PixelService._internal(); - factory IndividualPixelService() { + factory PixelService() { return _instance; } From 00728904c94ab9f42c02b5a7bb3dd3a5e56b82e1 Mon Sep 17 00:00:00 2001 From: MinUk Date: Fri, 28 Jun 2024 15:35:45 +0900 Subject: [PATCH 2/5] =?UTF-8?q?M3-119=20Feat=20:=20=EA=B0=9C=EC=9D=B8?= =?UTF-8?q?=EC=A0=84=20=ED=94=BD=EC=85=80=EC=9D=84=20=ED=99=94=EB=A9=B4?= =?UTF-8?q?=EC=97=90=20=ED=91=9C=EC=8B=9C=ED=95=98=EB=8A=94=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/controllers/map_controller.dart | 44 ++++++++++++++++++++++++++++- lib/screens/map_screen.dart | 1 + lib/widgets/pixel.dart | 26 +++++++++++++++++ 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 lib/widgets/pixel.dart diff --git a/lib/controllers/map_controller.dart b/lib/controllers/map_controller.dart index 991b13a1..c18e2fa1 100644 --- a/lib/controllers/map_controller.dart +++ b/lib/controllers/map_controller.dart @@ -1,17 +1,23 @@ import 'dart:async'; +import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:get/get.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:location/location.dart'; +import '../models/individual_pixel.dart'; import '../service/pixel_service.dart'; +import '../widgets/pixel.dart'; class MapController extends GetxController { final PixelService individualPixelService = PixelService(); static const String darkMapStylePath = 'assets/map_style/dark_map_style.txt'; static const String userMarkerId = 'USER'; + static const double latPerPixel = 0.000724; + static const double lonPerPixel = 0.000909; + static const int defaultUserId = 1; final Location location = Location(); late final String darkMapStyle; @@ -19,6 +25,7 @@ class MapController extends GetxController { late LocationData currentLocation; + RxList pixels = [].obs; RxList markers = [].obs; RxBool isLoading = true.obs; @@ -27,9 +34,10 @@ class MapController extends GetxController { super.onInit(); await _loadMapStyle(); await updateCurrentLocation(); + await _createIndividualPixel(); _createUserMarker(); _trackUserLocation(); - await individualPixelService.getIndividualPixels(currentLatitude: currentLocation.latitude!, currentLongitude: currentLocation.longitude!); + _trackPixels(); } void _trackUserLocation() { @@ -69,4 +77,38 @@ class MapController extends GetxController { markers.removeWhere((marker) => marker.markerId.value == markerId); _addMarker(LatLng(newLocation.latitude!, newLocation.longitude!), markerId); } + + Future _createIndividualPixel() async { + List individualPixelList = await individualPixelService.getIndividualPixels( + currentLatitude: currentLocation.latitude!, + currentLongitude: currentLocation.longitude!, + ); + + pixels = [ + for(var pixel in individualPixelList) + Pixel( + x: pixel.x, + y: pixel.y, + pixelId: pixel.pixelId, + polygonId: pixel.pixelId.toString(), + points: _getRectangleFromLatLng(topLeftPoint: LatLng(pixel.latitude, pixel.longitude)), + fillColor: (pixel.userId == defaultUserId) ? Colors.blue.withOpacity(0.3) : Colors.red.withOpacity(0.3), + strokeColor: (pixel.userId == defaultUserId) ? Colors.blue : Colors.red, + strokeWidth: 1, + ), + ].obs; + } + + List _getRectangleFromLatLng({required LatLng topLeftPoint}) { + return List.of({ + LatLng(topLeftPoint.latitude, topLeftPoint.longitude), + LatLng(topLeftPoint.latitude, topLeftPoint.longitude + lonPerPixel), + LatLng(topLeftPoint.latitude - latPerPixel, topLeftPoint.longitude + lonPerPixel), + LatLng(topLeftPoint.latitude - latPerPixel, topLeftPoint.longitude), + }); + } + + void _trackPixels() { + + } } diff --git a/lib/screens/map_screen.dart b/lib/screens/map_screen.dart index 258605df..ba08e4c6 100644 --- a/lib/screens/map_screen.dart +++ b/lib/screens/map_screen.dart @@ -35,6 +35,7 @@ class MapScreen extends StatelessWidget { }, style: mapController.darkMapStyle, markers: Set.of(mapController.markers), + polygons: Set.of(mapController.pixels), ); } }), diff --git a/lib/widgets/pixel.dart b/lib/widgets/pixel.dart new file mode 100644 index 00000000..fc2fde21 --- /dev/null +++ b/lib/widgets/pixel.dart @@ -0,0 +1,26 @@ +import 'package:flutter/material.dart'; +import 'package:google_maps_flutter/google_maps_flutter.dart'; + +class Pixel extends Polygon { + final int x; + final int y; + final int pixelId; + + Pixel({ + required this.x, + required this.y, + required this.pixelId, + required String polygonId, + super.points, + super.geodesic, + super.visible, + super.fillColor = const Color(0x00000000), + super.strokeColor = const Color(0x00000000), + super.strokeWidth = 0, + List patterns = const [], + super.consumeTapEvents, + super.onTap, + }) : super( + polygonId: PolygonId(polygonId), + ); +} \ No newline at end of file From 30fe516facde130439f642188f7f25899ba6998d Mon Sep 17 00:00:00 2001 From: MinUk Date: Fri, 28 Jun 2024 15:36:50 +0900 Subject: [PATCH 3/5] =?UTF-8?q?M3-119=20Rename=20:=20darkMapStyle=20?= =?UTF-8?q?=EB=B3=80=EC=88=98=EB=A5=BC=20mapStyle=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/controllers/map_controller.dart | 4 ++-- lib/screens/map_screen.dart | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/controllers/map_controller.dart b/lib/controllers/map_controller.dart index c18e2fa1..fc127e0a 100644 --- a/lib/controllers/map_controller.dart +++ b/lib/controllers/map_controller.dart @@ -20,7 +20,7 @@ class MapController extends GetxController { static const int defaultUserId = 1; final Location location = Location(); - late final String darkMapStyle; + late final String mapStyle; Completer completer = Completer(); late LocationData currentLocation; @@ -70,7 +70,7 @@ class MapController extends GetxController { } Future _loadMapStyle() async { - darkMapStyle = await rootBundle.loadString(darkMapStylePath); + mapStyle = await rootBundle.loadString(darkMapStylePath); } void _updateMarkerPosition(LocationData newLocation, String markerId) { diff --git a/lib/screens/map_screen.dart b/lib/screens/map_screen.dart index ba08e4c6..4dd29920 100644 --- a/lib/screens/map_screen.dart +++ b/lib/screens/map_screen.dart @@ -33,7 +33,7 @@ class MapScreen extends StatelessWidget { onMapCreated: (GoogleMapController ctrl) { mapController.completer.complete(ctrl); }, - style: mapController.darkMapStyle, + style: mapController.mapStyle, markers: Set.of(mapController.markers), polygons: Set.of(mapController.pixels), ); From f37bb048775da6d047439ad2ff0c9747124b7c06 Mon Sep 17 00:00:00 2001 From: MinUk Date: Fri, 28 Jun 2024 15:45:36 +0900 Subject: [PATCH 4/5] =?UTF-8?q?M3-119=20Rename=20:=20=5FcreateIndividualPi?= =?UTF-8?q?xel=20=EB=A9=94=EC=86=8C=EB=93=9C=EB=A5=BC=20=5FupdateIndividua?= =?UTF-8?q?lPixel=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/controllers/map_controller.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/controllers/map_controller.dart b/lib/controllers/map_controller.dart index fc127e0a..5cdac7e2 100644 --- a/lib/controllers/map_controller.dart +++ b/lib/controllers/map_controller.dart @@ -34,7 +34,7 @@ class MapController extends GetxController { super.onInit(); await _loadMapStyle(); await updateCurrentLocation(); - await _createIndividualPixel(); + await _updateIndividualPixel(); _createUserMarker(); _trackUserLocation(); _trackPixels(); @@ -78,7 +78,7 @@ class MapController extends GetxController { _addMarker(LatLng(newLocation.latitude!, newLocation.longitude!), markerId); } - Future _createIndividualPixel() async { + Future _updateIndividualPixel() async { List individualPixelList = await individualPixelService.getIndividualPixels( currentLatitude: currentLocation.latitude!, currentLongitude: currentLocation.longitude!, From d77934cff6a9478aba610fba5a4707edb4a6abeb Mon Sep 17 00:00:00 2001 From: MinUk Date: Fri, 28 Jun 2024 15:46:02 +0900 Subject: [PATCH 5/5] =?UTF-8?q?M3-119=20Rename=20:=20=5FupdateIndividualPi?= =?UTF-8?q?xel()=EC=9D=B4=2030=EC=B4=88=EC=97=90=20=ED=95=9C=EB=B2=88?= =?UTF-8?q?=EC=94=A9=20=EC=8B=A4=ED=96=89=EB=90=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/controllers/map_controller.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/controllers/map_controller.dart b/lib/controllers/map_controller.dart index 5cdac7e2..4eb3a7c3 100644 --- a/lib/controllers/map_controller.dart +++ b/lib/controllers/map_controller.dart @@ -109,6 +109,8 @@ class MapController extends GetxController { } void _trackPixels() { - + Timer.periodic(const Duration(seconds: 30), (timer) { + _updateIndividualPixel(); + }); } }