Skip to content

Commit

Permalink
publish: 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
liodali committed Apr 3, 2024
1 parent a34fffb commit d017f07
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 48 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### 1.0.0: Update iOS SDK, Stablize APIs
* replace Tangram es with another ios sdk
* add `startLocationUpdating`,`stopLocationUpdating` for external control of user location
* fix some bugs
* migrate to wasm for web
* add
### 1.0.0-rc.6: update dependencies
### 1.0.0-rc.5: fix userlocation in android
* fix user location tracking in android side (bug:#507)
Expand Down
32 changes: 25 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# flutter_osm_plugin

![pub](https://img.shields.io/badge/pub-v1.0.0--rc.6-yellow)
![pub](https://img.shields.io/badge/pub-v1.0.0-blue)


## Platform Support
Expand Down Expand Up @@ -50,7 +50,7 @@
Add the following to your `pubspec.yaml` file:

dependencies:
flutter_osm_plugin: ^1.0.0-rc.6
flutter_osm_plugin: ^1.0.0



Expand Down Expand Up @@ -181,6 +181,15 @@ final controller = MapController.withUserPosition(
unFollowUser: false,
)
)
// init the position using the user location and control map from outside
final controller = MapController.withUserPosition(
trackUserLocation: UserTrackingOption(
enableTracking: true,
unFollowUser: false,
),
useExternalTracking: true
)
```


Expand All @@ -202,6 +211,7 @@ final controller = MapController.withUserPosition(
| `initPosition` | (GeoPoint) if it isn't null, the map will be pointed at this position |
| `areaLimit` | (Bounding) set area limit of the map (default BoundingBox.world()) |
| `customLayer` | (CustomTile) set customer layer using different osm server , this attribute used only with named constructor `customLayer` |
| ` useExternalTracking` | (bool) if true,we will disable our logic to show userlocation marker or to move to the user position |


<b> 3.1) Custom Layers with `MapController` </b>
Expand Down Expand Up @@ -322,24 +332,32 @@ without need to call `currentLocation`
```dart
await controller.enableTracking(enableStopFollow:false,);
```
or

> use this method below if you want to control the map(move to the user location and show the marker) while receiving the user location
```dart
await controller.startLocationUpdating();
```
<b> 9) Disable tracking user position </b>

```dart
await controller.disabledTracking();
```
or

<b>10) update the location </b>

> this method will create marker on that specific position
> use this method below if you already used `startLocationUpdating`
```dart
await controller.changeLocation(GeoPoint(latitude: 47.35387, longitude: 8.43609));
await controller.stopLocationUpdating();
```

<b>10) update the location </b>

> Change the location without create marker
```dart
await controller.goToLocation(GeoPoint(latitude: 47.35387, longitude: 8.43609));
await controller.moveToLocation(GeoPoint(latitude: 47.35387, longitude: 8.43609),animate:true);
```


Expand Down
115 changes: 75 additions & 40 deletions example/lib/src/home/main_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ class Main extends StatefulWidget {

class _MainState extends State<Main> with OSMMixinObserver {
late MapController controller;
ValueNotifier<bool> trackingNotifier = ValueNotifier(true);
ValueNotifier<bool> trackingNotifier = ValueNotifier(false);
ValueNotifier<bool> showFab = ValueNotifier(false);
ValueNotifier<bool> disableMapControlUserTracking = ValueNotifier(true);
ValueNotifier<IconData> userLocationIcon = ValueNotifier(Icons.near_me);
ValueNotifier<GeoPoint?> lastGeoPoint = ValueNotifier(null);
ValueNotifier<GeoPoint?> userLocationNotifier = ValueNotifier(null);
Expand All @@ -35,15 +36,22 @@ class _MainState extends State<Main> with OSMMixinObserver {
void initState() {
super.initState();
controller = MapController(
/*initPosition: GeoPoint(
initPosition: GeoPoint(
latitude: 47.4358055,
longitude: 8.4737324,
),*/
initMapWithUserPosition: UserTrackingOption(
enableTracking: trackingNotifier.value,
),
// initMapWithUserPosition: UserTrackingOption(
// enableTracking: trackingNotifier.value,
// ),
useExternalTracking: disableMapControlUserTracking.value,
);
controller.addObserver(this);
trackingNotifier.addListener(() async {
if (userLocationNotifier.value != null && !trackingNotifier.value) {
await controller.removeMarker(userLocationNotifier.value!);
userLocationNotifier.value = null;
}
});
}

@override
Expand All @@ -56,8 +64,6 @@ class _MainState extends State<Main> with OSMMixinObserver {
@override
void onSingleTap(GeoPoint position) {
super.onSingleTap(position);
debugPrint(position.toString());
debugPrint(lastGeoPoint.value.toString());
Future.microtask(() async {
if (lastGeoPoint.value != null) {
await controller.changeLocationMarker(
Expand All @@ -82,6 +88,7 @@ class _MainState extends State<Main> with OSMMixinObserver {
//angle: -pi / 4,
);
}
await controller.moveTo(position, animate: true);
lastGeoPoint.value = position;
});
}
Expand All @@ -104,9 +111,32 @@ class _MainState extends State<Main> with OSMMixinObserver {
}

@override
void onLocationChanged(GeoPoint userLocation) {
void onLocationChanged(UserLocation userLocation) async {
super.onLocationChanged(userLocation);
userLocationNotifier.value = userLocation;
if (disableMapControlUserTracking.value && trackingNotifier.value) {
await controller.moveTo(userLocation);
if (userLocationNotifier.value == null) {
await controller.addMarker(
userLocation,
markerIcon: MarkerIcon(
icon: Icon(Icons.navigation),
),
angle: userLocation.angle,
);
} else {
await controller.changeLocationMarker(
oldLocation: userLocationNotifier.value!,
newLocation: userLocation,
angle: userLocation.angle,
);
}
userLocationNotifier.value = userLocation;
} else {
if (userLocationNotifier.value != null && !trackingNotifier.value) {
await controller.removeMarker(userLocationNotifier.value!);
userLocationNotifier.value = null;
}
}
}

@override
Expand All @@ -116,6 +146,7 @@ class _MainState extends State<Main> with OSMMixinObserver {

@override
Widget build(BuildContext context) {
final topPadding = MediaQuery.maybeOf(context)?.viewPadding.top;
return Stack(
children: [
Map(
Expand All @@ -141,19 +172,15 @@ class _MainState extends State<Main> with OSMMixinObserver {
children: [
if (!kIsWeb) ...[
Positioned(
top:
(MediaQuery.maybeOf(context)?.viewPadding.top ?? 26) +
48,
top: (topPadding ?? 26) + 48,
right: 15,
child: MapRotation(
controller: controller,
),
)
],
Positioned(
top: kIsWeb
? 26
: MediaQuery.maybeOf(context)?.viewPadding.top ?? 26.0,
top: kIsWeb ? 26 : topPadding ?? 26.0,
left: 12,
child: PointerInterceptor(
child: MainNavigation(),
Expand All @@ -165,6 +192,7 @@ class _MainState extends State<Main> with OSMMixinObserver {
child: ActivationUserLocation(
controller: controller,
trackingNotifier: trackingNotifier,
userLocation: userLocationNotifier,
userLocationIcon: userLocationIcon,
),
),
Expand All @@ -176,9 +204,7 @@ class _MainState extends State<Main> with OSMMixinObserver {
),
),
Positioned(
top: kIsWeb
? 26
: MediaQuery.maybeOf(context)?.viewPadding.top,
top: kIsWeb ? 26 : topPadding,
left: 64,
right: 72,
child: SearchInMap(
Expand Down Expand Up @@ -360,7 +386,7 @@ class Map extends StatelessWidget {
osmOption: OSMOption(
enableRotationByGesture: true,
zoomOption: ZoomOption(
initZoom: 14,
initZoom: 16,
minZoomLevel: 3,
maxZoomLevel: 19,
stepZoom: 1.0,
Expand Down Expand Up @@ -395,18 +421,18 @@ class Map extends StatelessWidget {
// ),
),
directionArrowMarker: MarkerIcon(
// icon: Icon(
// Icons.navigation_rounded,
// size: 48,
// ),
iconWidget: SizedBox(
width: 32,
height: 64,
child: Image.asset(
"asset/directionIcon.png",
scale: .3,
),
icon: Icon(
Icons.navigation_rounded,
size: 48,
),
// iconWidget: SizedBox(
// width: 32,
// height: 64,
// child: Image.asset(
// "asset/directionIcon.png",
// scale: .3,
// ),
// ),
)
// directionArrowMarker: MarkerIcon(
// assetMarker: AssetMarker(
Expand Down Expand Up @@ -477,41 +503,50 @@ class ActivationUserLocation extends StatelessWidget {
final ValueNotifier<bool> trackingNotifier;
final MapController controller;
final ValueNotifier<IconData> userLocationIcon;
final ValueNotifier<GeoPoint?> userLocation;

const ActivationUserLocation({
super.key,
required this.trackingNotifier,
required this.controller,
required this.userLocationIcon,
required this.userLocation,
});
@override
Widget build(BuildContext context) {
return PointerInterceptor(
child: GestureDetector(
behavior: HitTestBehavior.deferToChild,
onLongPress: () async {
await controller.disabledTracking();
//await controller.disabledTracking();
await controller.stopLocationUpdating();
trackingNotifier.value = false;
},
child: FloatingActionButton(
key: UniqueKey(),
onPressed: () async {
if (!trackingNotifier.value) {
await controller.currentLocation();
/*await controller.currentLocation();
await controller.enableTracking(
enableStopFollow: true,
disableUserMarkerRotation: true,
anchor: Anchor.left,
);
disableUserMarkerRotation: false,
anchor: Anchor.right,
useDirectionMarker: true,
);*/
await controller.startLocationUpdating();
trackingNotifier.value = true;

//await controller.zoom(5.0);
} else {
await controller.enableTracking(
enableStopFollow: false,
disableUserMarkerRotation: true,
anchor: Anchor.left,
);
if (userLocation.value != null) {
await controller.moveTo(userLocation.value!);
}

/*await controller.enableTracking(
enableStopFollow: false,
disableUserMarkerRotation: true,
anchor: Anchor.center,
useDirectionMarker: true);*/
// if (userLocationNotifier.value != null) {
// await controller
// .goToLocation(userLocationNotifier.value!);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_osm_plugin
description: OpenStreetMap Plugin Native for flutter apps (Andoird/iOS/web)
version: 1.0.0-rc.6
version: 1.0.0


homepage: https://github.com/liodali/osm_flutter
Expand Down

0 comments on commit d017f07

Please sign in to comment.