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
c181df86
Commit
c181df86
authored
Jun 05, 2017
by
Qiu Xiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
使用 setter 重构
parent
50335b35
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
136 additions
and
142 deletions
+136
-142
AMapMarker.kt
android/src/main/java/cn/qiuxiang/react/amap3d/AMapMarker.kt
+71
-73
AMapMarkerManager.kt
...c/main/java/cn/qiuxiang/react/amap3d/AMapMarkerManager.kt
+18
-18
AMapPolyline.kt
...id/src/main/java/cn/qiuxiang/react/amap3d/AMapPolyline.kt
+37
-41
AMapPolylineManager.kt
...main/java/cn/qiuxiang/react/amap3d/AMapPolylineManager.kt
+9
-9
AMapView.kt
android/src/main/java/cn/qiuxiang/react/amap3d/AMapView.kt
+1
-1
No files found.
android/src/main/java/cn/qiuxiang/react/amap3d/AMapMarker.kt
View file @
c181df86
...
...
@@ -4,23 +4,79 @@ import android.graphics.Bitmap
import
android.graphics.Canvas
import
com.amap.api.maps.AMap
import
com.amap.api.maps.model.*
import
com.facebook.react.bridge.ReadableMap
import
com.facebook.react.bridge.WritableMap
import
com.facebook.react.uimanager.ThemedReactContext
import
com.facebook.react.uimanager.events.RCTEventEmitter
import
com.facebook.react.views.view.ReactViewGroup
class
AMapMarker
(
context
:
ThemedReactContext
)
:
ReactViewGroup
(
context
)
{
companion
object
{
private
val
COLORS
=
mapOf
(
"AZURE"
to
BitmapDescriptorFactory
.
HUE_AZURE
,
"BLUE"
to
BitmapDescriptorFactory
.
HUE_BLUE
,
"CYAN"
to
BitmapDescriptorFactory
.
HUE_CYAN
,
"GREEN"
to
BitmapDescriptorFactory
.
HUE_GREEN
,
"MAGENTA"
to
BitmapDescriptorFactory
.
HUE_MAGENTA
,
"ORANGE"
to
BitmapDescriptorFactory
.
HUE_ORANGE
,
"RED"
to
BitmapDescriptorFactory
.
HUE_RED
,
"ROSE"
to
BitmapDescriptorFactory
.
HUE_ROSE
,
"VIOLET"
to
BitmapDescriptorFactory
.
HUE_VIOLET
,
"YELLOW"
to
BitmapDescriptorFactory
.
HUE_YELLOW
)
}
var
infoWindow
:
ReactViewGroup
?
=
null
private
var
marker
:
Marker
?
=
null
private
var
position
:
LatLng
?
=
null
private
var
title
=
""
private
var
snippet
=
""
private
var
flat
:
Boolean
=
false
private
var
opacity
:
Float
=
1f
private
var
draggable
:
Boolean
=
false
private
var
active
:
Boolean
=
false
private
var
infoWindowEnabled
:
Boolean
=
true
var
infoWindowEnabled
:
Boolean
=
true
var
marker
:
Marker
?
=
null
private
set
var
position
:
LatLng
?
=
null
set
(
value
)
{
field
=
value
marker
?.
position
=
value
}
var
title
=
""
set
(
value
)
{
field
=
value
marker
?.
title
=
value
}
var
snippet
=
""
set
(
value
)
{
field
=
value
marker
?.
snippet
=
value
}
var
flat
:
Boolean
=
false
set
(
value
)
{
field
=
value
marker
?.
isFlat
=
value
}
var
opacity
:
Float
=
1f
set
(
value
)
{
field
=
value
marker
?.
alpha
=
value
}
var
draggable
:
Boolean
=
false
set
(
value
)
{
field
=
value
marker
?.
isDraggable
=
value
}
var
active
:
Boolean
=
false
set
(
value
)
{
field
=
value
if
(
value
)
{
marker
?.
showInfoWindow
()
}
else
{
marker
?.
hideInfoWindow
()
}
}
private
var
bitmapDescriptor
:
BitmapDescriptor
?
=
null
private
val
eventEmitter
:
RCTEventEmitter
=
context
.
getJSModule
(
RCTEventEmitter
::
class
.
java
)
...
...
@@ -47,36 +103,6 @@ class AMapMarker(context: ThemedReactContext) : ReactViewGroup(context) {
.
infoWindowEnable
(
infoWindowEnabled
)
.
snippet
(
snippet
)
fun
setTitle
(
title
:
String
)
{
this
.
title
=
title
marker
?.
title
=
title
}
fun
setSnippet
(
snippet
:
String
)
{
this
.
snippet
=
snippet
marker
?.
snippet
=
snippet
}
fun
setCoordinate
(
coordinate
:
ReadableMap
)
{
position
=
LatLng
(
coordinate
.
getDouble
(
"latitude"
),
coordinate
.
getDouble
(
"longitude"
))
marker
?.
position
=
position
}
fun
setFlat
(
flat
:
Boolean
)
{
this
.
flat
=
flat
marker
?.
isFlat
=
flat
}
fun
setOpacity
(
opacity
:
Float
)
{
this
.
opacity
=
opacity
marker
?.
alpha
=
opacity
}
fun
setDraggable
(
draggable
:
Boolean
)
{
this
.
draggable
=
draggable
marker
?.
isDraggable
=
draggable
}
fun
setIcon
(
icon
:
String
)
{
bitmapDescriptor
=
COLORS
[
icon
.
toUpperCase
()]
?.
let
{
BitmapDescriptorFactory
.
defaultMarker
(
it
)
...
...
@@ -84,29 +110,16 @@ class AMapMarker(context: ThemedReactContext) : ReactViewGroup(context) {
marker
?.
setIcon
(
bitmapDescriptor
)
}
fun
sendEvent
(
name
:
String
,
data
:
WritableMap
)
{
eventEmitter
.
receiveEvent
(
id
,
name
,
data
)
}
fun
setActive
(
selected
:
Boolean
)
{
this
.
active
=
selected
if
(
selected
)
{
marker
?.
showInfoWindow
()
}
else
{
marker
?.
hideInfoWindow
()
}
}
fun
setIconView
(
overlay
:
AMapOverlay
)
{
overlay
.
addOnLayoutChangeListener
{
_
,
_
,
_
,
_
,
_
,
_
,
_
,
_
,
_
->
updateIcon
(
overlay
)
}
overlay
.
addOnLayoutChangeListener
{
_
,
_
,
_
,
_
,
_
,
_
,
_
,
_
,
_
->
updateIcon
View
(
overlay
)
}
overlay
.
setOnUpdateListener
(
object
:
AMapOverlay
.
OnUpdateListener
{
override
fun
onUpdate
()
{
updateIcon
(
overlay
)
updateIcon
View
(
overlay
)
}
})
}
private
fun
updateIcon
(
overlay
:
AMapOverlay
)
{
private
fun
updateIcon
View
(
overlay
:
AMapOverlay
)
{
val
bitmap
=
Bitmap
.
createBitmap
(
overlay
.
width
,
overlay
.
height
,
Bitmap
.
Config
.
ARGB_8888
)
overlay
.
draw
(
Canvas
(
bitmap
))
...
...
@@ -114,22 +127,7 @@ class AMapMarker(context: ThemedReactContext) : ReactViewGroup(context) {
marker
?.
setIcon
(
bitmapDescriptor
)
}
fun
setEnabledInfoWindow
(
enabled
:
Boolean
)
{
infoWindowEnabled
=
enabled
}
companion
object
{
private
val
COLORS
=
mapOf
(
"AZURE"
to
BitmapDescriptorFactory
.
HUE_AZURE
,
"BLUE"
to
BitmapDescriptorFactory
.
HUE_BLUE
,
"CYAN"
to
BitmapDescriptorFactory
.
HUE_CYAN
,
"GREEN"
to
BitmapDescriptorFactory
.
HUE_GREEN
,
"MAGENTA"
to
BitmapDescriptorFactory
.
HUE_MAGENTA
,
"ORANGE"
to
BitmapDescriptorFactory
.
HUE_ORANGE
,
"RED"
to
BitmapDescriptorFactory
.
HUE_RED
,
"ROSE"
to
BitmapDescriptorFactory
.
HUE_ROSE
,
"VIOLET"
to
BitmapDescriptorFactory
.
HUE_VIOLET
,
"YELLOW"
to
BitmapDescriptorFactory
.
HUE_YELLOW
)
fun
sendEvent
(
name
:
String
,
data
:
WritableMap
)
{
eventEmitter
.
receiveEvent
(
id
,
name
,
data
)
}
}
android/src/main/java/cn/qiuxiang/react/amap3d/AMapMarkerManager.kt
View file @
c181df86
package
cn.qiuxiang.react.amap3d
import
android.view.View
import
com.amap.api.maps.model.LatLng
import
com.facebook.react.bridge.ReadableMap
import
com.facebook.react.common.MapBuilder
import
com.facebook.react.uimanager.ThemedReactContext
import
com.facebook.react.uimanager.ViewGroupManager
import
com.facebook.react.uimanager.annotations.ReactProp
import
com.facebook.react.views.view.ReactViewGroup
internal
class
AMapMarkerManager
:
ViewGroupManager
<
AMapMarker
>()
{
override
fun
getName
():
String
{
...
...
@@ -25,48 +24,49 @@ internal class AMapMarkerManager : ViewGroupManager<AMapMarker>() {
}
override
fun
getExportedCustomDirectEventTypeConstants
():
Map
<
String
,
Any
>?
{
val
map
=
HashMap
<
String
,
Any
>()
map
.
put
(
"onMarkerClick"
,
MapBuilder
.
of
(
"registrationName"
,
"onMarkerClick"
))
map
.
put
(
"onMarkerDragStart"
,
MapBuilder
.
of
(
"registrationName"
,
"onMarkerDragStart"
))
map
.
put
(
"onMarkerDrag"
,
MapBuilder
.
of
(
"registrationName"
,
"onMarkerDrag"
))
map
.
put
(
"onMarkerDragEnd"
,
MapBuilder
.
of
(
"registrationName"
,
"onMarkerDragEnd"
))
map
.
put
(
"onInfoWindowClick"
,
MapBuilder
.
of
(
"registrationName"
,
"onInfoWindowClick"
))
return
map
return
mapOf
(
"onMarkerClick"
to
mapOf
(
"registrationName"
to
"onMarkerClick"
),
"onMarkerDragStart"
to
mapOf
(
"registrationName"
to
"onMarkerDragStart"
),
"onMarkerDrag"
to
mapOf
(
"registrationName"
to
"onMarkerDrag"
),
"onMarkerDragEnd"
to
mapOf
(
"registrationName"
to
"onMarkerDragEnd"
),
"onInfoWindowClick"
to
mapOf
(
"registrationName"
to
"onInfoWindowClick"
))
}
@ReactProp
(
name
=
"title"
)
fun
setTitle
(
marker
:
AMapMarker
,
title
:
String
)
{
marker
.
setTitle
(
title
)
marker
.
title
=
title
}
@ReactProp
(
name
=
"description"
)
fun
setSnippet
(
marker
:
AMapMarker
,
description
:
String
)
{
marker
.
s
etSnippet
(
description
)
marker
.
s
nippet
=
description
}
@ReactProp
(
name
=
"coordinate"
)
fun
setCoordinate
(
view
:
AMapMarker
,
coordinate
:
ReadableMap
)
{
view
.
setCoordinate
(
coordinate
)
view
.
position
=
LatLng
(
coordinate
.
getDouble
(
"latitude"
),
coordinate
.
getDouble
(
"longitude"
))
}
@ReactProp
(
name
=
"flat"
)
fun
setFlat
(
marker
:
AMapMarker
,
flat
:
Boolean
)
{
marker
.
setFlat
(
flat
)
marker
.
flat
=
flat
}
@ReactProp
(
name
=
"opacity"
)
override
fun
setOpacity
(
marker
:
AMapMarker
,
opacity
:
Float
)
{
marker
.
setOpacity
(
opacity
)
marker
.
opacity
=
opacity
}
@ReactProp
(
name
=
"draggable"
)
fun
setDraggable
(
marker
:
AMapMarker
,
draggable
:
Boolean
)
{
marker
.
setDraggable
(
draggable
)
marker
.
draggable
=
draggable
}
@ReactProp
(
name
=
"selected"
)
fun
setSelected
(
marker
:
AMapMarker
,
selected
:
Boolean
)
{
marker
.
setActive
(
selected
)
fun
setSelected
(
marker
:
AMapMarker
,
active
:
Boolean
)
{
marker
.
active
=
active
}
@ReactProp
(
name
=
"icon"
)
...
...
@@ -76,6 +76,6 @@ internal class AMapMarkerManager : ViewGroupManager<AMapMarker>() {
@ReactProp
(
name
=
"showsInfoWindow"
)
fun
setEnabledInfoWindow
(
marker
:
AMapMarker
,
enabled
:
Boolean
)
{
marker
.
setEnabledInfoWindow
(
enabled
)
marker
.
infoWindowEnabled
=
enabled
}
}
android/src/main/java/cn/qiuxiang/react/amap3d/AMapPolyline.kt
View file @
c181df86
...
...
@@ -12,61 +12,57 @@ import com.facebook.react.uimanager.events.RCTEventEmitter
import
com.facebook.react.views.view.ReactViewGroup
class
AMapPolyline
(
context
:
ThemedReactContext
)
:
ReactViewGroup
(
context
)
{
private
var
polyline
:
Polyline
?
=
null
private
var
coordinates
:
ArrayList
<
LatLng
>
=
ArrayList
()
private
var
width
:
Float
=
1f
private
var
color
:
Int
=
Color
.
BLACK
private
var
colors
:
ArrayList
<
Int
>
=
ArrayList
()
private
var
opacity
:
Float
=
1f
private
var
zIndex
:
Float
=
0f
private
var
geodesic
:
Boolean
=
false
private
var
dottedLine
:
Boolean
=
false
private
var
gradient
:
Boolean
=
false
private
val
eventEmitter
:
RCTEventEmitter
=
context
.
getJSModule
(
RCTEventEmitter
::
class
.
java
)
var
polyline
:
Polyline
?
=
null
private
set
val
polylineId
:
String
?
get
()
=
polyline
?.
id
fun
setCoordinates
(
coordinates
:
ReadableArray
)
{
this
.
coordinates
=
ArrayList
((
0
..
coordinates
.
size
()
-
1
)
.
map
{
coordinates
.
getMap
(
it
)
}
.
map
{
LatLng
(
it
.
getDouble
(
"latitude"
),
it
.
getDouble
(
"longitude"
))
})
polyline
?.
points
=
this
.
coordinates
var
width
:
Float
=
1f
set
(
value
)
{
field
=
value
polyline
?.
width
=
value
}
fun
setColor
(
color
:
Int
)
{
this
.
color
=
color
polyline
?.
color
=
color
var
color
:
Int
=
Color
.
BLACK
set
(
value
)
{
field
=
value
polyline
?.
color
=
value
}
fun
setWidth
(
width
:
Float
)
{
this
.
width
=
width
polyline
?.
width
=
width
var
opacity
:
Float
=
1f
set
(
value
)
{
field
=
value
polyline
?.
setTransparency
(
value
)
}
fun
setZIndex
(
zIndex
:
Float
)
{
this
.
zIndex
=
zIndex
polyline
?.
zIndex
=
zIndex
var
zIndex
:
Float
=
0f
set
(
value
)
{
field
=
value
polyline
?.
zIndex
=
value
}
fun
setGeodesic
(
geodesic
:
Boolean
)
{
this
.
geodesic
=
geodesic
polyline
?.
isGeodesic
=
geodesic
var
geodesic
:
Boolean
=
false
set
(
value
)
{
field
=
value
polyline
?.
isGeodesic
=
value
}
fun
setDottedLine
(
dottedLine
:
Boolean
)
{
this
.
dottedLine
=
dottedLine
polyline
?.
isDottedLine
=
dottedLine
var
dottedLine
:
Boolean
=
false
set
(
value
)
{
field
=
value
polyline
?.
isDottedLine
=
value
}
fun
setGradient
(
gradient
:
Boolean
)
{
this
.
gradient
=
gradient
}
var
gradient
:
Boolean
=
false
fun
setOpacity
(
opacity
:
Float
)
{
this
.
opacity
=
opacity
polyline
?.
setTransparency
(
opacity
)
private
var
coordinates
:
ArrayList
<
LatLng
>
=
ArrayList
()
private
var
colors
:
ArrayList
<
Int
>
=
ArrayList
()
private
val
eventEmitter
:
RCTEventEmitter
=
context
.
getJSModule
(
RCTEventEmitter
::
class
.
java
)
fun
setCoordinates
(
coordinates
:
ReadableArray
)
{
this
.
coordinates
=
ArrayList
((
0
..
coordinates
.
size
()
-
1
)
.
map
{
coordinates
.
getMap
(
it
)
}
.
map
{
LatLng
(
it
.
getDouble
(
"latitude"
),
it
.
getDouble
(
"longitude"
))
})
polyline
?.
points
=
this
.
coordinates
}
fun
setColors
(
colors
:
ReadableArray
)
{
...
...
android/src/main/java/cn/qiuxiang/react/amap3d/AMapPolylineManager.kt
View file @
c181df86
...
...
@@ -31,36 +31,36 @@ internal class AMapPolylineManager : ViewGroupManager<AMapPolyline>() {
@ReactProp
(
name
=
"color"
,
customType
=
"Color"
)
fun
setColor
(
polyline
:
AMapPolyline
,
color
:
Int
)
{
polyline
.
setColor
(
color
)
polyline
.
color
=
color
}
@ReactProp
(
name
=
"width"
)
fun
setWidth
(
polyline
:
AMapPolyline
,
width
:
In
t
)
{
polyline
.
setWidth
(
width
.
toFloat
())
fun
setWidth
(
polyline
:
AMapPolyline
,
width
:
Floa
t
)
{
polyline
.
width
=
width
}
@ReactProp
(
name
=
"zIndex"
)
fun
setZIndex
(
polyline
:
AMapPolyline
,
zIndex
:
In
t
)
{
polyline
.
setZIndex
(
zIndex
.
toFloat
())
fun
setZIndex
_
(
polyline
:
AMapPolyline
,
zIndex
:
Floa
t
)
{
polyline
.
zIndex
=
zIndex
}
@ReactProp
(
name
=
"opacity"
)
override
fun
setOpacity
(
polyline
:
AMapPolyline
,
opacity
:
Float
)
{
polyline
.
setOpacity
(
opacity
)
polyline
.
opacity
=
opacity
}
@ReactProp
(
name
=
"geodesic"
)
fun
setGeodesic
(
polyline
:
AMapPolyline
,
geodesic
:
Boolean
)
{
polyline
.
setGeodesic
(
geodesic
)
polyline
.
geodesic
=
geodesic
}
@ReactProp
(
name
=
"dottedLine"
)
fun
setDottedLine
(
polyline
:
AMapPolyline
,
dottedLine
:
Boolean
)
{
polyline
.
setDottedLine
(
dottedLine
)
polyline
.
dottedLine
=
dottedLine
}
@ReactProp
(
name
=
"gradient"
)
fun
setGradient
(
polyline
:
AMapPolyline
,
gradient
:
Boolean
)
{
polyline
.
setGradient
(
gradient
)
polyline
.
gradient
=
gradient
}
}
android/src/main/java/cn/qiuxiang/react/amap3d/AMapView.kt
View file @
c181df86
...
...
@@ -89,7 +89,7 @@ class AMapView(context: ThemedReactContext) : MapView(context) {
fun
addPolyline
(
polyline
:
AMapPolyline
)
{
polyline
.
addToMap
(
map
)
polylines
.
put
(
polyline
.
polyline
I
d
!!
,
polyline
)
polylines
.
put
(
polyline
.
polyline
?.
i
d
!!
,
polyline
)
}
fun
sendEvent
(
name
:
String
,
data
:
WritableMap
)
{
...
...
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