diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..3287bb6 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,13 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Flutter", + "request": "launch", + "type": "dart" + } + ] +} \ No newline at end of file diff --git a/example/README.md b/example/README.md index b120d81..a2053ee 100644 --- a/example/README.md +++ b/example/README.md @@ -5,8 +5,6 @@ Demonstrates how to use the flutter_google_maps package. ## Usage ```dart -import 'dart:math' show Point; - import 'package:flutter/material.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter_google_maps/flutter_google_maps.dart'; @@ -99,11 +97,11 @@ class _MyHomePageState extends State { child: Icon(Icons.pin_drop), onPressed: () { GoogleMap.of(_key).addMarker( - Point(33.875513, -117.550257), + GeoCoord(33.875513, -117.550257), info: 'test info', ); GoogleMap.of(_key).addMarker( - Point(33.775513, -117.450257), + GeoCoord(33.775513, -117.450257), icon: 'assets/images/map-marker-warehouse.png', info: contentString, ); @@ -114,12 +112,12 @@ class _MyHomePageState extends State { child: Icon(Icons.directions), onPressed: () { GoogleMap.of(_key).addDirection( - 'salinas municipal airport sns', - '1353 Dayton Street, Unit B, salinas', + 'San Francisco, CA', + 'San Jose, CA', startLabel: '1', - startInfo: 'salinas municipal airport sns', + startInfo: 'San Francisco, CA', endIcon: 'assets/images/map-marker-warehouse.png', - endInfo: '1353 Dayton Street, Unit B, salinas', + endInfo: 'San Jose, CA', ); }, ), @@ -153,10 +151,20 @@ class _MyHomePageState extends State { child: FloatingActionButton( child: Icon(Icons.person_pin_circle), onPressed: () { - GoogleMap.of(_key).moveCamera(GeoCoordBounds( + final bounds = GeoCoordBounds( northeast: GeoCoord(34.021307, -117.432317), southwest: GeoCoord(33.835745, -117.712785), - )); + ); + GoogleMap.of(_key).moveCamera(bounds); + GoogleMap.of(_key).addMarker( + GeoCoord( + (bounds.northeast.latitude + bounds.southwest.latitude) / + 2, + (bounds.northeast.longitude + + bounds.southwest.longitude) / + 2, + ), + ); }, ), ), @@ -213,58 +221,58 @@ const contentString = r''' '''; -const polygon = >[ - Point(32.707868, -117.191018), - Point(32.705645, -117.191096), - Point(32.697756, -117.166664), - Point(32.686486, -117.163206), - Point(32.675876, -117.169452), - Point(32.674726, -117.165233), - Point(32.679833, -117.158487), - Point(32.677571, -117.153893), - Point(32.671987, -117.160079), - Point(32.667547, -117.160477), - Point(32.654748, -117.147579), - Point(32.651933, -117.150312), - Point(32.649676, -117.144334), - Point(32.631665, -117.138201), - Point(32.632033, -117.132249), - Point(32.630156, -117.137234), - Point(32.628072, -117.136479), - Point(32.630315, -117.131443), - Point(32.625930, -117.135312), - Point(32.623754, -117.131664), - Point(32.627465, -117.130883), - Point(32.622598, -117.128791), - Point(32.622622, -117.133183), - Point(32.618690, -117.133634), - Point(32.618980, -117.128403), - Point(32.609847, -117.132502), - Point(32.604198, -117.125333), - Point(32.588260, -117.122032), - Point(32.591164, -117.116851), - Point(32.587601, -117.105968), - Point(32.583792, -117.104434), - Point(32.570566, -117.101382), - Point(32.569256, -117.122378), - Point(32.560825, -117.122903), - Point(32.557753, -117.131040), - Point(32.542737, -117.124883), - Point(32.534156, -117.126062), - Point(32.563255, -117.134963), - Point(32.584055, -117.134263), - Point(32.619405, -117.140001), - Point(32.655293, -117.157349), - Point(32.669944, -117.169624), - Point(32.682710, -117.189445), - Point(32.685297, -117.208773), - Point(32.679814, -117.224882), - Point(32.697212, -117.227058), - Point(32.707701, -117.219816), - Point(32.711931, -117.214107), - Point(32.715026, -117.196521), - Point(32.713053, -117.189703), - Point(32.707868, -117.191018), +const polygon = [ + GeoCoord(32.707868, -117.191018), + GeoCoord(32.705645, -117.191096), + GeoCoord(32.697756, -117.166664), + GeoCoord(32.686486, -117.163206), + GeoCoord(32.675876, -117.169452), + GeoCoord(32.674726, -117.165233), + GeoCoord(32.679833, -117.158487), + GeoCoord(32.677571, -117.153893), + GeoCoord(32.671987, -117.160079), + GeoCoord(32.667547, -117.160477), + GeoCoord(32.654748, -117.147579), + GeoCoord(32.651933, -117.150312), + GeoCoord(32.649676, -117.144334), + GeoCoord(32.631665, -117.138201), + GeoCoord(32.632033, -117.132249), + GeoCoord(32.630156, -117.137234), + GeoCoord(32.628072, -117.136479), + GeoCoord(32.630315, -117.131443), + GeoCoord(32.625930, -117.135312), + GeoCoord(32.623754, -117.131664), + GeoCoord(32.627465, -117.130883), + GeoCoord(32.622598, -117.128791), + GeoCoord(32.622622, -117.133183), + GeoCoord(32.618690, -117.133634), + GeoCoord(32.618980, -117.128403), + GeoCoord(32.609847, -117.132502), + GeoCoord(32.604198, -117.125333), + GeoCoord(32.588260, -117.122032), + GeoCoord(32.591164, -117.116851), + GeoCoord(32.587601, -117.105968), + GeoCoord(32.583792, -117.104434), + GeoCoord(32.570566, -117.101382), + GeoCoord(32.569256, -117.122378), + GeoCoord(32.560825, -117.122903), + GeoCoord(32.557753, -117.131040), + GeoCoord(32.542737, -117.124883), + GeoCoord(32.534156, -117.126062), + GeoCoord(32.563255, -117.134963), + GeoCoord(32.584055, -117.134263), + GeoCoord(32.619405, -117.140001), + GeoCoord(32.655293, -117.157349), + GeoCoord(32.669944, -117.169624), + GeoCoord(32.682710, -117.189445), + GeoCoord(32.685297, -117.208773), + GeoCoord(32.679814, -117.224882), + GeoCoord(32.697212, -117.227058), + GeoCoord(32.707701, -117.219816), + GeoCoord(32.711931, -117.214107), + GeoCoord(32.715026, -117.196521), + GeoCoord(32.713053, -117.189703), + GeoCoord(32.707868, -117.191018), ]; ``` diff --git a/example/lib/main.dart b/example/lib/main.dart index 7aa7bbf..c26efa4 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'dart:math' show Point; - import 'package:flutter/material.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter_google_maps/flutter_google_maps.dart'; @@ -96,11 +94,11 @@ class _MyHomePageState extends State { child: Icon(Icons.pin_drop), onPressed: () { GoogleMap.of(_key).addMarker( - Point(33.875513, -117.550257), + GeoCoord(33.875513, -117.550257), info: 'test info', ); GoogleMap.of(_key).addMarker( - Point(33.775513, -117.450257), + GeoCoord(33.775513, -117.450257), icon: 'assets/images/map-marker-warehouse.png', info: contentString, ); @@ -111,12 +109,12 @@ class _MyHomePageState extends State { child: Icon(Icons.directions), onPressed: () { GoogleMap.of(_key).addDirection( - 'salinas municipal airport sns', - '1353 Dayton Street, Unit B, salinas', + 'San Francisco, CA', + 'San Jose, CA', startLabel: '1', - startInfo: 'salinas municipal airport sns', + startInfo: 'San Francisco, CA', endIcon: 'assets/images/map-marker-warehouse.png', - endInfo: '1353 Dayton Street, Unit B, salinas', + endInfo: 'San Jose, CA', ); }, ), @@ -150,10 +148,20 @@ class _MyHomePageState extends State { child: FloatingActionButton( child: Icon(Icons.person_pin_circle), onPressed: () { - GoogleMap.of(_key).moveCamera(GeoCoordBounds( + final bounds = GeoCoordBounds( northeast: GeoCoord(34.021307, -117.432317), southwest: GeoCoord(33.835745, -117.712785), - )); + ); + GoogleMap.of(_key).moveCamera(bounds); + GoogleMap.of(_key).addMarker( + GeoCoord( + (bounds.northeast.latitude + bounds.southwest.latitude) / + 2, + (bounds.northeast.longitude + + bounds.southwest.longitude) / + 2, + ), + ); }, ), ), @@ -210,56 +218,56 @@ const contentString = r''' '''; -const polygon = >[ - Point(32.707868, -117.191018), - Point(32.705645, -117.191096), - Point(32.697756, -117.166664), - Point(32.686486, -117.163206), - Point(32.675876, -117.169452), - Point(32.674726, -117.165233), - Point(32.679833, -117.158487), - Point(32.677571, -117.153893), - Point(32.671987, -117.160079), - Point(32.667547, -117.160477), - Point(32.654748, -117.147579), - Point(32.651933, -117.150312), - Point(32.649676, -117.144334), - Point(32.631665, -117.138201), - Point(32.632033, -117.132249), - Point(32.630156, -117.137234), - Point(32.628072, -117.136479), - Point(32.630315, -117.131443), - Point(32.625930, -117.135312), - Point(32.623754, -117.131664), - Point(32.627465, -117.130883), - Point(32.622598, -117.128791), - Point(32.622622, -117.133183), - Point(32.618690, -117.133634), - Point(32.618980, -117.128403), - Point(32.609847, -117.132502), - Point(32.604198, -117.125333), - Point(32.588260, -117.122032), - Point(32.591164, -117.116851), - Point(32.587601, -117.105968), - Point(32.583792, -117.104434), - Point(32.570566, -117.101382), - Point(32.569256, -117.122378), - Point(32.560825, -117.122903), - Point(32.557753, -117.131040), - Point(32.542737, -117.124883), - Point(32.534156, -117.126062), - Point(32.563255, -117.134963), - Point(32.584055, -117.134263), - Point(32.619405, -117.140001), - Point(32.655293, -117.157349), - Point(32.669944, -117.169624), - Point(32.682710, -117.189445), - Point(32.685297, -117.208773), - Point(32.679814, -117.224882), - Point(32.697212, -117.227058), - Point(32.707701, -117.219816), - Point(32.711931, -117.214107), - Point(32.715026, -117.196521), - Point(32.713053, -117.189703), - Point(32.707868, -117.191018), +const polygon = [ + GeoCoord(32.707868, -117.191018), + GeoCoord(32.705645, -117.191096), + GeoCoord(32.697756, -117.166664), + GeoCoord(32.686486, -117.163206), + GeoCoord(32.675876, -117.169452), + GeoCoord(32.674726, -117.165233), + GeoCoord(32.679833, -117.158487), + GeoCoord(32.677571, -117.153893), + GeoCoord(32.671987, -117.160079), + GeoCoord(32.667547, -117.160477), + GeoCoord(32.654748, -117.147579), + GeoCoord(32.651933, -117.150312), + GeoCoord(32.649676, -117.144334), + GeoCoord(32.631665, -117.138201), + GeoCoord(32.632033, -117.132249), + GeoCoord(32.630156, -117.137234), + GeoCoord(32.628072, -117.136479), + GeoCoord(32.630315, -117.131443), + GeoCoord(32.625930, -117.135312), + GeoCoord(32.623754, -117.131664), + GeoCoord(32.627465, -117.130883), + GeoCoord(32.622598, -117.128791), + GeoCoord(32.622622, -117.133183), + GeoCoord(32.618690, -117.133634), + GeoCoord(32.618980, -117.128403), + GeoCoord(32.609847, -117.132502), + GeoCoord(32.604198, -117.125333), + GeoCoord(32.588260, -117.122032), + GeoCoord(32.591164, -117.116851), + GeoCoord(32.587601, -117.105968), + GeoCoord(32.583792, -117.104434), + GeoCoord(32.570566, -117.101382), + GeoCoord(32.569256, -117.122378), + GeoCoord(32.560825, -117.122903), + GeoCoord(32.557753, -117.131040), + GeoCoord(32.542737, -117.124883), + GeoCoord(32.534156, -117.126062), + GeoCoord(32.563255, -117.134963), + GeoCoord(32.584055, -117.134263), + GeoCoord(32.619405, -117.140001), + GeoCoord(32.655293, -117.157349), + GeoCoord(32.669944, -117.169624), + GeoCoord(32.682710, -117.189445), + GeoCoord(32.685297, -117.208773), + GeoCoord(32.679814, -117.224882), + GeoCoord(32.697212, -117.227058), + GeoCoord(32.707701, -117.219816), + GeoCoord(32.711931, -117.214107), + GeoCoord(32.715026, -117.196521), + GeoCoord(32.713053, -117.189703), + GeoCoord(32.707868, -117.191018), ]; diff --git a/lib/src/core/google_map.dart b/lib/src/core/google_map.dart index 3d334ec..ac5cb4e 100644 --- a/lib/src/core/google_map.dart +++ b/lib/src/core/google_map.dart @@ -59,6 +59,8 @@ class GoogleMap extends StatefulWidget { static const _defaultLat = 34.0469058; static const _defaultLng = -118.3503948; + /// Gets [MapOperations] interface via provided `key` of + /// [GoogleMapStateBase] state. static MapOperations of(GlobalKey key) => key.currentState; @@ -73,4 +75,10 @@ class GoogleMap extends StatefulWidget { } abstract class GoogleMapStateBase extends State - implements MapOperations {} + implements MapOperations { + @protected + String fixAssetPath(String icon) => + icon.endsWith('/marker_a.png') || icon.endsWith('/marker_b.png') + ? 'packages/flutter_google_maps/' + : ''; +} diff --git a/lib/src/core/google_map.state.dart b/lib/src/core/google_map.state.dart index abffab2..fc3e024 100644 --- a/lib/src/core/google_map.state.dart +++ b/lib/src/core/google_map.state.dart @@ -2,12 +2,10 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'dart:math'; - import 'package:flutter/widgets.dart'; import 'package:google_directions_api/google_directions_api.dart' - show GeoCoordBounds; + show GeoCoord, GeoCoordBounds; import 'google_map.dart'; @@ -35,7 +33,7 @@ class GoogleMapState extends GoogleMapStateBase { @override void addMarker( - Point position, { + GeoCoord position, { String label, String icon, String info, @@ -45,7 +43,7 @@ class GoogleMapState extends GoogleMapStateBase { @override void addPolygon( String id, - Iterable> points, { + Iterable points, { Color strokeColor = const Color(0x000000), double strokeOpacity = 0.8, double strokeWidth = 1, @@ -66,7 +64,7 @@ class GoogleMapState extends GoogleMapStateBase { @override void editPolygon( String id, - Iterable> points, { + Iterable points, { Color strokeColor = const Color(0x000000), double strokeOpacity = 0.8, double strokeWeight = 1, @@ -79,7 +77,7 @@ class GoogleMapState extends GoogleMapStateBase { void removeDirection(origin, destination) => throw UnimplementedError(); @override - void removeMarker(Point position) => throw UnimplementedError(); + void removeMarker(GeoCoord position) => throw UnimplementedError(); @override void removePolygon(String id) => throw UnimplementedError(); diff --git a/lib/src/core/map_operations.dart b/lib/src/core/map_operations.dart index 0eed73f..1224d56 100644 --- a/lib/src/core/map_operations.dart +++ b/lib/src/core/map_operations.dart @@ -3,10 +3,9 @@ // BSD-style license that can be found in the LICENSE file. import 'dart:ui' show Color; -import 'dart:math' show Point; import 'package:google_directions_api/google_directions_api.dart' - show GeoCoordBounds; + show GeoCoord, GeoCoordBounds; abstract class MapOperations implements MapMarkers, MapDirections, MapPolygones { @@ -32,14 +31,14 @@ abstract class MapMarkers { /// /// If marker with same [position] have been already added, addition of a new marker will be ignored. void addMarker( - Point position, { + GeoCoord position, { String label, String icon, String info, }); /// Removes a marker from map by given [position]. - void removeMarker(Point position); + void removeMarker(GeoCoord position); /// Removes all markers from map. void clearMarkers(); @@ -69,7 +68,7 @@ abstract class MapDirections { /// Removes a direction from map by given [origin] and [destination] coordinates. /// /// [origin] and [destination] are `dynamic` due to following variations: - /// * [LatLng], better use [Point], it will be converted into [LatLng] + /// * [LatLng], better use [GeoCoord], it will be converted into [LatLng] /// * [Place] /// * [String] void removeDirection(dynamic origin, dynamic destination); @@ -86,7 +85,7 @@ abstract class MapPolygones { /// If [id] have been already added, addition of a new polygon will be ignored. void addPolygon( String id, - Iterable> points, { + Iterable points, { Color strokeColor = const Color(0x000000), double strokeOpacity = 0.8, double strokeWidth = 1, @@ -101,7 +100,7 @@ abstract class MapPolygones { /// If [id] have been already added, addition of a new polygon will be ignored. void editPolygon( String id, - Iterable> points, { + Iterable points, { Color strokeColor = const Color(0x000000), double strokeOpacity = 0.8, double strokeWeight = 1, diff --git a/lib/src/core/utils.dart b/lib/src/core/utils.dart deleted file mode 100644 index 98ef47f..0000000 --- a/lib/src/core/utils.dart +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (c) 2020, the MarchDev Toolkit project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'dart:math' as math show Point; - -extension CorePointExtensions on math.Point { - math.Point swapCoords() => math.Point(this.y, this.x); -} diff --git a/lib/src/mobile/google_map.state.dart b/lib/src/mobile/google_map.state.dart index b2b3cec..ee38331 100644 --- a/lib/src/mobile/google_map.state.dart +++ b/lib/src/mobile/google_map.state.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'dart:math' as math show Point; - import 'package:flutter/widgets.dart'; import 'package:flinq/flinq.dart'; @@ -19,7 +17,7 @@ class GoogleMapState extends gmap.GoogleMapStateBase { final _markers = {}; final _polygons = {}; final _polylines = {}; - final _directionMarkerCoords = , dynamic>{}; + final _directionMarkerCoords = {}; GoogleMapController _controller; @@ -69,7 +67,7 @@ class GoogleMapState extends gmap.GoogleMapStateBase { @override void addMarker( - math.Point position, { + GeoCoord position, { String label, String icon, String info, @@ -80,8 +78,8 @@ class GoogleMapState extends gmap.GoogleMapStateBase { throw ArgumentError.notNull('position'); } - if (position.x == null || position.y == null) { - throw ArgumentError.notNull('position.x && position.y'); + if (position.latitude == null || position.longitude == null) { + throw ArgumentError.notNull('position.latitude && position.longitude'); } return true; @@ -97,7 +95,7 @@ class GoogleMapState extends gmap.GoogleMapStateBase { position: position.toLatLng(), icon: icon == null ? BitmapDescriptor.defaultMarker - : await _getBmpDescFromAsset(icon), + : await _getBmpDescFromAsset('${fixAssetPath(icon)}$icon'), infoWindow: info != null ? InfoWindow(title: info) : null, zIndex: zIndex?.toDouble(), ); @@ -106,14 +104,14 @@ class GoogleMapState extends gmap.GoogleMapStateBase { } @override - void removeMarker(math.Point position) { + void removeMarker(GeoCoord position) { assert(() { if (position == null) { throw ArgumentError.notNull('position'); } - if (position.x == null || position.y == null) { - throw ArgumentError.notNull('position.x && position.y'); + if (position.latitude == null || position.longitude == null) { + throw ArgumentError.notNull('position.latitude && position.longitude'); } return true; @@ -153,10 +151,11 @@ class GoogleMapState extends gmap.GoogleMapStateBase { }()); final request = DirectionsRequest( - origin: origin is math.Point ? LatLng(origin.x, origin.y) : origin, - destination: destination is math.Point - ? destination.toLatLng() - : destination, + origin: origin is GeoCoord + ? LatLng(origin.latitude, origin.longitude) + : origin, + destination: + destination is GeoCoord ? destination.toLatLng() : destination, travelMode: TravelMode.driving, ); directionsService.route( @@ -174,39 +173,39 @@ class GoogleMapState extends gmap.GoogleMapStateBase { final leg = response?.routes?.firstOrNull?.legs?.firstOrNull; - final startLatLng = leg?.startLocation?.toLatLng(); + final startLatLng = leg?.startLocation; if (startLatLng != null) { - _directionMarkerCoords[startLatLng.toPoint()] = origin; + _directionMarkerCoords[startLatLng] = origin; if (startIcon != null || startInfo != null || startLabel != null) { addMarker( - startLatLng.toPoint(), - icon: startIcon /* ?? 'assets/images/marker_a.png' */, + startLatLng, + icon: startIcon ?? 'assets/images/marker_a.png', info: startInfo ?? leg.startAddress, label: startLabel, ); } else { addMarker( - startLatLng.toPoint(), - // icon: 'assets/images/marker_a.png', // TODO: figure out wtf is happening + startLatLng, + icon: 'assets/images/marker_a.png', info: leg.startAddress, ); } } - final endLatLng = leg?.endLocation?.toLatLng(); + final endLatLng = leg?.endLocation; if (endLatLng != null) { - _directionMarkerCoords[endLatLng.toPoint()] = destination; + _directionMarkerCoords[endLatLng] = destination; if (endIcon != null || endInfo != null || endLabel != null) { addMarker( - endLatLng.toPoint(), - icon: endIcon /* ?? 'assets/images/marker_b.png' */, + endLatLng, + icon: endIcon ?? 'assets/images/marker_b.png', info: endInfo ?? leg.endAddress, label: endLabel, ); } else { addMarker( - endLatLng.toPoint(), - // icon: 'assets/images/marker_b.png', + endLatLng, + icon: 'assets/images/marker_b.png', info: leg.endAddress, ); } @@ -217,7 +216,7 @@ class GoogleMapState extends gmap.GoogleMapStateBase { polylineId: polylineId, points: response?.routes?.firstOrNull?.overviewPath ?.mapList((_) => _.toLatLng()) ?? - [startLatLng, endLatLng], + [startLatLng?.toLatLng(), endLatLng?.toLatLng()], color: const Color(0xcc2196F3), startCap: Cap.roundCap, endCap: Cap.roundCap, @@ -245,12 +244,12 @@ class GoogleMapState extends gmap.GoogleMapStateBase { }()); var value = _polylines.remove('${origin}_$destination'); - final start = value?.points?.firstOrNull?.toPoint(); + final start = value?.points?.firstOrNull?.toGeoCoord(); if (start != null) { removeMarker(start); _directionMarkerCoords.remove(start); } - final end = value?.points?.lastOrNull?.toPoint(); + final end = value?.points?.lastOrNull?.toGeoCoord(); if (end != null) { removeMarker(end); _directionMarkerCoords.remove(end); @@ -261,12 +260,12 @@ class GoogleMapState extends gmap.GoogleMapStateBase { @override void clearDirections() { for (var polyline in _polylines.values) { - final start = polyline?.points?.firstOrNull?.toPoint(); + final start = polyline?.points?.firstOrNull?.toGeoCoord(); if (start != null) { removeMarker(start); _directionMarkerCoords.remove(start); } - final end = polyline?.points?.lastOrNull?.toPoint(); + final end = polyline?.points?.lastOrNull?.toGeoCoord(); if (end != null) { removeMarker(end); _directionMarkerCoords.remove(end); @@ -279,7 +278,7 @@ class GoogleMapState extends gmap.GoogleMapStateBase { @override void addPolygon( String id, - Iterable> points, { + Iterable points, { Color strokeColor = const Color(0x000000), double strokeOpacity = 0.8, double strokeWidth = 1, @@ -296,7 +295,7 @@ class GoogleMapState extends gmap.GoogleMapStateBase { } if (points.isEmpty) { - throw ArgumentError.value(>[], 'points'); + throw ArgumentError.value([], 'points'); } if (points.length < 3) { @@ -323,7 +322,7 @@ class GoogleMapState extends gmap.GoogleMapStateBase { @override void editPolygon( String id, - Iterable> points, { + Iterable points, { Color strokeColor = const Color(0x000000), double strokeOpacity = 0.8, double strokeWeight = 1, diff --git a/lib/src/mobile/utils.dart b/lib/src/mobile/utils.dart index 296b94f..d43bd32 100644 --- a/lib/src/mobile/utils.dart +++ b/lib/src/mobile/utils.dart @@ -2,21 +2,14 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'dart:math' as math show Point; - import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:google_directions_api/google_directions_api.dart' show GeoCoord, GeoCoordBounds; extension MobileLatLngExtensions on LatLng { - math.Point toPoint() => math.Point(this.latitude, this.longitude); GeoCoord toGeoCoord() => GeoCoord(this.latitude, this.longitude); } -extension MobilePointExtensions on math.Point { - LatLng toLatLng() => LatLng(this.x, this.y); -} - extension MobileGeoCoordExtensions on GeoCoord { LatLng toLatLng() => LatLng(this.latitude, this.longitude); } diff --git a/lib/src/web/google_map.state.dart b/lib/src/web/google_map.state.dart index 392f964..692a62a 100644 --- a/lib/src/web/google_map.state.dart +++ b/lib/src/web/google_map.state.dart @@ -4,7 +4,6 @@ import 'dart:html'; import 'dart:ui' as ui; -import 'dart:math' as math show Point; import 'package:flutter/widgets.dart'; @@ -12,7 +11,7 @@ import 'package:uuid/uuid.dart'; import 'package:flinq/flinq.dart'; import 'package:google_maps/google_maps.dart'; import 'package:google_directions_api/google_directions_api.dart' - show GeoCoordBounds; + show GeoCoord, GeoCoordBounds; import 'utils.dart'; import '../core/google_map.dart'; @@ -56,7 +55,7 @@ class GoogleMapState extends GoogleMapStateBase { @override void addMarker( - math.Point position, { + GeoCoord position, { String label, String icon, String info, @@ -66,8 +65,8 @@ class GoogleMapState extends GoogleMapStateBase { throw ArgumentError.notNull('position'); } - if (position.x == null || position.y == null) { - throw ArgumentError.notNull('position.x && position.y'); + if (position.latitude == null || position.longitude == null) { + throw ArgumentError.notNull('position.latitude && position.longitude'); } return true; @@ -79,7 +78,7 @@ class GoogleMapState extends GoogleMapStateBase { final marker = Marker() ..map = _map ..label = label - ..icon = icon != null ? 'assets/$icon' : null + ..icon = icon != null ? '${fixAssetPath(icon)}assets/$icon' : null ..position = position.toLatLng(); if (info != null) { @@ -108,14 +107,14 @@ class GoogleMapState extends GoogleMapStateBase { } @override - void removeMarker(math.Point position) { + void removeMarker(GeoCoord position) { assert(() { if (position == null) { throw ArgumentError.notNull('position'); } - if (position.x == null || position.y == null) { - throw ArgumentError.notNull('position.x && position.y'); + if (position.latitude == null || position.longitude == null) { + throw ArgumentError.notNull('position.latitude && position.longitude'); } return true; @@ -182,10 +181,11 @@ class GoogleMapState extends GoogleMapStateBase { direction.map = _map; final request = DirectionsRequest() - ..origin = origin is math.Point ? LatLng(origin.x, origin.y) : origin - ..destination = destination is math.Point - ? destination.toLatLng() - : destination + ..origin = origin is GeoCoord + ? LatLng(origin.latitude, origin.longitude) + : origin + ..destination = + destination is GeoCoord ? destination.toLatLng() : destination ..travelMode = TravelMode.DRIVING; directionsService.route( request, @@ -201,14 +201,14 @@ class GoogleMapState extends GoogleMapStateBase { startInfo != null || startLabel != null) { addMarker( - startLatLng.toPoint(), + startLatLng.toGeoCoord(), icon: startIcon, info: startInfo ?? leg.startAddress, label: startLabel, ); } else { addMarker( - startLatLng.toPoint(), + startLatLng.toGeoCoord(), icon: 'assets/images/marker_a.png', info: leg.startAddress, ); @@ -219,14 +219,14 @@ class GoogleMapState extends GoogleMapStateBase { if (endLatLng != null) { if (endIcon != null || endInfo != null || endLabel != null) { addMarker( - endLatLng.toPoint(), + endLatLng.toGeoCoord(), icon: endIcon, info: endInfo ?? leg.endAddress, label: endLabel, ); } else { addMarker( - endLatLng.toPoint(), + endLatLng.toGeoCoord(), icon: 'assets/images/marker_b.png', info: leg.endAddress, ); @@ -259,13 +259,13 @@ class GoogleMapState extends GoogleMapStateBase { value?.map = null; final start = value ?.directions?.routes?.firstOrNull?.legs?.firstOrNull?.startLocation - ?.toPoint(); + ?.toGeoCoord(); if (start != null) { removeMarker(start); } final end = value ?.directions?.routes?.firstOrNull?.legs?.lastOrNull?.endLocation - ?.toPoint(); + ?.toGeoCoord(); if (end != null) { removeMarker(end); } @@ -278,13 +278,13 @@ class GoogleMapState extends GoogleMapStateBase { direction?.map = null; final start = direction ?.directions?.routes?.firstOrNull?.legs?.firstOrNull?.startLocation - ?.toPoint(); + ?.toGeoCoord(); if (start != null) { removeMarker(start); } final end = direction ?.directions?.routes?.firstOrNull?.legs?.lastOrNull?.endLocation - ?.toPoint(); + ?.toGeoCoord(); if (end != null) { removeMarker(end); } @@ -296,7 +296,7 @@ class GoogleMapState extends GoogleMapStateBase { @override void addPolygon( String id, - Iterable> points, { + Iterable points, { Color strokeColor = const Color(0x000000), double strokeOpacity = 0.8, double strokeWidth = 1, @@ -313,7 +313,7 @@ class GoogleMapState extends GoogleMapStateBase { } if (points.isEmpty) { - throw ArgumentError.value(>[], 'points'); + throw ArgumentError.value([], 'points'); } if (points.length < 3) { @@ -342,7 +342,7 @@ class GoogleMapState extends GoogleMapStateBase { @override void editPolygon( String id, - Iterable> points, { + Iterable points, { Color strokeColor = const Color(0x000000), double strokeOpacity = 0.8, double strokeWeight = 1, diff --git a/lib/src/web/utils.dart b/lib/src/web/utils.dart index 52368a5..6db8362 100644 --- a/lib/src/web/utils.dart +++ b/lib/src/web/utils.dart @@ -3,21 +3,15 @@ // BSD-style license that can be found in the LICENSE file. import 'dart:ui' as ui show Color; -import 'dart:math' as math show Point; import 'package:google_maps/google_maps.dart'; import 'package:google_directions_api/google_directions_api.dart' show GeoCoord, GeoCoordBounds; extension WebLatLngExtensions on LatLng { - math.Point toPoint() => math.Point(this.lat, this.lng); GeoCoord toGeoCoord() => GeoCoord(this.lat, this.lng); } -extension WebPointExtensions on math.Point { - LatLng toLatLng() => LatLng(this.x, this.y); -} - extension WebGeoCoordExtensions on GeoCoord { LatLng toLatLng() => LatLng(this.latitude, this.longitude); }