Skip to content

Commit a0c8030

Browse files
committed
icon image 复用; Marker.animateType; BaiduMapManager.hasLocationPermission
1 parent d008535 commit a0c8030

File tree

18 files changed

+167
-41
lines changed

18 files changed

+167
-41
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,14 @@ BaiduMapManager.initSDK('sIMQlfmOXhQmPLF1QMh4aBp8zZO9Lb2A');
124124
| Prop | Type | Default | Description
125125
| ----------------------- |:-----:| :-------:| -------
126126
| title | string| null | 如果没有 InfoWindow,将会根据 title 生成 InfoWindow
127-
| titleOffsetY | int | -80 | title 作为 InfoWindow 展示的 y 轴偏移量,仅 Android
127+
| titleOffsetY | int | -80 | title 作为 InfoWindow 展示的 y 轴偏移量,仅 Android
128128
| location | object| {latitude: 0, longitude: 0} |
129129
| perspective | bool | null | 仅 Android
130130
| flat | bool | null | 仅 Android
131131
| rotate | float | 0 | 旋转角度,仅 Android
132132
| icon | any | null | icon图片,同 <Image> 的 source 属性
133133
| alpha | float | 1 | 透明度,仅 Android
134+
| animateType | string| | 动画效果:drop/grow/jump (iOS 仅支持 drop)
134135
| pinColor | string| red | red/green/purple,大头针颜色,仅 iOS
135136
| onClick | func | | 点击事件回调
136137
##### Cluster 点聚合
@@ -240,6 +241,13 @@ Cluster 示例
240241
</MapView>
241242
```
242243

244+
#### BaiduMapManager
245+
246+
| Method | Description | Result
247+
| ------------------------- | ---------------- | -------
248+
| void initSDK(string apiKey) | iOS 初始化 SDK |
249+
| Promise hasLocationPermission | 是否有定位权限 |
250+
243251
#### Geolocation Methods
244252

245253
| Method | Description | Result

android/src/main/java/org/lovebing/reactnative/baidumap/module/BaiduMapManager.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@
77

88
package org.lovebing.reactnative.baidumap.module;
99

10+
import android.Manifest;
1011
import android.util.Log;
1112
import androidx.annotation.NonNull;
13+
14+
import com.facebook.react.bridge.Promise;
1215
import com.facebook.react.bridge.ReactApplicationContext;
1316
import com.facebook.react.bridge.ReactMethod;
1417

18+
import org.lovebing.reactnative.baidumap.support.AppUtils;
19+
1520
/**
1621
* @author lovebing
1722
* @date 2019/10/30
@@ -33,4 +38,8 @@ public void initSDK(String key) {
3338
Log.i("initSDK", key);
3439
}
3540

41+
@ReactMethod
42+
public void hasLocationPermission(Promise promise) {
43+
promise.resolve(AppUtils.hasPermission(context.getCurrentActivity(), Manifest.permission.ACCESS_FINE_LOCATION));
44+
}
3645
}

android/src/main/java/org/lovebing/reactnative/baidumap/module/GeolocationModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public String getName() {
5656
}
5757

5858
private void initLocationClient(String coorType) {
59-
if(context.getCurrentActivity()!=null) {
59+
if(context.getCurrentActivity() != null) {
6060
AppUtils.checkPermission(context.getCurrentActivity(), Manifest.permission.ACCESS_FINE_LOCATION);
6161
}
6262
LocationClientOption option = new LocationClientOption();

android/src/main/java/org/lovebing/reactnative/baidumap/support/AppUtils.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ public class AppUtils {
2323
public static void checkPermission(Activity activity, String permission) {
2424
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
2525
if (activity.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.M) {
26-
if (ContextCompat.checkSelfPermission(activity, permission)
27-
!= PackageManager.PERMISSION_GRANTED) {
26+
if (!hasPermission(activity, permission)) {
2827
ActivityCompat.requestPermissions(activity, new String[]{permission}, RequestCode.CODE_ASK_PERMISSIONS);
2928
}
3029
}
3130
}
3231
}
32+
33+
public static boolean hasPermission(Activity activity, String permission) {
34+
return ContextCompat.checkSelfPermission(activity, permission) == PackageManager.PERMISSION_GRANTED;
35+
}
3336
}

android/src/main/java/org/lovebing/reactnative/baidumap/support/ConvertUtils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public static LatLng convert(LocationData locationData) {
3333
}
3434

3535
public static <T> T convert(ReadableMap readableMap, Class<T> targetClass) {
36+
if (readableMap == null) {
37+
return null;
38+
}
3639
if (!FILED_MAP.containsKey(targetClass)) {
3740
FILED_MAP.put(targetClass, targetClass.getDeclaredFields());
3841
}

android/src/main/java/org/lovebing/reactnative/baidumap/uimanager/OverlayMarkerManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ public void setTitle(OverlayMarker overlayMarker, String title) {
3838
overlayMarker.setTitle(title);
3939
}
4040

41+
@ReactProp(name = "animateType")
42+
public void setAnimateType(OverlayMarker overlayMarker, String animateType) {
43+
overlayMarker.setAnimateType(animateType);
44+
}
45+
4146
@ReactProp(name = "titleOffsetY")
4247
public void setTitleOffsetY(OverlayMarker overlayMarker, int titleOffsetY) {
4348
overlayMarker.setTitleOffsetY(titleOffsetY);

android/src/main/java/org/lovebing/reactnative/baidumap/view/OverlayMarker.java

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,18 @@
4343
import org.lovebing.reactnative.baidumap.model.IconInfo;
4444
import org.lovebing.reactnative.baidumap.util.BitmapUtil;
4545

46+
import java.util.Map;
4647
import java.util.Objects;
48+
import java.util.concurrent.ConcurrentHashMap;
4749

4850
public class OverlayMarker extends ViewGroup implements OverlayView, ClusterItem {
4951

52+
// TODO 1. 下载中的情况。 2. 清理零引用的 key
53+
private static final Map<String, BitmapDescriptor> BITMAP_DESCRIPTOR_MAP = new ConcurrentHashMap<>();
54+
5055
private String title;
5156
private int titleOffsetY = -100;
57+
private MarkerOptions.MarkerAnimateType animateType = MarkerOptions.MarkerAnimateType.none;
5258
private LatLng position;
5359
private Float rotate;
5460
private Boolean flat;
@@ -66,10 +72,8 @@ public class OverlayMarker extends ViewGroup implements OverlayView, ClusterItem
6672
private final ControllerListener<ImageInfo> imageControllerListener =
6773
new BaseControllerListener<ImageInfo>() {
6874
@Override
69-
public void onFinalImageSet(
70-
String id,
71-
final ImageInfo imageInfo,
72-
Animatable animatable) {
75+
public void onFinalImageSet(String id, final ImageInfo imageInfo, Animatable animatable) {
76+
Log.i("onFinalImageSet", id);
7377
CloseableReference<CloseableImage> imageReference = null;
7478
try {
7579
imageReference = dataSource.getResult();
@@ -81,6 +85,7 @@ public void onFinalImageSet(
8185
if (bitmap != null) {
8286
bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
8387
iconBitmapDescriptor = BitmapDescriptorFactory.fromBitmap(bitmap);
88+
BITMAP_DESCRIPTOR_MAP.put(iconInfo.getUri(), iconBitmapDescriptor);
8489
}
8590
}
8691
}
@@ -167,8 +172,26 @@ public void setIconView(View iconView) {
167172
}
168173
}
169174

170-
public String getTitle() {
171-
return title;
175+
public void setAnimateType(String animateType) {
176+
if (animateType == null) {
177+
return;
178+
}
179+
switch (animateType) {
180+
case "drop":
181+
this.animateType = MarkerOptions.MarkerAnimateType.drop;
182+
break;
183+
case "grow":
184+
this.animateType = MarkerOptions.MarkerAnimateType.grow;
185+
break;
186+
case "jump":
187+
this.animateType = MarkerOptions.MarkerAnimateType.jump;
188+
break;
189+
default:
190+
this.animateType = MarkerOptions.MarkerAnimateType.none;
191+
}
192+
if (marker != null) {
193+
marker.setAnimateType(this.animateType.ordinal());
194+
}
172195
}
173196

174197
public void setTitle(String title) {
@@ -220,6 +243,10 @@ public void setIcon(IconInfo iconInfo) {
220243
if (iconInfo.getUri() == null || iconInfo.getUri().length() == 0) {
221244
return;
222245
}
246+
if (BITMAP_DESCRIPTOR_MAP.containsKey(iconInfo.getUri())) {
247+
iconBitmapDescriptor = BITMAP_DESCRIPTOR_MAP.get(iconInfo.getUri());
248+
return;
249+
}
223250
Log.i("download", iconInfo.getUri());
224251
this.iconInfo = iconInfo;
225252
String uri = iconInfo.getUri();
@@ -312,6 +339,7 @@ private void addOverlay(BaiduMap baiduMap) {
312339
MarkerOptions option = new MarkerOptions()
313340
.position(position)
314341
.alpha(getAlpha())
342+
.animateType(animateType)
315343
.icon(getBitmapDescriptor());
316344
if (rotate != null) {
317345
option.rotate(rotate);

index.d.ts

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ declare namespace ReactNativeBaiduMap {
2020
longitude: number;
2121
}
2222

23+
export interface Stroke {
24+
width: number;
25+
color: string;
26+
}
27+
28+
/**
29+
* 颜色渐变对象
30+
*/
31+
export interface Gradient {
32+
colors: Array<string>;
33+
startPoints: Array<number>
34+
}
35+
2336
type CommonCallBack<T> = (l: T) => void;
2437

2538
/**
@@ -176,6 +189,11 @@ declare namespace ReactNativeBaiduMap {
176189
*/
177190
icon?: ImageSourcePropType;
178191

192+
/**
193+
* 动画效果:drop/grow/jump (iOS 仅支持 drop)
194+
*/
195+
animateType?: string;
196+
179197
/**
180198
* @default 0
181199
*/
@@ -190,19 +208,19 @@ declare namespace ReactNativeBaiduMap {
190208

191209
export interface ArcProps extends ViewProps {
192210
/**
193-
* @default 'AA00FF00'
211+
* @default {width: 5, color: 'AA000000'}
194212
*/
195-
color?: string;
213+
stroke: Stroke;
196214

197215
/**
198-
* @default 4
216+
* 数值长度必须为 3
199217
*/
200-
width?: number;
218+
points: [Location, Location, Location];
201219

202220
/**
203-
* 数值长度必须为 3
221+
* 是否为虚线,仅 iOS
204222
*/
205-
poins: [Location, Location, Location];
223+
dash: boolean;
206224
}
207225

208226
export class Arc extends Component<ArcProps> {
@@ -227,23 +245,18 @@ declare namespace ReactNativeBaiduMap {
227245
center: Location;
228246
}
229247

230-
export interface CircleProps extends ViewProps {}
248+
export interface CircleProps extends ViewProps {
249+
radius: number;
250+
fillColor: string;
251+
stroke: Stroke;
252+
center: Location;
253+
}
231254

232255
export class Circle extends Component<CircleProps> {}
233256

234257
export interface PolylineProps extends ViewProps {
235258
points: Location[];
236-
237-
/**
238-
* 8位(AARRGGBB)
239-
* @default 'AAFF0000'
240-
*/
241-
strokeColor?: string;
242-
243-
/**
244-
* @default 1
245-
*/
246-
lineWidth?: number;
259+
stroke: Stroke;
247260
}
248261

249262
export class Polyline extends Component<PolylineProps> {}
@@ -283,15 +296,23 @@ declare namespace ReactNativeBaiduMap {
283296
export class Text extends Component<TextProps> {}
284297

285298
export interface InfoWindowProps extends ViewProps {
286-
location: Location;
287-
288299
/**
289-
* @default false
300+
* 相对于 point 在 y 轴的偏移量,仅 Android
290301
*/
291-
visible?: boolean;
302+
offsetY: number;
292303
}
293304

294-
export class InfoWindowProps extends Component<TextProps> {}
305+
export class InfoWindow extends Component<InfoWindowProps> {}
306+
307+
export interface HeatMapProps extends ViewProps {
308+
points: Array<Location>;
309+
gradient: Gradient;
310+
}
311+
312+
/**
313+
* 自定义热力图
314+
*/
315+
export class HeatMap extends Component<HeatMapProps> {}
295316
}
296317

297318
export namespace Geolocation {
@@ -431,6 +452,19 @@ declare namespace ReactNativeBaiduMap {
431452
*/
432453
export function openWalkNavi(sl: OpenLocation, el: OpenLocation): void;
433454
}
455+
456+
export namespace BaiduMapManager {
457+
/**
458+
* iOS 初始化 SDK
459+
* @param appKey
460+
*/
461+
export function initSDK(appKey: string): void;
462+
463+
/**
464+
* 是否有定位权限
465+
*/
466+
export function hasLocationPermission(): Promise<boolean>;
467+
}
434468
}
435469

436470
export = ReactNativeBaiduMap;

ios/RCTBaiduMap/BMKPointAnnotationPro.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#import "BMKPointAnnotationPro.h"
1010

1111
@implementation BMKPointAnnotationPro {
12-
BMKActionPaopaoView *_pView;
1312
BMKActionPaopaoView *_paopaoView;
1413
}
1514

@@ -18,7 +17,6 @@ @implementation BMKPointAnnotationPro {
1817
- (instancetype)init {
1918
self = [super init];
2019
_annotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:self reuseIdentifier:markerIdentifier];
21-
_annotationView.animatesDrop = YES;
2220
_customPopView = [[UIView alloc] init];
2321
_paopaoView = [[BMKActionPaopaoView alloc] initWithCustomView:_customPopView];
2422
return self;

ios/RCTBaiduMap/GeolocationModule.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,4 +290,8 @@ - (void)sendEvent:(NSString *)name body:(NSMutableDictionary *)body {
290290
[self.bridge.eventDispatcher sendDeviceEventWithName:name body:body];
291291
}
292292

293+
+ (BOOL)requiresMainQueueSetup {
294+
return YES;
295+
}
296+
293297
@end

0 commit comments

Comments
 (0)