Skip to content

Commit

Permalink
feat : add show interestPoint with custom icon in drawRoadManually (l…
Browse files Browse the repository at this point in the history
…iodali#229)

* add new attribute `deleteOldRoad` in map_controller  to delete previous drawn route
* add new attribute `interestPoints` in map_controller  to show markers in the current drawn route
* add new attribute `interestPointsIcon` in map_controller  to show custom icon marker for interestPoints in the  current drawn route
  • Loading branch information
liodali committed Mar 1, 2022
1 parent 5797f69 commit 0d4eb68
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 5 deletions.
14 changes: 12 additions & 2 deletions example/lib/src/home/home_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ class _MainExampleState extends State<MainExample> with OSMMixinObserver {
color: Colors.brown,
size: 48,
),
Text(randNum,style: TextStyle(fontSize: 18),),
Text(
randNum,
style: TextStyle(fontSize: 18),
),
],
),
),
Expand Down Expand Up @@ -368,6 +371,9 @@ class _MainExampleState extends State<MainExample> with OSMMixinObserver {
color: Colors.brown,
),
),
middleIcon: MarkerIcon(
icon: Icon(Icons.location_history_sharp),
),
roadColor: Colors.red,
),
markerOption: MarkerOption(
Expand Down Expand Up @@ -527,7 +533,11 @@ class _MainExampleState extends State<MainExample> with OSMMixinObserver {
roadType: notifierRoadType.value,
//interestPoints: [pointM1, pointM2],
roadOption: RoadOption(
roadWidth: 10, roadColor: Colors.blue, showMarkerOfPOI: false, zoomInto: true),
roadWidth: 10,
roadColor: Colors.blue,
showMarkerOfPOI: true,
zoomInto: true,
),
);
print("duration:${Duration(seconds: roadInformation.duration!.toInt()).inMinutes}");
print("distance:${roadInformation.distance}Km");
Expand Down
16 changes: 16 additions & 0 deletions flutter_osm_interface/lib/src/channel/osm_method_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,9 @@ class MethodChannelOSM extends MobileOSMPlatform {
Color roadColor,
double width, {
bool zoomInto = false,
bool deleteOldRoads = false,
GlobalKey? keyIconForInterestPoints,
List<GeoPoint> interestPoints = const [],
}) async {
final coordinates = road.map((e) => e.toListNum()).toList();
final encodedCoordinates = encodePolyline(coordinates);
Expand All @@ -511,6 +514,19 @@ class MethodChannelOSM extends MobileOSMPlatform {
data.addAll(roadColor.toMap("roadColor"));
}
data["zoomInto"] = zoomInto;
data["clearPreviousRoad"] = deleteOldRoads;
data["iconInterestPoints"] = null;
data["interestPoints"] = null;
if (interestPoints.isNotEmpty) {
data["interestPoints"] = await interestPoints.encodedToString();
if (keyIconForInterestPoints != null) {
try {
final Uint8List bytes = await _capturePng(keyIconForInterestPoints);
data["iconInterestPoints"] = Platform.isIOS ? bytes.convertToString() : bytes;
} catch (e) {}
}
}

await _channels[idOSM]?.invokeMethod(
"drawRoad#manually",
data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ abstract class IBaseOSMController {
Color roadColor,
double width, {
bool zoomInto = false,
bool deleteOldRoads = false,
MarkerIcon? interestPointIcon,
List<GeoPoint> interestPoints = const [],
});

/// [drawMultipleRoad]
Expand Down
3 changes: 3 additions & 0 deletions flutter_osm_interface/lib/src/osm_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ abstract class MobileOSMPlatform extends OSMPlatform {
Color roadColor,
double width, {
bool zoomInto = false,
bool deleteOldRoads = false,
GlobalKey? keyIconForInterestPoints,
List<GeoPoint> interestPoints = const [],
});

Future<void> mapRotation(
Expand Down
8 changes: 7 additions & 1 deletion lib/src/controller/map_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,19 @@ class MapController extends BaseMapController {
Color roadColor,
double roadWidth, {
bool zoomInto = false,
bool deleteOldRoads = false,
MarkerIcon? interestPointIcon,
List<GeoPoint> interestPoints = const [],
}) async {
assert(path.length > 3);
await osmBaseController.drawRoadManually(
path,
roadColor,
roadWidth,
zoomInto: zoomInto
zoomInto: zoomInto,
deleteOldRoads: deleteOldRoads,
interestPoints: interestPoints,
interestPointIcon: interestPointIcon,
);
}

Expand Down
15 changes: 13 additions & 2 deletions lib/src/controller/osm/osm_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ class MobileOSMController extends IBaseOSMController {
_idMap,
[
_osmFlutterState.startIconKey,
_osmFlutterState.endIconKey,
_osmFlutterState.middleIconKey,
_osmFlutterState.endIconKey,
],
);
}
Expand Down Expand Up @@ -410,7 +410,7 @@ class MobileOSMController extends IBaseOSMController {
MarkerIcon? markerIcon,
double? angle,
}) async {
if (markerIcon != null ) {
if (markerIcon != null) {
_osmFlutterState.widget.dynamicMarkerWidgetNotifier.value =
((angle == null) || (angle == 0.0))
? markerIcon
Expand Down Expand Up @@ -516,6 +516,9 @@ class MobileOSMController extends IBaseOSMController {
Color roadColor,
double width, {
bool zoomInto = false,
bool deleteOldRoads = false,
MarkerIcon? interestPointIcon,
List<GeoPoint> interestPoints = const [],
}) async {
if (path.isEmpty) {
throw Exception("you cannot make road with empty list of geoPoint");
Expand All @@ -525,12 +528,20 @@ class MobileOSMController extends IBaseOSMController {
path.length < 3) {
throw Exception("you cannot make line with same geoPoint");
}
if (interestPointIcon != null) {
_osmFlutterState.widget.dynamicMarkerWidgetNotifier.value;
await Future.delayed(Duration(milliseconds: 350));
}
await osmPlatform.drawRoadManually(
_idMap,
path,
roadColor,
width,
zoomInto: zoomInto,
deleteOldRoads: deleteOldRoads,
interestPoints: interestPoints,
keyIconForInterestPoints:
interestPointIcon != null ? _osmFlutterState.dynamicMarkerKey : null,
);
}

Expand Down

0 comments on commit 0d4eb68

Please sign in to comment.