-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
M3-119 개인전 픽셀 표시하는 화면 만들기 #12
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
367bbf4
M3-119 Rename : PixelService로 이름 변경
qjvk2880 0072890
M3-119 Feat : 개인전 픽셀을 화면에 표시하는 기능 구현 완료
qjvk2880 30fe516
M3-119 Rename : darkMapStyle 변수를 mapStyle로 변경
qjvk2880 f37bb04
M3-119 Rename : _createIndividualPixel 메소드를 _updateIndividualPixel로 변경
qjvk2880 d77934c
M3-119 Rename : _updateIndividualPixel()이 30초에 한번씩 실행되도록 변경
qjvk2880 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,24 +1,31 @@ | ||
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 '../service/individual_pixel_service.dart'; | ||
import '../models/individual_pixel.dart'; | ||
import '../service/pixel_service.dart'; | ||
import '../widgets/pixel.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'; | ||
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; | ||
late final String mapStyle; | ||
Completer<GoogleMapController> completer = Completer(); | ||
|
||
late LocationData currentLocation; | ||
|
||
RxList<Pixel> pixels = <Pixel>[].obs; | ||
RxList<Marker> markers = <Marker>[].obs; | ||
RxBool isLoading = true.obs; | ||
|
||
|
@@ -27,9 +34,10 @@ class MapController extends GetxController { | |
super.onInit(); | ||
await _loadMapStyle(); | ||
await updateCurrentLocation(); | ||
await _updateIndividualPixel(); | ||
_createUserMarker(); | ||
_trackUserLocation(); | ||
await individualPixelService.getIndividualPixels(currentLatitude: currentLocation.latitude!, currentLongitude: currentLocation.longitude!); | ||
_trackPixels(); | ||
} | ||
|
||
void _trackUserLocation() { | ||
|
@@ -62,11 +70,47 @@ class MapController extends GetxController { | |
} | ||
|
||
Future<void> _loadMapStyle() async { | ||
darkMapStyle = await rootBundle.loadString(darkMapStylePath); | ||
mapStyle = await rootBundle.loadString(darkMapStylePath); | ||
} | ||
|
||
void _updateMarkerPosition(LocationData newLocation, String markerId) { | ||
markers.removeWhere((marker) => marker.markerId.value == markerId); | ||
_addMarker(LatLng(newLocation.latitude!, newLocation.longitude!), markerId); | ||
} | ||
|
||
Future<void> _updateIndividualPixel() async { | ||
List<IndividualPixel> 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<LatLng> _getRectangleFromLatLng({required LatLng topLeftPoint}) { | ||
return List<LatLng>.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() { | ||
Timer.periodic(const Duration(seconds: 30), (timer) { | ||
_updateIndividualPixel(); | ||
}); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 30초 단위로 호출하면 성능이 괜찮겠죠? 걸음수도 동기화 해야되서 뭔가 walkingService 랑도 같이 쓸수도 있을 것 같네요 |
||
} |
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
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
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,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<PatternItem> patterns = const <PatternItem>[], | ||
super.consumeTapEvents, | ||
super.onTap, | ||
}) : super( | ||
polygonId: PolygonId(polygonId), | ||
); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pixels.signAll([])
로도 구현할 수 있습니다~