-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.tsx
More file actions
377 lines (302 loc) · 10.7 KB
/
index.tsx
File metadata and controls
377 lines (302 loc) · 10.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
import React, {
Component,
} from 'react'
import {
requireNativeComponent,
NativeModules,
findNodeHandle,
Platform,
StyleProp,
ViewStyle,
NativeSyntheticEvent
} from 'react-native';
const AMapManager = Platform.OS == 'ios' ? NativeModules.AMap : NativeModules.AMapModule;
export interface CoordinateShort {
lat: number;
lng: number;
}
export interface CoordinateLong {
latitude: number;
longitude: number;
}
export type Coordinate = CoordinateLong | CoordinateShort
export interface Region {
center: Coordinate;
radius: number;
animate: boolean;
}
export interface RegionByLatLngs {
coordinates: any;
animate: boolean;
padding: any;
}
export interface CustomViewProps {
imgName: string;
addrName: string;
index: number;
isSelected: boolean;
}
export interface Marker {
coordinate: Coordinate;
imageName?: string;
customView?: string;
customViewProps?: CustomViewProps;
isToTop?: boolean;
flat?: boolean;
uid?: string;
}
export interface Circle {
coordinate: Coordinate;
radius: number;
lineWidth: number;
strokeColor: string;
fillColor: string;
}
export interface Line {
lineWidth: number;
strokeColor: string;
coordinates: Coordinate[];
}
export interface Polygon {
lineWidth: number;
strokeColor: string;
fillColor: string;
coordinates: Coordinate[];
}
function isFunction(fn: Function) {
return typeof fn === 'function';
}
function safeCallback(callback: Function) {
return isFunction(callback) ? callback : function() {};
}
export type MoveByUserEvent = NativeSyntheticEvent<{
data: {
centerCoordinate: CoordinateLong
}}>;
export type TapEvent = NativeSyntheticEvent<{
coordinate: CoordinateLong
}>
export type ZoomChangeEvent = NativeSyntheticEvent<{
zoomLevel: number;
}>
export type AnnotationDragChangeEvent = NativeSyntheticEvent<{
key: string;
coordinate: CoordinateLong;
}>
export type AnnotationClickEvent = NativeSyntheticEvent<Marker>
export type InfoWindowClickEvent = NativeSyntheticEvent<{
key: string
}>
export interface CommonProps {
// standart satellite
// ios 0 1
// android 1 2
style: StyleProp<ViewStyle>
mapType?: 0|1|2; //地图样式
showsUserLocation?: boolean; //是否显示中心点
bearing?: number; //地图旋转角度
tilt?: number; //地图倾斜角度
// 设置地图视图类型 0 是 MapView 1 是 TextureMapView,默认是 0
mapViewType?: 0|1;
centerCoordinate?: Coordinate; //设置地图中心点
customMapStyleFileName?: string; //设置地图样式
zoomLevel?: number; //地图缩放比例
onDidMoveByUser?: (event: MoveByUserEvent) => void; //挪动地图事件
onSingleTapped?: (evnet: TapEvent) => void; //点击地u事件
onLongTapped?: (evnet: TapEvent) => void; //长按地图事件
onMapZoomChange?: (event: ZoomChangeEvent) => void; //地图缩放比例改变事件
onAnnotationDragChange?: (event: AnnotationDragChangeEvent) => void; //Marker 被拖动事件
onAnnotationClick?: (event: AnnotationClickEvent) => void; //Marker 点击事件
circles?: Circle[]; //地图上面画圆形
markers?: Marker[]; //地图上画点标记
polygons?: Polygon[]; //地图上画多边形
polylines?: Line[]; //地图上画折线
region?: Region|RegionByLatLngs; //设置地图可视区域
}
export interface AndroidProps {
scaleControls?: boolean; //是否显示缩放按钮
tiltGestures?: boolean; //是否允许用户倾斜地图
rotateGestures?: boolean; //是否允许用户旋转地图
infoWindowClass?: boolean; //自定义 InfoWindow 样式的 class 名
onAttachedToWindow?: () => void; //地图 ready 事件
onInfoWindowClick?: (event: InfoWindowClickEvent) => void; // InfoWindow 点击的时候触发的事件
}
export interface SetLatLngZoomParams {
coordinate: Coordinate;
animate: boolean;
zoomLevel: number;
}
export type ReturnAKeyCallback = (key: string) => void;
export type ReturnKeysCallback = (keys: string[]) => void;
export type ReturnResultCallback = (result: boolean) => void;
export default class AMap extends Component<CommonProps&AndroidProps> {
render() {
return (
<NativeAMap
{...this.props}
/>
)
}
printCurrentMapShot(){
AMapManager.printCurrentMapShot(findNodeHandle(this));
}
setCenterCoordinate(coordinate: Coordinate) {
AMapManager.setCenterCoordinate(findNodeHandle(this), coordinate)
}
setRegion(region: Region) {
AMapManager.setRegion(findNodeHandle(this), region)
}
setRegionByLatLngs(region: RegionByLatLngs) {
AMapManager.setRegionByLatLngs(findNodeHandle(this), region)
}
setLatLngZoom(config: SetLatLngZoomParams) {
AMapManager.setLatLngZoom(findNodeHandle(this), config)
}
setMapType(mapType: 0|1|2) {
AMapManager.setMapType(findNodeHandle(this), mapType)
}
movieToUserLocation() {
AMapManager.movieToUserLocation(findNodeHandle(this))
}
setZoomLevel(zoomLevel: number) {
AMapManager.setZoomLevel(findNodeHandle(this), zoomLevel)
}
zoomLevel(callback: (zoomLevel: number) => void) {
AMapManager.zoomLevel(findNodeHandle(this), safeCallback(callback))
}
minZoomLevel(callback: (zoomLevel: number) => void) {
AMapManager.minZoomLevel(findNodeHandle(this), safeCallback(callback))
}
maxZoomLevel(callback: (zoomLevel: number) => void) {
AMapManager.maxZoomLevel(findNodeHandle(this), safeCallback(callback))
}
addAnnotation(annotationConfig: Marker, callback: ReturnAKeyCallback) {
AMapManager.addAnnotation(findNodeHandle(this), annotationConfig, safeCallback(callback))
}
addAnnotations(annotationConfigs: Marker[], callback: ReturnKeysCallback) {
AMapManager.addAnnotations(findNodeHandle(this), annotationConfigs, safeCallback(callback))
}
removeAnnotation(key: string) {
AMapManager.removeAnnotation(findNodeHandle(this), key)
}
removeAnnotations(keys: string) {
AMapManager.removeAnnotations(findNodeHandle(this), keys)
}
removeAllAnnotations(callback: ReturnResultCallback) {
AMapManager.removeAllAnnotations(findNodeHandle(this),callback)
}
showInfoWindow(key: string) {
AMapManager.showInfoWindow(findNodeHandle(this), key)
}
hideInfoWindow(key: string) {
AMapManager.hideInfoWindow(findNodeHandle(this), key)
}
showAnnotation(key: string) {
AMapManager.showAnnotation(findNodeHandle(this), key)
}
hideAnnotation(key: string) {
AMapManager.hideAnnotation(findNodeHandle(this), key)
}
showAnnotations(keys: string[]) {
AMapManager.showAnnotations(findNodeHandle(this), keys)
}
hideAnnotations(keys: string[]) {
AMapManager.hideAnnotations(findNodeHandle(this), keys)
}
addCircle(circleConfig: Circle, callback: ReturnAKeyCallback) {
AMapManager.addCircle(findNodeHandle(this), circleConfig, safeCallback(callback))
}
addCircles(circleConfigs: Circle[], callback: ReturnKeysCallback) {
AMapManager.addCircles(findNodeHandle(this), circleConfigs, safeCallback(callback))
}
removeCircle(key: string) {
AMapManager.removeCircle(findNodeHandle(this), key)
}
removeCircles(keys: string) {
AMapManager.removeCircles(findNodeHandle(this), keys)
}
removeAllCircles(callback: ReturnResultCallback) {
AMapManager.removeAllCircles(findNodeHandle(this),callback)
}
addPolyline(polylineConfig: Line, callback: ReturnAKeyCallback) {
AMapManager.addPolyline(findNodeHandle(this), polylineConfig, safeCallback(callback))
}
addPolylines(polylineConfigs: Line[], callback: ReturnKeysCallback) {
AMapManager.addPolylines(findNodeHandle(this), polylineConfigs, safeCallback(callback))
}
removePolyline(key: string) {
AMapManager.removePolyline(findNodeHandle(this), key)
}
removePolylines(keys: string[]) {
AMapManager.removePolylines(findNodeHandle(this), keys)
}
removeAllPolylines(callback: ReturnResultCallback) {
AMapManager.removeAllPolylines(findNodeHandle(this),callback)
}
addPolygon(polygonConfig: Polygon, callback: ReturnAKeyCallback) {
AMapManager.addPolygon(findNodeHandle(this), polygonConfig, safeCallback(callback))
}
addPolygons(polygonConfigs: Polygon[], callback: ReturnKeysCallback) {
AMapManager.addPolygons(findNodeHandle(this), polygonConfigs, safeCallback(callback))
}
removePolygon(key: string) {
AMapManager.removePolygon(findNodeHandle(this), key)
}
removePolygons(keys: string[]) {
AMapManager.removePolygons(findNodeHandle(this), keys)
}
removeAllPolygons(callback: ReturnResultCallback) {
AMapManager.removeAllPolygons(findNodeHandle(this),callback)
}
setBearing(degree: number){
AMapManager.setBearing(findNodeHandle(this),degree);
}
setTilt(degree: number){
AMapManager.setTilt(findNodeHandle(this),degree);
}
}
export interface LinesInCircleCallbackParam {
results: boolean[]
}
export let AMapUtility= {
isLinesInCircle(center: CoordinateLong, radius: number, lines: Line[], callback: (param: LinesInCircleCallbackParam) => void) {
AMapManager.isLinesInCircle(center, radius, lines, safeCallback(callback));
}
}
export interface PoiItem {
uid: string;
name: string;
type: string;
typecode: string;
latitude: number;
longitude: number;
address: string;
tel: string;
distance: number;
}
export interface SearchParam {
types?: string;
keywords?: string;
limit?: number;
page?: number;
coordinate?: CoordinateLong;
radius?: number;
}
export interface ReGoecodeSearchParam {
coordinate?: Coordinate;
radius?: number;
}
export let AMapSearch = {
searchPoiByCenterCoordinate(params: SearchParam) {
AMapManager.searchPoiByCenterCoordinate(params) //传null为默认参数配置
},
searchPoiByUid(uid: string, callback: (poiItem: PoiItem) => void) {
AMapManager.searchPoiByUid(uid, safeCallback(callback));
},
reGoecodeSearch(params: ReGoecodeSearchParam) {
AMapManager.reGoecodeSearch(params)
},
OnPOISearchDoneEvent: AMapManager != null ? AMapManager.OnPOISearchDoneEvent : null,
OnReGeocodeSearchDoneEvent: AMapManager != null ? AMapManager.OnReGeocodeSearchDoneEvent : null
}
const NativeAMap = Platform.OS == 'ios' ? requireNativeComponent('RCTAMap') : requireNativeComponent('RCTAMapView');