Skip to content

Commit

Permalink
feat : add extension to support convert list of geo to string and str…
Browse files Browse the repository at this point in the history
…ing to list of geo
  • Loading branch information
liodali committed Feb 11, 2022
1 parent 98a21ba commit 805aaed
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 4 deletions.
28 changes: 28 additions & 0 deletions flutter_osm_interface/lib/src/common/utilities.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import 'dart:convert';
import 'dart:typed_data';
import 'dart:ui' as ui;

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:google_polyline_algorithm/google_polyline_algorithm.dart';

import '../types/types.dart';

Expand All @@ -19,6 +21,32 @@ extension ExtGeoPoint on GeoPoint {
}
}

extension ExtListGeoPoint on List<GeoPoint> {
Future<String> encodedToString() async {
final List<GeoPoint> listGeos = this;
return compute((List<GeoPoint> geoPoints) async {
final coordinates = geoPoints.map((e) => e.toListNum()).toList();
return encodePolyline(coordinates);
}, listGeos);
}
}

extension TransformEncodedPolyLineToListGeo on String {
Future<List<GeoPoint>> toListGeo() async {
final String polylineEncoded = this;
try {
return await compute((String encoded) {
final listPoints = decodePolyline(encoded);
return listPoints
.map((e) => GeoPoint(latitude: e.last.toDouble(), longitude: e.first.toDouble()))
.toList();
}, polylineEncoded);
} catch (e) {
return [];
}
}
}

extension ColorMap on Color {
Map<String, List<int>> toMap(String key) {
return {
Expand Down
2 changes: 1 addition & 1 deletion flutter_osm_interface/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_osm_interface
description: osm flutter controller and utilities.
version: 0.1.16
version: 0.1.17
homepage: https://github.com/liodali/osm_flutter

environment:
Expand Down
4 changes: 3 additions & 1 deletion lib/flutter_osm_plugin.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
library osm_flutter;

export 'package:flutter_osm_interface/src/common/utilities.dart'
hide Uint8ListConvert,ListMultiRoadConf, ColorMap,capturePng;
export 'package:flutter_osm_interface/src/map_controller/base_map_controller.dart'
hide OSMControllerOfBaseMapController, PrivateBaseMapController;
export 'package:flutter_osm_interface/src/types/types.dart';
export 'package:flutter_osm_interface/src/mixin/interface_mixin.dart';
export 'package:flutter_osm_interface/src/types/types.dart';

export 'src/common/geo_point_exception.dart';
export 'src/common/road_exception.dart';
Expand Down
4 changes: 2 additions & 2 deletions lib/src/osm_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import 'controller/map_controller.dart';
import 'interface_osm/base_osm_platform.dart';
import 'widgets/copyright_osm_widget.dart';

typedef OnGeoPointClicked = void Function(GeoPoint);
typedef OnLocationChanged = void Function(GeoPoint);
// typedef OnGeoPointClicked = void Function(GeoPoint);
// typedef OnLocationChanged = void Function(GeoPoint);

/// Principal widget to show OSMMap using osm api
/// you can track you current location,show static points like position of your stores
Expand Down
10 changes: 10 additions & 0 deletions test/flutter_osm_plugin_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,14 @@ void main() {
List<SearchInfo> suggestions = await addressSuggestion("berlin");
expect(suggestions.length, 5);
});

test("test parse route Encoded to ListGeo", () async {
String routeEncoded =
"mfp_I__vpAYBO@K@[BuBRgBLK@UBMMC?AAKAe@FyBTC@E?IDKDA@K@]BUBSBA?E@E@A@KFUBK@mAL{CZQ@qBRUBmAFc@@}@Fu@DG?a@B[@qAF_AJ[D_E`@SBO@ODA@UDA?]JC?uBNE?OAKACa@AI]mCCUE[AK[iCWqB[{Bk@sE_@_DAICSAOIm@AIQuACOQyAG[Gc@]wBw@aFKu@y@oFCMAOIm@?KAQ?KIuDQmHE}BBQ?Q?OCq@?I?IASAg@OuF?OAi@?c@@c@Du@r@cH@U@I@G@K?E~@kJRyBf@uE@KFi@RaBBMFc@Da@@ETaC@QJ{@Ny@Ha@RiAfBuJF]DOh@yAHSf@aADIR_@\\q@w@y@e@a@CCUQaCkB{@y@GESO?_@?C?[IoCIgDMsEAYOkEAQ@Yj@kENg@ZyBBIHm@FY@GBUJk@JmA?c@?QAQG]LKDEDCHOL]FO^uA@GTu@La@`A_DJ[pAgCJSlAwBJSf@{@b@w@dAqBHQZq@LMLKRIFAL?J@HBFBp@XPHh@TTJNFTRNFd@N\\HF@J@J@@V?N@rA@dB";

final list = await routeEncoded.toListGeo();
final encodedRoute = await list.encodedToString();
expect(list.isNotEmpty, true);
expect(encodedRoute, routeEncoded);
});
}

0 comments on commit 805aaed

Please sign in to comment.