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
7e497853
Commit
7e497853
authored
Apr 29, 2018
by
7c00
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化 kotlin 代码
parent
6eb2f429
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
73 additions
and
74 deletions
+73
-74
build.gradle
lib/android/build.gradle
+1
-1
AMapUtils.kt
...droid/src/main/java/cn/qiuxiang/react/amap3d/AMapUtils.kt
+36
-2
AMapCircleManager.kt
...n/java/cn/qiuxiang/react/amap3d/maps/AMapCircleManager.kt
+4
-6
AMapHeatMap.kt
...rc/main/java/cn/qiuxiang/react/amap3d/maps/AMapHeatMap.kt
+2
-3
AMapInfoWindowManager.kt
...va/cn/qiuxiang/react/amap3d/maps/AMapInfoWindowManager.kt
+0
-6
AMapMarker.kt
...src/main/java/cn/qiuxiang/react/amap3d/maps/AMapMarker.kt
+2
-2
AMapMarkerManager.kt
...n/java/cn/qiuxiang/react/amap3d/maps/AMapMarkerManager.kt
+4
-7
AMapMultiPoint.kt
...main/java/cn/qiuxiang/react/amap3d/maps/AMapMultiPoint.kt
+2
-3
AMapPolygon.kt
...rc/main/java/cn/qiuxiang/react/amap3d/maps/AMapPolygon.kt
+2
-4
AMapPolygonManager.kt
.../java/cn/qiuxiang/react/amap3d/maps/AMapPolygonManager.kt
+1
-1
AMapPolyline.kt
...c/main/java/cn/qiuxiang/react/amap3d/maps/AMapPolyline.kt
+2
-4
AMapPolylineManager.kt
...java/cn/qiuxiang/react/amap3d/maps/AMapPolylineManager.kt
+1
-1
AMapView.kt
...d/src/main/java/cn/qiuxiang/react/amap3d/maps/AMapView.kt
+16
-34
No files found.
lib/android/build.gradle
View file @
7e497853
...
...
@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
apply
plugin:
'kotlin-android'
buildscript
{
ext
.
kotlin_version
=
'1.2.
2
1'
ext
.
kotlin_version
=
'1.2.
4
1'
repositories
{
jcenter
()
...
...
lib/android/src/main/java/cn/qiuxiang/react/amap3d/AMapUtils.kt
View file @
7e497853
package
cn.qiuxiang.react.amap3d
import
android.content.res.Resources
import
com.amap.api.maps.model.LatLng
import
com.amap.api.maps.model.LatLngBounds
import
com.facebook.react.bridge.Arguments
import
com.facebook.react.bridge.ReadableArray
import
com.facebook.react.bridge.ReadableMap
import
com.facebook.react.bridge.WritableMap
val
Float
.
toPx
:
Int
get
()
=
(
this
*
Resources
.
getSystem
().
displayMetrics
.
density
).
toInt
()
fun
Float
.
toPx
():
Int
{
return
(
this
*
Resources
.
getSystem
().
displayMetrics
.
density
).
toInt
()
}
fun
ReadableMap
.
toLatLng
():
LatLng
{
return
LatLng
(
this
.
getDouble
(
"latitude"
),
this
.
getDouble
(
"longitude"
))
}
fun
ReadableArray
.
toLatLngList
():
ArrayList
<
LatLng
>
{
return
ArrayList
((
0
..
(
this
.
size
()
-
1
)).
map
{
this
.
getMap
(
it
).
toLatLng
()
})
}
fun
LatLng
.
toWritableMap
():
WritableMap
{
val
map
=
Arguments
.
createMap
()
map
.
putDouble
(
"latitude"
,
this
.
latitude
)
map
.
putDouble
(
"longitude"
,
this
.
longitude
)
return
map
}
fun
ReadableMap
.
toLatLngBounds
():
LatLngBounds
{
val
latitude
=
this
.
getDouble
(
"latitude"
)
val
longitude
=
this
.
getDouble
(
"longitude"
)
val
latitudeDelta
=
this
.
getDouble
(
"latitudeDelta"
)
val
longitudeDelta
=
this
.
getDouble
(
"longitudeDelta"
)
return
LatLngBounds
(
LatLng
(
latitude
-
latitudeDelta
/
2
,
longitude
-
longitudeDelta
/
2
),
LatLng
(
latitude
+
latitudeDelta
/
2
,
longitude
+
longitudeDelta
/
2
)
)
}
\ No newline at end of file
lib/android/src/main/java/cn/qiuxiang/react/amap3d/maps/AMapCircleManager.kt
View file @
7e497853
package
cn.qiuxiang.react.amap3d.maps
import
cn.qiuxiang.react.amap3d.toLatLng
import
cn.qiuxiang.react.amap3d.toPx
import
com.amap.api.maps.model.LatLng
import
com.facebook.react.bridge.ReadableMap
import
com.facebook.react.uimanager.SimpleViewManager
import
com.facebook.react.uimanager.ThemedReactContext
...
...
@@ -19,9 +19,7 @@ internal class AMapCircleManager : SimpleViewManager<AMapCircle>() {
@ReactProp
(
name
=
"coordinate"
)
fun
setCoordinate
(
circle
:
AMapCircle
,
coordinate
:
ReadableMap
)
{
circle
.
center
=
LatLng
(
coordinate
.
getDouble
(
"latitude"
),
coordinate
.
getDouble
(
"longitude"
))
circle
.
center
=
coordinate
.
toLatLng
()
}
@ReactProp
(
name
=
"radius"
)
...
...
@@ -41,11 +39,11 @@ internal class AMapCircleManager : SimpleViewManager<AMapCircle>() {
@ReactProp
(
name
=
"strokeWidth"
)
fun
setStrokeWidth
(
circle
:
AMapCircle
,
strokeWidth
:
Float
)
{
circle
.
strokeWidth
=
strokeWidth
.
toPx
.
toFloat
()
circle
.
strokeWidth
=
strokeWidth
.
toPx
()
.
toFloat
()
}
@ReactProp
(
name
=
"zIndex"
)
fun
setZInde
x_
(
circle
:
AMapCircle
,
zIndex
:
Float
)
{
fun
setZInde
z
(
circle
:
AMapCircle
,
zIndex
:
Float
)
{
circle
.
zIndex
=
zIndex
}
}
lib/android/src/main/java/cn/qiuxiang/react/amap3d/maps/AMapHeatMap.kt
View file @
7e497853
package
cn.qiuxiang.react.amap3d.maps
import
android.content.Context
import
cn.qiuxiang.react.amap3d.toLatLngList
import
com.amap.api.maps.AMap
import
com.amap.api.maps.model.HeatmapTileProvider
import
com.amap.api.maps.model.LatLng
...
...
@@ -17,9 +18,7 @@ class AMapHeatMap(context: Context) : ReactViewGroup(context), AMapOverlay {
var
radius
:
Int
=
12
fun
setCoordinates
(
coordinates
:
ReadableArray
)
{
this
.
coordinates
=
ArrayList
((
0
until
coordinates
.
size
())
.
map
{
coordinates
.
getMap
(
it
)
}
.
map
{
LatLng
(
it
.
getDouble
(
"latitude"
),
it
.
getDouble
(
"longitude"
))
})
this
.
coordinates
=
coordinates
.
toLatLngList
()
}
override
fun
add
(
map
:
AMap
)
{
...
...
lib/android/src/main/java/cn/qiuxiang/react/amap3d/maps/AMapInfoWindowManager.kt
View file @
7e497853
package
cn.qiuxiang.react.amap3d.maps
import
com.facebook.react.uimanager.LayoutShadowNode
import
com.facebook.react.uimanager.ThemedReactContext
import
com.facebook.react.uimanager.ViewGroupManager
...
...
@@ -12,8 +11,4 @@ class AMapInfoWindowManager : ViewGroupManager<AMapInfoWindow>() {
override
fun
createViewInstance
(
reactContext
:
ThemedReactContext
):
AMapInfoWindow
{
return
AMapInfoWindow
(
reactContext
)
}
override
fun
createShadowNodeInstance
():
LayoutShadowNode
{
return
super
.
createShadowNodeInstance
()
}
}
\ No newline at end of file
lib/android/src/main/java/cn/qiuxiang/react/amap3d/maps/AMapMarker.kt
View file @
7e497853
...
...
@@ -159,8 +159,8 @@ class AMapMarker(context: Context) : ReactViewGroup(context), AMapOverlay {
fun
lockToScreen
(
args
:
ReadableArray
?)
{
if
(
args
!=
null
)
{
val
x
=
args
.
getDouble
(
0
).
toFloat
().
toPx
val
y
=
args
.
getDouble
(
1
).
toFloat
().
toPx
val
x
=
args
.
getDouble
(
0
).
toFloat
().
toPx
()
val
y
=
args
.
getDouble
(
1
).
toFloat
().
toPx
()
marker
?.
setPositionByPixels
(
x
,
y
)
}
}
...
...
lib/android/src/main/java/cn/qiuxiang/react/amap3d/maps/AMapMarkerManager.kt
View file @
7e497853
package
cn.qiuxiang.react.amap3d.maps
import
android.view.View
import
cn.qiuxiang.react.amap3d.toLatLng
import
com.amap.api.maps.model.LatLng
import
com.facebook.react.bridge.ReadableArray
import
com.facebook.react.bridge.ReadableMap
...
...
@@ -70,9 +71,7 @@ internal class AMapMarkerManager : ViewGroupManager<AMapMarker>() {
@ReactProp
(
name
=
"coordinate"
)
fun
setCoordinate
(
view
:
AMapMarker
,
coordinate
:
ReadableMap
)
{
view
.
position
=
LatLng
(
coordinate
.
getDouble
(
"latitude"
),
coordinate
.
getDouble
(
"longitude"
))
view
.
position
=
coordinate
.
toLatLng
()
}
@ReactProp
(
name
=
"flat"
)
...
...
@@ -116,14 +115,12 @@ internal class AMapMarkerManager : ViewGroupManager<AMapMarker>() {
}
@ReactProp
(
name
=
"zIndex"
)
fun
setZIn
ex
(
marker
:
AMapMarker
,
zIndex
:
Float
)
{
fun
setZIn
dez
(
marker
:
AMapMarker
,
zIndex
:
Float
)
{
marker
.
zIndex
=
zIndex
}
@ReactProp
(
name
=
"anchor"
)
fun
setAnchor
(
view
:
AMapMarker
,
coordinate
:
ReadableMap
)
{
view
.
setAnchor
(
coordinate
.
getDouble
(
"x"
),
coordinate
.
getDouble
(
"y"
))
view
.
setAnchor
(
coordinate
.
getDouble
(
"x"
),
coordinate
.
getDouble
(
"y"
))
}
}
lib/android/src/main/java/cn/qiuxiang/react/amap3d/maps/AMapMultiPoint.kt
View file @
7e497853
package
cn.qiuxiang.react.amap3d.maps
import
android.content.Context
import
cn.qiuxiang.react.amap3d.toLatLng
import
com.amap.api.maps.AMap
import
com.amap.api.maps.model.*
import
com.facebook.react.bridge.ReadableArray
...
...
@@ -15,9 +16,7 @@ class AMapMultiPoint(context: Context) : ReactViewGroup(context), AMapOverlay {
items
=
ArrayList
((
0
until
points
.
size
())
.
map
{
val
data
=
points
.
getMap
(
it
)
val
item
=
MultiPointItem
(
LatLng
(
data
.
getDouble
(
"latitude"
),
data
.
getDouble
(
"longitude"
)))
val
item
=
MultiPointItem
(
data
.
toLatLng
())
if
(
data
.
hasKey
(
"title"
))
{
item
.
title
=
data
.
getString
(
"title"
)
}
...
...
lib/android/src/main/java/cn/qiuxiang/react/amap3d/maps/AMapPolygon.kt
View file @
7e497853
...
...
@@ -2,6 +2,7 @@ package cn.qiuxiang.react.amap3d.maps
import
android.content.Context
import
android.graphics.Color
import
cn.qiuxiang.react.amap3d.toLatLngList
import
com.amap.api.maps.AMap
import
com.amap.api.maps.model.LatLng
import
com.amap.api.maps.model.Polygon
...
...
@@ -38,10 +39,7 @@ class AMapPolygon(context: Context) : ReactViewGroup(context), AMapOverlay {
}
fun
setCoordinates
(
coordinates
:
ReadableArray
)
{
this
.
coordinates
=
ArrayList
((
0
until
coordinates
.
size
())
.
map
{
coordinates
.
getMap
(
it
)
}
.
map
{
LatLng
(
it
.
getDouble
(
"latitude"
),
it
.
getDouble
(
"longitude"
))
})
this
.
coordinates
=
coordinates
.
toLatLngList
()
polygon
?.
points
=
this
.
coordinates
}
...
...
lib/android/src/main/java/cn/qiuxiang/react/amap3d/maps/AMapPolygonManager.kt
View file @
7e497853
...
...
@@ -33,7 +33,7 @@ internal class AMapPolygonManager : SimpleViewManager<AMapPolygon>() {
@ReactProp
(
name
=
"strokeWidth"
)
fun
setStrokeWidth
(
polygon
:
AMapPolygon
,
strokeWidth
:
Float
)
{
polygon
.
strokeWidth
=
strokeWidth
.
toPx
.
toFloat
()
polygon
.
strokeWidth
=
strokeWidth
.
toPx
()
.
toFloat
()
}
@ReactProp
(
name
=
"zIndex"
)
...
...
lib/android/src/main/java/cn/qiuxiang/react/amap3d/maps/AMapPolyline.kt
View file @
7e497853
...
...
@@ -2,6 +2,7 @@ package cn.qiuxiang.react.amap3d.maps
import
android.content.Context
import
android.graphics.Color
import
cn.qiuxiang.react.amap3d.toLatLngList
import
com.amap.api.maps.AMap
import
com.amap.api.maps.model.LatLng
import
com.amap.api.maps.model.Polyline
...
...
@@ -49,10 +50,7 @@ class AMapPolyline(context: Context) : ReactViewGroup(context), AMapOverlay {
var
gradient
:
Boolean
=
false
fun
setCoordinates
(
coordinates
:
ReadableArray
)
{
this
.
coordinates
=
ArrayList
((
0
until
coordinates
.
size
())
.
map
{
coordinates
.
getMap
(
it
)
}
.
map
{
LatLng
(
it
.
getDouble
(
"latitude"
),
it
.
getDouble
(
"longitude"
))
})
this
.
coordinates
=
coordinates
.
toLatLngList
()
polyline
?.
points
=
this
.
coordinates
}
...
...
lib/android/src/main/java/cn/qiuxiang/react/amap3d/maps/AMapPolylineManager.kt
View file @
7e497853
...
...
@@ -37,7 +37,7 @@ internal class AMapPolylineManager : SimpleViewManager<AMapPolyline>() {
@ReactProp
(
name
=
"width"
)
fun
setWidth
(
polyline
:
AMapPolyline
,
width
:
Float
)
{
polyline
.
width
=
width
.
toPx
.
toFloat
()
polyline
.
width
=
width
.
toPx
()
.
toFloat
()
}
@ReactProp
(
name
=
"zIndex"
)
...
...
lib/android/src/main/java/cn/qiuxiang/react/amap3d/maps/AMapView.kt
View file @
7e497853
...
...
@@ -2,10 +2,16 @@ package cn.qiuxiang.react.amap3d.maps
import
android.content.Context
import
android.view.View
import
cn.qiuxiang.react.amap3d.toLatLng
import
cn.qiuxiang.react.amap3d.toLatLngBounds
import
cn.qiuxiang.react.amap3d.toWritableMap
import
com.amap.api.maps.AMap
import
com.amap.api.maps.CameraUpdateFactory
import
com.amap.api.maps.TextureMapView
import
com.amap.api.maps.model.*
import
com.amap.api.maps.model.BitmapDescriptorFactory
import
com.amap.api.maps.model.CameraPosition
import
com.amap.api.maps.model.Marker
import
com.amap.api.maps.model.MyLocationStyle
import
com.facebook.react.bridge.Arguments
import
com.facebook.react.bridge.ReadableArray
import
com.facebook.react.bridge.ReadableMap
...
...
@@ -31,17 +37,11 @@ class AMapView(context: Context) : TextureMapView(context) {
marker
.
active
=
false
}
val
event
=
Arguments
.
createMap
()
event
.
putDouble
(
"latitude"
,
latLng
.
latitude
)
event
.
putDouble
(
"longitude"
,
latLng
.
longitude
)
emit
(
id
,
"onPress"
,
event
)
emit
(
id
,
"onPress"
,
latLng
.
toWritableMap
())
}
map
.
setOnMapLongClickListener
{
latLng
->
val
event
=
Arguments
.
createMap
()
event
.
putDouble
(
"latitude"
,
latLng
.
latitude
)
event
.
putDouble
(
"longitude"
,
latLng
.
longitude
)
emit
(
id
,
"onLongPress"
,
event
)
emit
(
id
,
"onLongPress"
,
latLng
.
toWritableMap
())
}
map
.
setOnMyLocationChangeListener
{
location
->
...
...
@@ -73,11 +73,7 @@ class AMapView(context: Context) : TextureMapView(context) {
}
override
fun
onMarkerDragEnd
(
marker
:
Marker
)
{
val
position
=
marker
.
position
val
data
=
Arguments
.
createMap
()
data
.
putDouble
(
"latitude"
,
position
.
latitude
)
data
.
putDouble
(
"longitude"
,
position
.
longitude
)
emit
(
markers
[
marker
.
id
]
?.
id
,
"onDragEnd"
,
data
)
emit
(
markers
[
marker
.
id
]
?.
id
,
"onDragEnd"
,
marker
.
position
.
toWritableMap
())
}
})
...
...
@@ -112,12 +108,10 @@ class AMapView(context: Context) : TextureMapView(context) {
fun
emitCameraChangeEvent
(
event
:
String
,
position
:
CameraPosition
?)
{
position
?.
let
{
val
data
=
Arguments
.
creat
eMap
()
val
data
=
it
.
target
.
toWritabl
eMap
()
data
.
putDouble
(
"zoomLevel"
,
it
.
zoom
.
toDouble
())
data
.
putDouble
(
"tilt"
,
it
.
tilt
.
toDouble
())
data
.
putDouble
(
"rotation"
,
it
.
bearing
.
toDouble
())
data
.
putDouble
(
"latitude"
,
it
.
target
.
latitude
)
data
.
putDouble
(
"longitude"
,
it
.
target
.
longitude
)
if
(
event
==
"onStatusChangeComplete"
)
{
val
southwest
=
map
.
projection
.
visibleRegion
.
latLngBounds
.
southwest
val
northeast
=
map
.
projection
.
visibleRegion
.
latLngBounds
.
northeast
...
...
@@ -136,10 +130,10 @@ class AMapView(context: Context) : TextureMapView(context) {
if
(
child
is
AMapOverlay
)
{
child
.
add
(
map
)
if
(
child
is
AMapMarker
)
{
markers
.
put
(
child
.
marker
?.
id
!!
,
child
)
markers
[
child
.
marker
?.
id
!!
]
=
child
}
if
(
child
is
AMapPolyline
)
{
lines
.
put
(
child
.
polyline
?.
id
!!
,
child
)
lines
[
child
.
polyline
?.
id
!!
]
=
child
}
}
}
...
...
@@ -177,8 +171,7 @@ class AMapView(context: Context) : TextureMapView(context) {
var
rotation
=
currentCameraPosition
.
bearing
if
(
target
.
hasKey
(
"coordinate"
))
{
val
json
=
target
.
getMap
(
"coordinate"
)
coordinate
=
LatLng
(
json
.
getDouble
(
"latitude"
),
json
.
getDouble
(
"longitude"
))
coordinate
=
target
.
getMap
(
"coordinate"
).
toLatLng
()
}
if
(
target
.
hasKey
(
"zoomLevel"
))
{
...
...
@@ -199,11 +192,11 @@ class AMapView(context: Context) : TextureMapView(context) {
}
fun
setRegion
(
region
:
ReadableMap
)
{
map
.
moveCamera
(
CameraUpdateFactory
.
newLatLngBounds
(
latLngBoundsFromReadableMap
(
region
),
0
))
map
.
moveCamera
(
CameraUpdateFactory
.
newLatLngBounds
(
region
.
toLatLngBounds
(
),
0
))
}
fun
setLimitRegion
(
region
:
ReadableMap
)
{
map
.
setMapStatusLimits
(
latLngBoundsFromReadableMap
(
region
))
map
.
setMapStatusLimits
(
region
.
toLatLngBounds
(
))
}
fun
setLocationEnabled
(
enabled
:
Boolean
)
{
...
...
@@ -215,17 +208,6 @@ class AMapView(context: Context) : TextureMapView(context) {
locationStyle
.
interval
(
interval
)
}
private
fun
latLngBoundsFromReadableMap
(
region
:
ReadableMap
):
LatLngBounds
{
val
latitude
=
region
.
getDouble
(
"latitude"
)
val
longitude
=
region
.
getDouble
(
"longitude"
)
val
latitudeDelta
=
region
.
getDouble
(
"latitudeDelta"
)
val
longitudeDelta
=
region
.
getDouble
(
"longitudeDelta"
)
return
LatLngBounds
(
LatLng
(
latitude
-
latitudeDelta
/
2
,
longitude
-
longitudeDelta
/
2
),
LatLng
(
latitude
+
latitudeDelta
/
2
,
longitude
+
longitudeDelta
/
2
)
)
}
fun
setLocationStyle
(
style
:
ReadableMap
)
{
if
(
style
.
hasKey
(
"fillColor"
))
{
locationStyle
.
radiusFillColor
(
style
.
getInt
(
"fillColor"
))
...
...
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