Skip to content

Commit

Permalink
fix(map): fix map cache error
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhuJHua committed Nov 12, 2024
1 parent 395a8c5 commit ddf9dc0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
16 changes: 10 additions & 6 deletions lib/pages/map/map_logic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:latlong2/latlong.dart';
import 'package:mood_diary/pages/diary_details/diary_details_logic.dart';
import 'package:mood_diary/router/app_routes.dart';
import 'package:mood_diary/utils/utils.dart';
import 'package:permission_handler/permission_handler.dart';

import 'map_state.dart';

Expand All @@ -28,11 +29,14 @@ class MapLogic extends GetxController {
super.onClose();
}

Future<LatLng> getLocation() async {
Position? position;
position = await Geolocator.getLastKnownPosition(forceAndroidLocationManager: true);
position ??= await Geolocator.getCurrentPosition(locationSettings: AndroidSettings(forceLocationManager: true));
return LatLng(position.latitude, position.longitude);
Future<LatLng?> getLocation() async {
if (await Utils().permissionUtil.checkPermission(Permission.location)) {
Position? position;
position = await Geolocator.getLastKnownPosition(forceAndroidLocationManager: true);
position ??= await Geolocator.getCurrentPosition(locationSettings: AndroidSettings(forceLocationManager: true));
return LatLng(position.latitude, position.longitude);
}
return null;
}

Future<void> getAllItem() async {
Expand All @@ -44,7 +48,7 @@ class MapLogic extends GetxController {
var currentPosition = await getLocation();
Utils().logUtil.printInfo(currentPosition.toString());
Utils().noticeUtil.showToast('定位成功');
mapController.move(currentPosition, mapController.camera.maxZoom!);
mapController.move(currentPosition!, mapController.camera.maxZoom!);
}

Future<void> toDiaryPage({required int isarId}) async {
Expand Down
4 changes: 4 additions & 0 deletions lib/pages/map/map_state.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:math';

import 'package:latlong2/latlong.dart';
import 'package:mood_diary/common/models/map.dart';
import 'package:mood_diary/utils/utils.dart';
Expand All @@ -9,5 +11,7 @@ class MapState {

String? tiandituKey = Utils().prefUtil.getValue<String>('tiandituKey');

int random = Random().nextInt(8);

MapState();
}
5 changes: 2 additions & 3 deletions lib/pages/map/map_view.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:io';
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
Expand Down Expand Up @@ -35,12 +34,12 @@ class MapPage extends StatelessWidget {
children: [
TileLayer(
urlTemplate:
'http://t${Random().nextInt(8)}.tianditu.gov.cn/vec_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=${state.tiandituKey}',
'http://t6.tianditu.gov.cn/vec_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=${state.tiandituKey}',
tileProvider: const FMTCStore('mapStore').getTileProvider(),
),
TileLayer(
urlTemplate:
'http://t${Random().nextInt(8)}.tianditu.gov.cn/cva_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cva&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=${state.tiandituKey}',
'http://t6.tianditu.gov.cn/cva_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cva&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=${state.tiandituKey}',
tileProvider: const FMTCStore('mapStore').getTileProvider(),
),
MarkerClusterLayerWidget(
Expand Down

0 comments on commit ddf9dc0

Please sign in to comment.