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
6b7e7214
Commit
6b7e7214
authored
Jun 18, 2017
by
Qiu Xiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
实现 iOS 自定义 marker
parent
06b46218
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
91 additions
and
10 deletions
+91
-10
Overlay.js
components/Overlay.js
+13
-5
AMapMarker.h
ios/AMapMarker.h
+4
-2
AMapMarker.m
ios/AMapMarker.m
+23
-3
AMapOverlay.h
ios/AMapOverlay.h
+13
-0
AMapOverlay.m
ios/AMapOverlay.m
+11
-0
AMapOverlayManager.m
ios/AMapOverlayManager.m
+27
-0
No files found.
components/Overlay.js
View file @
6b7e7214
...
@@ -2,6 +2,7 @@ import React, {PropTypes, Component} from 'react'
...
@@ -2,6 +2,7 @@ import React, {PropTypes, Component} from 'react'
import
{
import
{
View
,
View
,
UIManager
,
UIManager
,
Platform
,
NativeModules
,
NativeModules
,
findNodeHandle
,
findNodeHandle
,
requireNativeComponent
,
requireNativeComponent
,
...
@@ -14,11 +15,18 @@ class Overlay extends Component {
...
@@ -14,11 +15,18 @@ class Overlay extends Component {
componentDidUpdate
()
{
componentDidUpdate
()
{
setTimeout
(()
=>
{
setTimeout
(()
=>
{
UIManager
.
dispatchViewManagerCommand
(
switch
(
Platform
.
OS
)
{
findNodeHandle
(
this
),
case
'android'
:
UIManager
.
AMapOverlay
.
Commands
.
update
,
UIManager
.
dispatchViewManagerCommand
(
null
,
findNodeHandle
(
this
),
)
UIManager
.
AMapOverlay
.
Commands
.
update
,
null
,
)
break
;
case
'ios'
:
NativeModules
.
AMapOverlayManager
.
update
(
findNodeHandle
(
this
))
break
;
}
},
0
)
},
0
)
}
}
...
...
ios/AMapMarker.h
View file @
6b7e7214
#import <Foundation/Foundation.h>
#import <Foundation/Foundation.h>
#import <MAMapKit/MAMapKit.h>
#import <MAMapKit/MAMapKit.h>
#import <React/RCTComponent.h>
#import <React/RCTComponent.h>
#import "AMapView.h"
#import "AMapOverlay.h"
#pragma ide diagnostic ignored "OCUnusedPropertyInspection"
#pragma ide diagnostic ignored "OCUnusedPropertyInspection"
@class
AMapView
;
@class
AMapView
;
@class
AMapOverlay
;
@interface
AMapMarker
:
MAAnnotationView
<
MAAnnotation
>
@interface
AMapMarker
:
MAAnnotationView
<
MAAnnotation
,
AMapOverlayDelegate
>
@property
(
nonatomic
,
assign
)
CLLocationCoordinate2D
coordinate
;
@property
(
nonatomic
,
assign
)
CLLocationCoordinate2D
coordinate
;
@property
(
nonatomic
,
copy
)
NSString
*
title
;
@property
(
nonatomic
,
copy
)
NSString
*
title
;
@property
(
nonatomic
,
copy
)
NSString
*
subtitle
;
@property
(
nonatomic
,
copy
)
NSString
*
subtitle
;
@property
(
nonatomic
,
strong
)
AMapView
*
mapView
;
@property
(
nonatomic
,
strong
)
AMapView
*
mapView
;
@property
(
nonatomic
,
assign
)
BOOL
_active
;
@property
(
nonatomic
,
copy
)
RCTBubblingEventBlock
onPress
;
@property
(
nonatomic
,
copy
)
RCTBubblingEventBlock
onPress
;
@property
(
nonatomic
,
copy
)
RCTBubblingEventBlock
onInfoWindowPress
;
@property
(
nonatomic
,
copy
)
RCTBubblingEventBlock
onInfoWindowPress
;
...
...
ios/AMapMarker.m
View file @
6b7e7214
#import "AMapMarker.h"
#import "AMapMarker.h"
#import "AMapView.h"
#pragma ide diagnostic ignored "OCUnusedMethodInspection"
#pragma ide diagnostic ignored "OCUnusedMethodInspection"
@implementation
AMapMarker
{
@implementation
AMapMarker
{
MAAnnotationView
*
_pinView
;
MAAnnotationView
*
_pinView
;
AMapOverlay
*
_iconView
;
BOOL
_active
;
}
}
-
(
void
)
setActive
:
(
BOOL
)
active
{
-
(
void
)
setActive
:
(
BOOL
)
active
{
self
.
_active
=
active
;
_active
=
active
;
if
(
active
)
{
if
(
active
)
{
[
self
.
mapView
selectAnnotation
:
self
animated
:
YES
];
[
self
.
mapView
selectAnnotation
:
self
animated
:
YES
];
}
}
...
@@ -27,6 +28,9 @@
...
@@ -27,6 +28,9 @@
_pinView
=
[[
MAPinAnnotationView
alloc
]
initWithAnnotation
:
self
reuseIdentifier
:
nil
];
_pinView
=
[[
MAPinAnnotationView
alloc
]
initWithAnnotation
:
self
reuseIdentifier
:
nil
];
_pinView
.
annotation
=
self
;
_pinView
.
annotation
=
self
;
}
}
if
(
_iconView
!=
nil
)
{
_pinView
.
image
=
nil
;
}
_pinView
.
zIndex
=
self
.
zIndex
;
_pinView
.
zIndex
=
self
.
zIndex
;
_pinView
.
draggable
=
self
.
draggable
;
_pinView
.
draggable
=
self
.
draggable
;
_pinView
.
canShowCallout
=
self
.
canShowCallout
;
_pinView
.
canShowCallout
=
self
.
canShowCallout
;
...
@@ -34,7 +38,23 @@
...
@@ -34,7 +38,23 @@
}
}
-
(
BOOL
)
active
{
-
(
BOOL
)
active
{
return
self
.
_active
;
return
_active
;
}
-
(
void
)
insertReactSubview
:
(
id
<
RCTComponent
>
)
subview
atIndex
:
(
NSInteger
)
atIndex
{
if
([
subview
isKindOfClass
:[
AMapOverlay
class
]])
{
_iconView
=
(
AMapOverlay
*
)
subview
;
_iconView
.
delegate
=
self
;
}
}
#pragma mark AMapOverlayDelegate
-
(
void
)
update
{
UIGraphicsBeginImageContextWithOptions
([
_iconView
bounds
].
size
,
NO
,
0
.
0
f
);
[
_iconView
.
layer
renderInContext
:
UIGraphicsGetCurrentContext
()];
UIImage
*
image
=
UIGraphicsGetImageFromCurrentImageContext
();
UIGraphicsEndImageContext
();
_pinView
.
image
=
image
;
}
}
@end
@end
ios/AMapOverlay.h
0 → 100644
View file @
6b7e7214
#import <Foundation/Foundation.h>
#import <React/RCTView.h>
@protocol
AMapOverlayDelegate
<
NSObject
>
@optional
-
(
void
)
update
;
@end
@interface
AMapOverlay
:
RCTView
@property
(
nonatomic
,
strong
)
id
delegate
;
-
(
void
)
update
;
@end
\ No newline at end of file
ios/AMapOverlay.m
0 → 100644
View file @
6b7e7214
#import "AMapOverlay.h"
@implementation
AMapOverlay
{
}
-
(
void
)
update
{
[
self
.
delegate
update
];
}
@end
\ No newline at end of file
ios/AMapOverlayManager.m
0 → 100644
View file @
6b7e7214
#import <React/RCTViewManager.h>
#import <React/RCTUIManager.h>
#import "AMapOverlay.h"
#pragma ide diagnostic ignored "OCUnusedClassInspection"
@interface
AMapOverlayManager
:
RCTViewManager
@end
@implementation
AMapOverlayManager
{
}
RCT_EXPORT_MODULE
()
-
(
UIView
*
)
view
{
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
];
}];
}
@end
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