Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
R
react-native-amap3d
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
放牛的园子
react-native-amap3d
Commits
b0bda04f
Commit
b0bda04f
authored
Jul 19, 2017
by
Qiu Xiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
重构 iOS Marker
ref #7
parent
0a1c8064
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
78 additions
and
101 deletions
+78
-101
marker.js
example/src/examples/marker.js
+1
-0
AMapMarker.h
ios/AMapMarker.h
+2
-8
AMapMarker.m
ios/AMapMarker.m
+70
-75
AMapOverlay.h
ios/AMapOverlay.h
+0
-1
AMapOverlay.m
ios/AMapOverlay.m
+3
-1
AMapOverlayManager.m
ios/AMapOverlayManager.m
+1
-6
AMapViewManager.m
ios/AMapViewManager.m
+1
-10
No files found.
example/src/examples/marker.js
View file @
b0bda04f
...
...
@@ -70,6 +70,7 @@ export default class MarkerExample extends Component {
/
>
<
Marker
icon
=
'green'
onInfoWindowPress
=
{
this
.
_handleCustomInfoWindowPress
}
coordinate
=
{{
latitude
:
39.806901
,
longitude
:
116.297972
,
...
...
ios/AMapMarker.h
View file @
b0bda04f
#import "AMapView.h"
#import "AMapOverlay.h"
@interface
AMapMarker
:
UI
View
<
MAAnnotation
,
AMapOverlayDelegate
>
@interface
AMapMarker
:
MAAnnotation
View
<
MAAnnotation
,
AMapOverlayDelegate
>
@property
(
nonatomic
,
copy
)
RCTBubblingEventBlock
onPress
;
@property
(
nonatomic
,
copy
)
RCTBubblingEventBlock
onInfoWindowPress
;
@property
(
nonatomic
,
copy
)
RCTBubblingEventBlock
onDragStart
;
@property
(
nonatomic
,
copy
)
RCTBubblingEventBlock
onDrag
;
@property
(
nonatomic
,
copy
)
RCTBubblingEventBlock
onDragEnd
;
@property
(
nonatomic
,
assign
)
BOOL
dragging
;
-
(
CLLocationCoordinate2D
)
coordinate
;
-
(
NSString
*
)
title
;
-
(
NSString
*
)
subtitle
;
-
(
BOOL
)
active
;
-
(
MAAnnotationView
*
)
annotationView
;
-
(
void
)
setMapView
:(
AMapView
*
)
mapView
;
-
(
void
)
setCoordinate
:(
CLLocationCoordinate2D
)
coordinat
e
;
-
(
void
)
updateActiv
e
;
@end
ios/AMapMarker.m
View file @
b0bda04f
#import <React/UIView+React.h>
#import "AMapMarker.h"
#pragma ide diagnostic ignored "OCUnusedMethodInspection"
@implementation
AMapMarker
{
MAAnnotationView
*
_annotationView
;
MAPointAnnotation
*
_annotation
;
AMapOverlay
*
_marker
;
MAPinAnnotationView
*
_pinView
;
MAPinAnnotationColor
_pinColor
;
MACustomCalloutView
*
_calloutView
;
AMapOverlay
*
_callout
;
AMapView
*
_mapView
;
BOOL
_active
;
NSString
*
_title
;
NSString
*
_subtitle
;
CLLocationCoordinate2D
_coordinate
;
MAPinAnnotationColor
_pinColor
;
BOOL
_draggable
;
NSInteger
_zIndex
;
}
-
(
MAAnnotationView
*
)
annotationView
{
return
_annotationView
;
-
(
instancetype
)
init
{
_annotation
=
[
MAPointAnnotation
new
];
self
=
[
super
initWithAnnotation
:
_annotation
reuseIdentifier
:
nil
];
self
.
canShowCallout
=
YES
;
[
self
addGestureRecognizer
:[
[
UITapGestureRecognizer
alloc
]
initWithTarget
:
self
action
:
@selector
(
_handleTap
:)]];
return
self
;
}
-
(
NSString
*
)
title
{
return
_title
;
return
_
annotation
.
title
;
}
-
(
NSString
*
)
subtitle
{
return
_subtitle
;
return
_
annotation
.
subtitle
;
}
-
(
CLLocationCoordinate2D
)
coordinate
{
return
_coordinate
;
}
-
(
void
)
setCoordinate
:
(
CLLocationCoordinate2D
)
coordinate
{
_coordinate
=
coordinate
;
_annotation
.
coordinate
=
coordinate
;
return
_annotation
.
coordinate
;
}
-
(
void
)
setTitle
:
(
NSString
*
)
title
{
_title
=
title
;
_annotation
.
title
=
title
;
}
-
(
void
)
setActive
:
(
BOOL
)
active
{
_active
=
active
;
if
(
active
)
{
[
_mapView
selectAnnotation
:
self
animated
:
YES
];
}
else
{
[
_mapView
deselectAnnotation
:
self
animated
:
YES
];
}
}
-
(
void
)
setIcon
:
(
MAPinAnnotationColor
)
color
{
_pinColor
=
color
;
((
MAPinAnnotationView
*
)
_annotationView
)
.
pinColor
=
color
;
_pinView
.
pinColor
=
color
;
}
-
(
void
)
setDescription
:
(
NSString
*
)
description
{
_subtitle
=
description
;
_annotation
.
subtitle
=
description
;
}
-
(
void
)
setDraggable
:
(
BOOL
)
draggable
{
_draggable
=
draggable
;
_annotationView
.
draggable
=
draggable
;
-
(
void
)
setCoordinate
:
(
CLLocationCoordinate2D
)
coordinate
{
_annotation
.
coordinate
=
coordinate
;
}
-
(
void
)
setInfoWindowEnabled
:
(
BOOL
)
enabled
{
_annotationView
.
canShowCallout
=
enabled
;
-
(
void
)
setActive
:
(
BOOL
)
active
{
_active
=
active
;
_pinView
.
selected
=
active
;
self
.
selected
=
active
;
[
self
updateActive
];
}
-
(
void
)
updateActive
{
dispatch_async
(
dispatch_get_main_queue
(),
^
{
if
(
_active
)
{
[
_mapView
selectAnnotation
:
self
animated
:
YES
];
}
else
{
[
_mapView
deselectAnnotation
:
self
animated
:
YES
];
}
});
}
-
(
void
)
set
ZIndex
:
(
NSInteger
)
zIndex
{
_
zIndex
=
zIndex
;
_annotationView
.
zIndex
=
zIndex
;
-
(
void
)
set
InfoWindowEnabled
:
(
BOOL
)
enabled
{
_
pinView
.
canShowCallout
=
enabled
;
self
.
canShowCallout
=
enabled
;
}
-
(
void
)
setMapView
:
(
AMapView
*
)
mapView
{
_mapView
=
mapView
;
}
-
(
void
)
_handleTap
:
(
UITapGestureRecognizer
*
)
recognizer
{
_active
=
YES
;
[
self
updateActive
];
if
(
self
.
onInfoWindowPress
)
{
self
.
onInfoWindowPress
(@{});
}
}
-
(
BOOL
)
active
{
return
_active
;
}
-
(
void
)
insertReactSubview
:
(
id
<
RCTComponent
>
)
subview
atIndex
:
(
NSInteger
)
atIndex
{
if
(
atIndex
==
0
)
{
_annotation
=
[
MAPointAnnotation
new
];
_annotation
.
coordinate
=
_coordinate
;
_annotation
.
title
=
_title
;
_annotation
.
subtitle
=
_subtitle
;
if
([
subview
isKindOfClass
:[
AMapOverlay
class
]])
{
_marker
=
(
AMapOverlay
*
)
subview
;
_marker
.
delegate
=
self
;
_annotationView
=
[[
MAAnnotationView
alloc
]
initWithAnnotation
:
_annotation
reuseIdentifier
:
nil
];
}
else
{
_annotationView
=
[[
MAPinAnnotationView
alloc
]
initWithAnnotation
:
_annotation
reuseIdentifier
:
nil
];
((
MAPinAnnotationView
*
)
_annotationView
).
pinColor
=
_pinColor
;
-
(
MAAnnotationView
*
)
annotationView
{
if
(
self
.
reactSubviews
.
count
==
0
)
{
if
(
_pinView
==
nil
)
{
_pinView
=
[[
MAPinAnnotationView
alloc
]
initWithAnnotation
:
_annotation
reuseIdentifier
:
nil
];
_pinView
.
canShowCallout
=
YES
;
_pinView
.
draggable
=
self
.
draggable
;
_pinView
.
pinColor
=
_pinColor
;
_pinView
.
customCalloutView
=
_calloutView
;
}
return
_pinView
;
}
else
{
return
self
;
}
}
_annotationView
.
canShowCallout
=
YES
;
_annotationView
.
draggable
=
_draggable
;
_annotationView
.
zIndex
=
_zIndex
;
}
else
if
(
atIndex
==
1
&&
[
subview
isKindOfClass
:[
AMapOverlay
class
]])
{
-
(
void
)
insertReactSubview
:
(
id
<
RCTComponent
>
)
subview
atIndex
:
(
NSInteger
)
atIndex
{
if
(
atIndex
==
0
&&
subview
.
reactSubviews
.
count
>
0
)
{
[
super
insertReactSubview
:
subview
atIndex
:
atIndex
];
}
if
(
atIndex
==
1
&&
[
subview
isKindOfClass
:[
AMapOverlay
class
]])
{
_callout
=
(
AMapOverlay
*
)
subview
;
_callout
.
delegate
=
self
;
UIButton
*
button
=
[
UIButton
new
];
[
button
addSubview
:
_callout
];
_annotationView
.
customCalloutView
=
[[
MACustomCalloutView
alloc
]
initWithCustomView
:
button
];
_calloutView
=
[[
MACustomCalloutView
alloc
]
initWithCustomView
:
button
];
self
.
customCalloutView
=
_calloutView
;
}
}
-
(
void
)
didUpdateReactSubviews
{
[
super
didUpdateReactSubviews
];
self
.
bounds
=
self
.
reactSubviews
[
0
].
bounds
;
}
#pragma mark AMapOverlayDelegate
-
(
void
)
update
:
(
AMapOverlay
*
)
overlay
{
if
(
self
.
dragging
)
{
return
;
}
CGFloat
width
=
CGRectGetWidth
(
overlay
.
bounds
);
CGFloat
height
=
CGRectGetHeight
(
overlay
.
bounds
);
if
(
overlay
==
_marker
)
{
UIGraphicsBeginImageContextWithOptions
([
_marker
bounds
].
size
,
NO
,
0
.
0
f
);
[
_marker
.
layer
renderInContext
:
UIGraphicsGetCurrentContext
()];
UIImage
*
image
=
UIGraphicsGetImageFromCurrentImageContext
();
UIGraphicsEndImageContext
();
_annotationView
.
image
=
image
;
_annotationView
.
centerOffset
=
CGPointMake
(
0
,
-
height
/
2
);
}
else
if
(
overlay
==
_callout
)
{
_annotationView
.
customCalloutView
.
bounds
=
CGRectMake
(
0
,
0
,
width
,
height
);
}
self
.
customCalloutView
.
bounds
=
overlay
.
bounds
;
}
@end
ios/AMapOverlay.h
View file @
b0bda04f
...
...
@@ -9,5 +9,4 @@
@interface
AMapOverlay
:
RCTView
@property
(
nonatomic
,
strong
)
id
<
AMapOverlayDelegate
>
delegate
;
-
(
void
)
update
;
@end
ios/AMapOverlay.m
View file @
b0bda04f
#import <React/UIView+React.h>
#import "AMapOverlay.h"
@implementation
AMapOverlay
{
}
-
(
void
)
update
{
-
(
void
)
didUpdateReactSubviews
{
[
super
didUpdateReactSubviews
];
[
self
.
delegate
update
:
self
];
}
...
...
ios/AMapOverlayManager.m
View file @
b0bda04f
...
...
@@ -15,11 +15,6 @@ RCT_EXPORT_MODULE()
return
[
AMapOverlay
new
];
}
RCT_EXPORT_METHOD
(
update
:
(
nonnull
NSNumber
*
)
reactTag
)
{
[
self
.
bridge
.
uiManager
addUIBlock
:
^
(
__unused
RCTUIManager
*
uiManager
,
NSDictionary
<
NSNumber
*
,
UIView
*>
*
viewRegistry
)
{
id
view
=
viewRegistry
[
reactTag
];
[(
AMapOverlay
*
)
view
update
];
}];
}
RCT_EXPORT_METHOD
(
update
:
(
nonnull
NSNumber
*
)
reactTag
)
{}
@end
ios/AMapViewManager.m
View file @
b0bda04f
...
...
@@ -16,7 +16,6 @@ RCT_EXPORT_MODULE()
-
(
UIView
*
)
view
{
AMapView
*
mapView
=
[
AMapView
new
];
// when scroll view contains Map maybe we need stop Map Rending Cost.
mapView
.
runLoopMode
=
NSDefaultRunLoopMode
;
mapView
.
allowsAnnotationViewSorting
=
YES
;
mapView
.
centerCoordinate
=
CLLocationCoordinate2DMake
(
39
.
9042
,
116
.
4074
);
...
...
@@ -105,13 +104,7 @@ RCT_EXPORT_METHOD(animateTo:(nonnull NSNumber *)reactTag params:(NSDictionary *)
-
(
MAAnnotationView
*
)
mapView
:
(
MAMapView
*
)
mapView
viewForAnnotation
:
(
id
<
MAAnnotation
>
)
annotation
{
if
([
annotation
isKindOfClass
:[
AMapMarker
class
]])
{
AMapMarker
*
marker
=
(
AMapMarker
*
)
annotation
;
if
(
marker
.
active
)
{
dispatch_async
(
dispatch_get_main_queue
(),
^
{
// directly call selectAnnotation not work, because of there has no current AnnotationView presentation.
// use RUNLOOP
[
mapView
selectAnnotation
:
marker
animated
:
YES
];
});
}
[
marker
updateActive
];
return
marker
.
annotationView
;
}
return
nil
;
...
...
@@ -141,12 +134,10 @@ RCT_EXPORT_METHOD(animateTo:(nonnull NSNumber *)reactTag params:(NSDictionary *)
-
(
void
)
mapView
:
(
MAMapView
*
)
mapView
annotationView
:
(
MAAnnotationView
*
)
view
didChangeDragState
:
(
MAAnnotationViewDragState
)
newState
fromOldState
:
(
MAAnnotationViewDragState
)
oldState
{
AMapMarker
*
marker
=
(
AMapMarker
*
)
view
.
annotation
;
marker
.
dragging
=
NO
;
if
(
newState
==
MAAnnotationViewDragStateStarting
&&
marker
.
onDragStart
)
{
marker
.
onDragStart
(@{});
}
if
(
newState
==
MAAnnotationViewDragStateDragging
)
{
marker
.
dragging
=
YES
;
if
(
marker
.
onDrag
)
{
marker
.
onDrag
(@{});
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment