Browse Source

添加定图镜头移动

jun7572 5 years ago
parent
commit
0a42f0ed5b

+ 6 - 0
android/src/main/kotlin/com/i2edu/amap_location/AMapView.kt

@@ -71,6 +71,12 @@ class AMapView(private val context: Context, messenger: BinaryMessenger, id: Int
                 setMarkers(data)
                 result.success(true)
             }
+            "moveCamera" -> {
+                val data =  call.argument<Map<String,Double>>("data")!!
+               val x= data["x"].toString().toDouble();
+                val y= data["y"].toString().toDouble();
+                aMap?.moveCamera(CameraUpdateFactory.newCameraPosition(CameraPosition(LatLng(x, y), 14f, 0f, 0f)))
+            }
             else -> {
                 result.notImplemented()
             }

+ 2 - 1
example/pubspec.yaml

@@ -12,7 +12,8 @@ dependencies:
   # The following adds the Cupertino Icons font to your application.
   # Use with the CupertinoIcons class for iOS style icons.
   cupertino_icons: ^0.1.2
-
+  amap_location:
+    path: ../
 dev_dependencies:
   flutter_test:
     sdk: flutter

+ 9 - 0
ios/Classes/FlutterAmapView.m

@@ -54,6 +54,7 @@ static NSString* viewType = @"com.i2edu.mapView";
         _mapView = [[MAMapView alloc] initWithFrame:frame];
         _mapView.backgroundColor = [UIColor clearColor];
         _mapView.frame = frame;
+        [_mapView setZoomLevel:17.5 animated:YES];
         [_mapView updateUserLocationRepresentation:[self getRepresentation]];
         _mapView.delegate=self;
         
@@ -104,6 +105,14 @@ static NSString* viewType = @"com.i2edu.mapView";
     }else if([call.method isEqualToString:@"onPause"]){
         result(nil);
     }else if([call.method isEqualToString:@"onResume"]){
+        result(nil);
+    }else if([call.method isEqualToString:@"moveCamera"]){
+        NSDictionary  *data = [call.arguments objectForKey:@"data"];
+        NSNumber  *x = data[@"x"];
+        NSNumber  *y = data[@"y"];
+        _mapView.centerCoordinate=CLLocationCoordinate2DMake(x.doubleValue, y.doubleValue);
+        
+        
         result(nil);
     }else {
         result(FlutterMethodNotImplemented);

+ 4 - 0
lib/amap_view_controller.dart

@@ -45,6 +45,10 @@ class AmapViewController {
     return await _methodChannel.invokeMethod('onResume');
   }
 
+  Future<void> moveCamera(Map<String,double> map) async {
+    return await _methodChannel.invokeMethod('moveCamera',{"data":map});
+  }
+
   void dispose() {
     if (!_guideStreamController.isClosed) {
       _guideStreamController.close();