Browse Source

Merge remote-tracking branch 'origin/master'

i2edu 5 years ago
parent
commit
ea71c170c5

+ 3 - 2
example/lib/main.dart

@@ -76,11 +76,12 @@ class HomePageState extends State<HomePage> {
                       locationMode: LocationMode.Battery_Saving,));
                 AmapLocation.instance.locationStream.listen((d) {
                   print(d.city);
+                  AmapLocation.instance.disposed();
                   // stop location when isOnceLocation is true
 //                     AmapLocation.instance.disposed();
                 });
-                await Future.delayed(Duration(seconds: 60));
-                AmapLocation.instance.disposed();
+//                await Future.delayed(Duration(seconds: 60));
+
               },
               child: Text("get lcoation"),
             ),

BIN
ios/Assets/Images/dog.png


BIN
ios/Assets/Images/i2.png


+ 24 - 0
ios/Classes/FlutterAmapView.m

@@ -69,11 +69,34 @@ static NSString* viewType = @"com.i2edu.mapView";
 -(MAUserLocationRepresentation*)getRepresentation{
     MAUserLocationRepresentation *r = [[MAUserLocationRepresentation alloc] init];
     r.image=[UIImage imageNamed:@"dog"];
+      r.image=[self scaleToSize: r.image size:CGSizeMake(50, 60)];
 //    r.image=[UIImage imageWithContentsOfFile:@"Assets/Images/dog.png"];
 //    r.locationDotFillColor = [UIColor redColor];
     return r;
     
 }
+- (UIImage *)scaleToSize:(UIImage *)image size:(CGSize)size {
+    // 创建一个bitmap的context
+    // 并把它设置成为当前正在使用的context
+    // Determine whether the screen is retina
+    /*
+    if([[UIScreen mainScreen] scale] == 2.0) {
+        UIGraphicsBeginImageContextWithOptions(size, NO, 2.0);
+    } else {
+        UIGraphicsBeginImageContext(size);
+    }
+     */
+    UIGraphicsBeginImageContextWithOptions(size, NO, [[UIScreen mainScreen] scale]);
+    // 绘制改变大小的图片
+    [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
+    // 从当前context中创建一个改变大小后的图片
+    UIImage * scaledImage = UIGraphicsGetImageFromCurrentImageContext();
+    // 使当前的context出堆栈
+    UIGraphicsEndImageContext();
+    // 返回新的改变大小后的图片
+    return scaledImage;
+}
+
 
 - (UIView *)view{
     return _mapView;
@@ -134,6 +157,7 @@ static NSString* viewType = @"com.i2edu.mapView";
         annotationView.channel = self.channel;
         
         annotationView.image = [UIImage imageNamed:@"i2"];
+        annotationView.image=[self scaleToSize: annotationView.image size:CGSizeMake(50, 60)];
 //        annotationView.pinColor = MAPinAnnotationColorPurple;
         annotationView.canShowCallout= NO;       //设置气泡可以弹出,默认为NO
 //        annotationView.animatesDrop = YES;        //设置标注动画显示,默认为NO

+ 1 - 0
lib/amap_location.dart

@@ -42,6 +42,7 @@ class AmapLocation {
   Future<void> disposed() async {
     if (!_locationStreamController.isClosed) {
       await _locationStreamController.close();
+      _locationStreamController=null;
     }
     return await _channel.invokeMethod("closeLocation");
   }

+ 5 - 5
lib/amap_view_controller.dart

@@ -29,24 +29,24 @@ class AmapViewController {
   }
 
   Future<void> setMapMarkers(List<AmapMarker> markers) async {
-    return await _methodChannel.invokeMethod(
+    return  _methodChannel.invokeMethod(
         "setMarkers", {"markers": markers.map((f) => f.toMap()).toList()});
   }
 
   Future<void> onCreateMapView() async {
-    return await _methodChannel.invokeMethod('onCreate');
+    return  _methodChannel.invokeMethod('onCreate');
   }
 
   Future<void> onPauseMapView() async {
-    return await _methodChannel.invokeMethod('onPause');
+    return  _methodChannel.invokeMethod('onPause');
   }
 
   Future<void> onResumeMapView() async {
-    return await _methodChannel.invokeMethod('onResume');
+    return  _methodChannel.invokeMethod('onResume');
   }
 
   Future<void> moveCamera(Map<String,double> map) async {
-    return await _methodChannel.invokeMethod('moveCamera',{"data":map});
+    return  _methodChannel.invokeMethod('moveCamera',{"data":map});
   }
 
   void dispose() {