Commit 2532d141 authored by Qiu Xiang's avatar Qiu Xiang

实现 iOS 基本 marker 添加

parent dc63c879
#import <Foundation/Foundation.h>
#import <MAMapKit/MAMapKit.h>
@class AMapView;
@interface AMapMarker : MAAnnotationView <MAAnnotation>
@property(nonatomic, assign) CLLocationCoordinate2D coordinate;
@property(nonatomic, copy) NSString *title;
@property(nonatomic, copy) NSString *subtitle;
@property(nonatomic, assign) BOOL _active;
@property(nonatomic, strong) AMapView *mapView;
- (MAAnnotationView *)getAnnotationView;
- (BOOL)active;
@end
\ No newline at end of file
#import "AMapMarker.h"
#import "AMapView.h"
@implementation AMapMarker {
MAAnnotationView *_pinView;
}
- (void)setActive:(BOOL)active {
self._active = active;
if (active) {
[self.mapView selectAnnotation:self animated:YES];
}
}
- (void)setDescription:(NSString *)description {
self.subtitle = description;
}
- (void)setInfoWindowEnabled:(BOOL)enabled {
self.canShowCallout = enabled;
}
- (MAAnnotationView *)getAnnotationView {
if (_pinView == nil) {
_pinView = [[MAPinAnnotationView alloc] initWithAnnotation:self reuseIdentifier: nil];
_pinView.annotation = self;
}
_pinView.zIndex = self.zIndex;
_pinView.draggable = self.draggable;
_pinView.canShowCallout = self.canShowCallout;
return _pinView;
}
- (BOOL)active {
return self._active;
}
@end
\ No newline at end of file
#import <MAMapKit/MAMapView.h>
#import <React/RCTViewManager.h>
#import "AMapMarker.h"
#pragma ide diagnostic ignored "OCUnusedClassInspection"
@interface AMapMarkerManager : RCTViewManager <MAMapViewDelegate>
@end
@implementation AMapMarkerManager {
}
RCT_EXPORT_MODULE()
- (UIView *)view {
AMapMarker *marker = [AMapMarker new];
marker.canShowCallout = YES;
return marker;
}
RCT_EXPORT_VIEW_PROPERTY(coordinate, CLLocationCoordinate2D)
RCT_EXPORT_VIEW_PROPERTY(title, NSString)
RCT_EXPORT_VIEW_PROPERTY(description, NSString)
RCT_EXPORT_VIEW_PROPERTY(active, BOOL)
RCT_EXPORT_VIEW_PROPERTY(draggable, BOOL)
RCT_EXPORT_VIEW_PROPERTY(infoWindowEnabled, BOOL)
RCT_EXPORT_VIEW_PROPERTY(zIndex, NSInteger)
@end
#import "AMapView.h" #import "AMapView.h"
#import "AMapMarker.h"
#pragma ide diagnostic ignored "OCUnusedMethodInspection" #pragma ide diagnostic ignored "OCUnusedMethodInspection"
...@@ -25,4 +26,17 @@ ...@@ -25,4 +26,17 @@
super.cameraDegree = degree; super.cameraDegree = degree;
} }
- (void)insertReactSubview:(id<RCTComponent>)subview atIndex:(NSInteger)atIndex {
if ([subview isKindOfClass:[AMapMarker class]]) {
((AMapMarker *) subview).mapView = self;
[self addAnnotation:(id <MAAnnotation>) subview];
}
}
- (void)removeReactSubview:(id<RCTComponent>)subview {
if ([subview isKindOfClass:[AMapMarker class]]) {
[self removeAnnotation:(id <MAAnnotation>) subview];
}
}
@end @end
#import <MAMapKit/MAMapKit.h> #import <MAMapKit/MAMapKit.h>
#import <React/RCTViewManager.h> #import <React/RCTViewManager.h>
#import "AMapView.h" #import "AMapView.h"
#import "AMapMarker.h"
#pragma ide diagnostic ignored "OCUnusedClassInspection" #pragma ide diagnostic ignored "OCUnusedClassInspection"
#pragma ide diagnostic ignored "-Woverriding-method-mismatch" #pragma ide diagnostic ignored "-Woverriding-method-mismatch"
...@@ -9,17 +10,16 @@ ...@@ -9,17 +10,16 @@
@end @end
@implementation AMapViewManager { @implementation AMapViewManager {
AMapView *_mapView;
} }
RCT_EXPORT_MODULE() RCT_EXPORT_MODULE()
- (UIView *)view { - (UIView *)view {
_mapView = [[AMapView alloc] init]; AMapView *mapView = [AMapView new];
_mapView.centerCoordinate = CLLocationCoordinate2DMake(39.9042, 116.4074); mapView.centerCoordinate = CLLocationCoordinate2DMake(39.9042, 116.4074);
_mapView.zoomLevel = 10; mapView.zoomLevel = 10;
_mapView.delegate = self; mapView.delegate = self;
return _mapView; return mapView;
} }
RCT_EXPORT_VIEW_PROPERTY(locationEnabled, BOOL) RCT_EXPORT_VIEW_PROPERTY(locationEnabled, BOOL)
...@@ -94,7 +94,6 @@ RCT_EXPORT_VIEW_PROPERTY(onLocation, RCTBubblingEventBlock) ...@@ -94,7 +94,6 @@ RCT_EXPORT_VIEW_PROPERTY(onLocation, RCTBubblingEventBlock)
} }
- (void)mapView:(AMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation updatingLocation:(BOOL)updatingLocation { - (void)mapView:(AMapView *)mapView didUpdateUserLocation:(MAUserLocation *)userLocation updatingLocation:(BOOL)updatingLocation {
NSLog(@"location");
if (!mapView.onLocation) { if (!mapView.onLocation) {
return; return;
} }
...@@ -105,4 +104,11 @@ RCT_EXPORT_VIEW_PROPERTY(onLocation, RCTBubblingEventBlock) ...@@ -105,4 +104,11 @@ RCT_EXPORT_VIEW_PROPERTY(onLocation, RCTBubblingEventBlock)
}); });
} }
- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(AMapMarker *)marker {
if (marker.active) {
[mapView selectAnnotation:marker animated:YES];
}
return [marker getAnnotationView];
}
@end @end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment