diff options
author | Aakash Solanki <tech2aks@gmail.com> | 2022-08-31 15:23:53 +0200 |
---|---|---|
committer | Aakash Solanki <tech2aks@gmail.com> | 2022-09-14 11:50:03 +0200 |
commit | e39f2a69fde316b4e260c151757fb739494fbd56 (patch) | |
tree | 3ea8a65eee101457264d0000b5bcf122d428b0b8 /lib/map/networkPolyline.dart | |
parent | 5957cfa0609ff57adfafa4538fb151d00f3c72e3 (diff) |
Upload Flutter Instrument Cluster app
Instrument Cluster demo app which shows speedometer
tachometer guages, temperature and fuel bars and some
indicators like turn indicators, engine malfunction,
lights, cruise control, lane assist. KUKSA.VAL is the
data source for the widgets.
This app depends on several plugins and all the plugins
have an OSI-approved license.
Bug-AGL: SPEC-4543
Change-Id: I2698c66f9d8d824690ae7e567ca7c93ceeb17e08
Signed-off-by: Aakash Solanki <tech2aks@gmail.com>
Diffstat (limited to 'lib/map/networkPolyline.dart')
-rw-r--r-- | lib/map/networkPolyline.dart | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/lib/map/networkPolyline.dart b/lib/map/networkPolyline.dart new file mode 100644 index 0000000..0241bec --- /dev/null +++ b/lib/map/networkPolyline.dart @@ -0,0 +1,86 @@ +// SPDX-License-Identifier: Apache-2.0 + +import 'dart:math'; +import 'package:flutter_cluster_dashboard/cluster_config.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:http/http.dart' as http; +import 'dart:convert'; +import 'package:latlong2/latlong.dart'; + +class NetworkHelper { + NetworkHelper( + {required this.startLng, + required this.startLat, + required this.endLng, + required this.endLat}); + + final String url = 'https://api.openrouteservice.org/v2/directions/'; + + final double startLng; + final double startLat; + final double endLng; + final double endLat; + + Future getData(WidgetRef ref) async { + final config = ref.read(clusterConfigStateprovider); + String uriStr = + '$url${config.orsPathParam}?api_key=${config.orsApiKey}&start=$startLng,$startLat&end=$endLng,$endLat'; + http.Response response = await http.get(Uri.parse(uriStr)); + + if (response.statusCode == 200) { + String data = response.body; + return jsonDecode(data); + } else { + print("Warning: API Response Code: ${response.statusCode}"); + } + } +} + +Future getJsonData( + WidgetRef ref, + double startLat, + double startLng, + double endLat, + double endLng, +) async { + if (startLat == endLat && startLng == endLng) { + return []; + } else { + NetworkHelper network = NetworkHelper( + startLat: startLat, + startLng: startLng, + endLat: endLat, + endLng: endLng, + ); + try { + final apikey = ref.read(clusterConfigStateprovider).orsApiKey; + if (apikey.isNotEmpty) { + var data = await network.getData(ref); + return data['features'][0]['geometry']['coordinates']; + } + else { + return []; + } + } catch (error) { + print('Warning: Something Wrong with openstreet API Key !'); + return []; + } + } +} + +double calcAngle(LatLng a, LatLng b) { + List<double> newA = convertCoord(a); + List<double> newB = convertCoord(b); + double slope = (newB[1] - newA[1]) / (newB[0] - newA[0]); + // -1 * deg + 180 + return ((atan(slope) * 180) / pi); +} + +List<double> convertCoord(LatLng coord) { + double oldLat = coord.latitude; + double oldLong = coord.longitude; + double newLong = (oldLong * 20037508.34 / 180); + double newlat = + (log(tan((90 + oldLat) * pi / 360)) / (pi / 180)) * (20037508.34 / 180); + return [newlat, newLong]; +} |