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
f4ee5c3b
Commit
f4ee5c3b
authored
May 31, 2017
by
Qiu Xiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
实现 Marker 颜色选择
parent
ce26e789
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
10 deletions
+44
-10
AMapMarker.java
...id/src/main/java/cn/qiuxiang/react/amap3d/AMapMarker.java
+34
-8
Marker.js
components/Marker.js
+6
-2
marker.js
example/src/marker.js
+4
-0
No files found.
android/src/main/java/cn/qiuxiang/react/amap3d/AMapMarker.java
View file @
f4ee5c3b
...
@@ -20,7 +20,26 @@ import com.facebook.imagepipeline.request.ImageRequest;
...
@@ -20,7 +20,26 @@ import com.facebook.imagepipeline.request.ImageRequest;
import
com.facebook.react.bridge.ReadableMap
;
import
com.facebook.react.bridge.ReadableMap
;
import
com.facebook.react.views.view.ReactViewGroup
;
import
com.facebook.react.views.view.ReactViewGroup
;
import
java.util.HashMap
;
import
java.util.Map
;
public
class
AMapMarker
extends
ReactViewGroup
{
public
class
AMapMarker
extends
ReactViewGroup
{
private
static
final
Map
<
String
,
Float
>
COLORS
;
static
{
COLORS
=
new
HashMap
<
String
,
Float
>();
COLORS
.
put
(
"HUE_AZURE"
,
BitmapDescriptorFactory
.
HUE_AZURE
);
COLORS
.
put
(
"HUE_BLUE"
,
BitmapDescriptorFactory
.
HUE_BLUE
);
COLORS
.
put
(
"HUE_CYAN"
,
BitmapDescriptorFactory
.
HUE_CYAN
);
COLORS
.
put
(
"HUE_GREEN"
,
BitmapDescriptorFactory
.
HUE_GREEN
);
COLORS
.
put
(
"HUE_MAGENTA"
,
BitmapDescriptorFactory
.
HUE_MAGENTA
);
COLORS
.
put
(
"HUE_ORANGE"
,
BitmapDescriptorFactory
.
HUE_ORANGE
);
COLORS
.
put
(
"HUE_RED"
,
BitmapDescriptorFactory
.
HUE_RED
);
COLORS
.
put
(
"HUE_ROSE"
,
BitmapDescriptorFactory
.
HUE_ROSE
);
COLORS
.
put
(
"HUE_VIOLET"
,
BitmapDescriptorFactory
.
HUE_VIOLET
);
COLORS
.
put
(
"HUE_YELLOW"
,
BitmapDescriptorFactory
.
HUE_YELLOW
);
}
private
Marker
marker
;
private
Marker
marker
;
private
LatLng
position
;
private
LatLng
position
;
private
String
title
=
""
;
private
String
title
=
""
;
...
@@ -28,7 +47,7 @@ public class AMapMarker extends ReactViewGroup {
...
@@ -28,7 +47,7 @@ public class AMapMarker extends ReactViewGroup {
private
boolean
flat
=
false
;
private
boolean
flat
=
false
;
private
float
opacity
=
1
;
private
float
opacity
=
1
;
private
boolean
draggable
=
false
;
private
boolean
draggable
=
false
;
private
BitmapDescriptor
iconB
itmapDescriptor
;
private
BitmapDescriptor
b
itmapDescriptor
;
private
DataSubscriber
<
CloseableReference
<
CloseableImage
>>
dataSubscriber
=
private
DataSubscriber
<
CloseableReference
<
CloseableImage
>>
dataSubscriber
=
new
BaseDataSubscriber
<
CloseableReference
<
CloseableImage
>>()
{
new
BaseDataSubscriber
<
CloseableReference
<
CloseableImage
>>()
{
@Override
@Override
...
@@ -36,10 +55,10 @@ public class AMapMarker extends ReactViewGroup {
...
@@ -36,10 +55,10 @@ public class AMapMarker extends ReactViewGroup {
CloseableReference
<
CloseableImage
>
ref
=
dataSource
.
getResult
();
CloseableReference
<
CloseableImage
>
ref
=
dataSource
.
getResult
();
if
(
ref
!=
null
)
{
if
(
ref
!=
null
)
{
try
{
try
{
iconB
itmapDescriptor
=
BitmapDescriptorFactory
.
fromBitmap
(
b
itmapDescriptor
=
BitmapDescriptorFactory
.
fromBitmap
(
((
CloseableStaticBitmap
)
ref
.
get
()).
getUnderlyingBitmap
());
((
CloseableStaticBitmap
)
ref
.
get
()).
getUnderlyingBitmap
());
if
(
marker
!=
null
)
{
if
(
marker
!=
null
)
{
marker
.
setIcon
(
iconB
itmapDescriptor
);
marker
.
setIcon
(
b
itmapDescriptor
);
}
}
}
finally
{
}
finally
{
CloseableReference
.
closeSafely
(
ref
);
CloseableReference
.
closeSafely
(
ref
);
...
@@ -63,7 +82,7 @@ public class AMapMarker extends ReactViewGroup {
...
@@ -63,7 +82,7 @@ public class AMapMarker extends ReactViewGroup {
private
MarkerOptions
getMarkerOptions
()
{
private
MarkerOptions
getMarkerOptions
()
{
return
new
MarkerOptions
()
return
new
MarkerOptions
()
.
setFlat
(
flat
)
.
setFlat
(
flat
)
.
icon
(
iconB
itmapDescriptor
)
.
icon
(
b
itmapDescriptor
)
.
alpha
(
opacity
)
.
alpha
(
opacity
)
.
draggable
(
draggable
)
.
draggable
(
draggable
)
.
position
(
position
)
.
position
(
position
)
...
@@ -113,9 +132,16 @@ public class AMapMarker extends ReactViewGroup {
...
@@ -113,9 +132,16 @@ public class AMapMarker extends ReactViewGroup {
}
}
}
}
public
void
setImage
(
String
uri
)
{
public
void
setImage
(
String
image
)
{
DataSource
<
CloseableReference
<
CloseableImage
>>
dataSource
=
Fresco
if
(
image
.
startsWith
(
"HUE_"
))
{
.
getImagePipeline
().
fetchDecodedImage
(
ImageRequest
.
fromUri
(
uri
),
this
);
bitmapDescriptor
=
BitmapDescriptorFactory
.
defaultMarker
(
COLORS
.
get
(
image
));
dataSource
.
subscribe
(
dataSubscriber
,
CallerThreadExecutor
.
getInstance
());
if
(
marker
!=
null
)
{
marker
.
setIcon
(
bitmapDescriptor
);
}
}
else
{
DataSource
<
CloseableReference
<
CloseableImage
>>
dataSource
=
Fresco
.
getImagePipeline
().
fetchDecodedImage
(
ImageRequest
.
fromUri
(
image
),
this
);
dataSource
.
subscribe
(
dataSubscriber
,
CallerThreadExecutor
.
getInstance
());
}
}
}
}
}
components/Marker.js
View file @
f4ee5c3b
...
@@ -25,6 +25,7 @@ class Marker extends Component {
...
@@ -25,6 +25,7 @@ class Marker extends Component {
/**
/**
* 自定义图片
* 自定义图片
* 可以是 uri 或者 require 引用的资源图片
*/
*/
image
:
PropTypes
.
oneOfType
([
image
:
PropTypes
.
oneOfType
([
PropTypes
.
number
,
PropTypes
.
number
,
...
@@ -54,8 +55,11 @@ class Marker extends Component {
...
@@ -54,8 +55,11 @@ class Marker extends Component {
render
()
{
render
()
{
if
(
this
.
props
.
image
)
{
if
(
this
.
props
.
image
)
{
const
source
=
resolveAssetSource
(
this
.
props
.
image
)
let
image
=
this
.
props
.
image
return
<
AMapMarker
{...
this
.
props
}
image
=
{
source
.
uri
}
/
>
if
(
typeof
this
.
props
.
image
===
'number'
)
{
image
=
resolveAssetSource
(
this
.
props
.
image
).
uri
}
return
<
AMapMarker
{...
this
.
props
}
image
=
{
image
}
/
>
}
else
{
}
else
{
return
<
AMapMarker
{...
this
.
props
}
/
>
return
<
AMapMarker
{...
this
.
props
}
/
>
}
}
...
...
example/src/marker.js
View file @
f4ee5c3b
...
@@ -13,6 +13,10 @@ export default class MarkerComponent extends Component {
...
@@ -13,6 +13,10 @@ export default class MarkerComponent extends Component {
latitude
:
39.806901
,
latitude
:
39.806901
,
longitude
:
116.397972
,
longitude
:
116.397972
,
}}
/
>
}}
/
>
<
Marker
image
=
'HUE_RED'
title
=
'其他颜色'
coordinate
=
{{
latitude
:
39.806901
,
longitude
:
116.297972
,
}}
/
>
<
Marker
image
=
{
require
(
'../images/marker.png'
)}
title
=
'自定义图标'
coordinate
=
{{
<
Marker
image
=
{
require
(
'../images/marker.png'
)}
title
=
'自定义图标'
coordinate
=
{{
latitude
:
39.906901
,
latitude
:
39.906901
,
longitude
:
116.397972
,
longitude
:
116.397972
,
...
...
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