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
4d19ee36
Commit
4d19ee36
authored
Jun 03, 2017
by
Qiu Xiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
重写 InfoWindow 的默认 UI,提供更好的显示效果
parent
3a8fcba0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
11 deletions
+34
-11
AMapMarker.java
...id/src/main/java/cn/qiuxiang/react/amap3d/AMapMarker.java
+2
-2
AMapView.java
android/src/main/java/cn/qiuxiang/react/amap3d/AMapView.java
+27
-1
marker.js
example/src/marker.js
+5
-8
No files found.
android/src/main/java/cn/qiuxiang/react/amap3d/AMapMarker.java
View file @
4d19ee36
...
...
@@ -34,7 +34,7 @@ public class AMapMarker extends ReactViewGroup {
private
static
final
Map
<
String
,
Float
>
COLORS
;
static
{
COLORS
=
new
HashMap
<
String
,
Float
>();
COLORS
=
new
HashMap
<>();
COLORS
.
put
(
"HUE_AZURE"
,
BitmapDescriptorFactory
.
HUE_AZURE
);
COLORS
.
put
(
"HUE_BLUE"
,
BitmapDescriptorFactory
.
HUE_BLUE
);
COLORS
.
put
(
"HUE_CYAN"
,
BitmapDescriptorFactory
.
HUE_CYAN
);
...
...
@@ -56,7 +56,7 @@ public class AMapMarker extends ReactViewGroup {
private
float
opacity
=
1
;
private
boolean
draggable
=
false
;
private
boolean
selected
;
private
boolean
infoWindowEnabled
=
fals
e
;
private
boolean
infoWindowEnabled
=
tru
e
;
private
BitmapDescriptor
bitmapDescriptor
;
private
RCTEventEmitter
eventEmitter
;
private
DataSubscriber
<
CloseableReference
<
CloseableImage
>>
dataSubscriber
=
...
...
android/src/main/java/cn/qiuxiang/react/amap3d/AMapView.java
View file @
4d19ee36
package
cn
.
qiuxiang
.
react
.
amap3d
;
import
android.annotation.SuppressLint
;
import
android.content.Context
;
import
android.graphics.Color
;
import
android.location.Location
;
import
android.view.View
;
import
android.widget.LinearLayout
;
import
android.widget.TextView
;
import
com.amap.api.maps.AMap
;
import
com.amap.api.maps.MapView
;
...
...
@@ -119,7 +123,25 @@ public class AMapView extends MapView {
@Override
public
View
getInfoContents
(
Marker
marker
)
{
return
null
;
LinearLayout
layout
=
new
LinearLayout
(
context
);
layout
.
setOrientation
(
LinearLayout
.
VERTICAL
);
TextView
titleView
=
new
TextView
(
context
);
titleView
.
setText
(
marker
.
getTitle
());
titleView
.
setTextColor
(
Color
.
parseColor
(
"#212121"
));
layout
.
addView
(
titleView
);
String
snippet
=
marker
.
getSnippet
();
if
(!
snippet
.
isEmpty
())
{
TextView
snippetView
=
new
TextView
(
context
);
snippetView
.
setText
(
snippet
);
snippetView
.
setSingleLine
(
false
);
snippetView
.
setMaxEms
(
12
);
snippetView
.
setPadding
(
0
,
(
int
)
pxFromDp
(
context
,
5
),
0
,
0
);
snippetView
.
setTextColor
(
Color
.
parseColor
(
"#757575"
));
layout
.
addView
(
snippetView
);
}
return
layout
;
}
});
}
...
...
@@ -132,4 +154,8 @@ public class AMapView extends MapView {
public
void
sendEvent
(
String
name
,
WritableMap
data
)
{
eventEmitter
.
receiveEvent
(
getId
(),
name
,
data
);
}
private
static
float
pxFromDp
(
Context
context
,
float
dp
)
{
return
dp
*
context
.
getResources
().
getDisplayMetrics
().
density
;
}
}
example/src/marker.js
View file @
4d19ee36
...
...
@@ -28,7 +28,6 @@ export default class MarkerComponent extends Component {
return
<
MapView
style
=
{
StyleSheet
.
absoluteFill
}
>
<
Marker
draggable
showsInfoWindow
title
=
'一个可拖拽的 Marker'
onDragEnd
=
{({
nativeEvent
})
=>
Alert
.
alert
(
`新坐标:
${
nativeEvent
.
latitude
}
,
${
nativeEvent
.
longitude
}
`
)}
...
...
@@ -40,7 +39,6 @@ export default class MarkerComponent extends Component {
/
>
<
Marker
selected
showsInfoWindow
icon
=
'HUE_RED'
title
=
'一个红色的 Marker'
infoWindowWidth
=
{
100
}
...
...
@@ -49,21 +47,20 @@ export default class MarkerComponent extends Component {
longitude
:
116.297972
,
}}
>
<
InfoWindow
style
=
{
styles
.
customInfoWindow
}
>
<
Text
>
一个自定义
View
的信息窗口
<
/Text
>
<
Text
>
Custom
View
InfoWindow
<
/Text
>
<
/InfoWindow
>
<
/Marker
>
<
Marker
showsInfoWindow
icon
=
{
require
(
'../images/marker.png'
)}
title
=
'自定义图片'
description
=
"Note the use of nativeOnly above. Sometimes you'll have some special properties that you need to expose for the native component, but don't actually want them as part of the API for the associated React component."
coordinate
=
{{
latitude
:
39.906901
,
longitude
:
116.397972
,
}}
/
>
<
Marker
showsInfoWindow
title
=
'自定义 View Marker'
title
=
'Custom View Marker'
icon
=
{()
=>
<
Overlay
style
=
{
styles
.
customMarker
}
>
<
Text
style
=
{
styles
.
markerText
}
>
{
this
.
state
.
time
.
toLocaleTimeString
()}
<
/Text
>
<
/Overlay>
}
...
...
@@ -79,12 +76,12 @@ export default class MarkerComponent extends Component {
const
styles
=
StyleSheet
.
create
({
customInfoWindow
:
{
backgroundColor
:
'#fff'
,
width
:
128
,
position
:
'absolute'
,
padding
:
10
,
elevation
:
4
,
},
customMarker
:
{
width
:
70
,
position
:
'absolute'
,
backgroundColor
:
'#009688'
,
alignItems
:
'center'
,
padding
:
5
,
...
...
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