@evnydd0sf/react-native-amap3d-fix 3.2.4-fix.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/android/build.gradle +34 -0
- package/lib/android/src/main/AndroidManifest.xml +10 -0
- package/lib/android/src/main/java/qiuxiang/amap3d/AMap3DPackage.kt +28 -0
- package/lib/android/src/main/java/qiuxiang/amap3d/Utils.kt +114 -0
- package/lib/android/src/main/java/qiuxiang/amap3d/map_view/Circle.kt +65 -0
- package/lib/android/src/main/java/qiuxiang/amap3d/map_view/CircleManager.kt +49 -0
- package/lib/android/src/main/java/qiuxiang/amap3d/map_view/HeatMap.kt +32 -0
- package/lib/android/src/main/java/qiuxiang/amap3d/map_view/HeatMapManager.kt +33 -0
- package/lib/android/src/main/java/qiuxiang/amap3d/map_view/MapView.kt +174 -0
- package/lib/android/src/main/java/qiuxiang/amap3d/map_view/MapViewManager.kt +153 -0
- package/lib/android/src/main/java/qiuxiang/amap3d/map_view/Marker.kt +102 -0
- package/lib/android/src/main/java/qiuxiang/amap3d/map_view/MarkerManager.kt +78 -0
- package/lib/android/src/main/java/qiuxiang/amap3d/map_view/MultiPoint.kt +53 -0
- package/lib/android/src/main/java/qiuxiang/amap3d/map_view/MultiPointManager.kt +33 -0
- package/lib/android/src/main/java/qiuxiang/amap3d/map_view/Overlay.kt +8 -0
- package/lib/android/src/main/java/qiuxiang/amap3d/map_view/Polygon.kt +58 -0
- package/lib/android/src/main/java/qiuxiang/amap3d/map_view/PolygonManager.kt +44 -0
- package/lib/android/src/main/java/qiuxiang/amap3d/map_view/Polyline.kt +69 -0
- package/lib/android/src/main/java/qiuxiang/amap3d/map_view/PolylineManager.kt +64 -0
- package/lib/android/src/main/java/qiuxiang/amap3d/modules/SdkModule.kt +31 -0
- package/lib/ios/.swiftformat +2 -0
- package/lib/ios/Bridging-Header.h +4 -0
- package/lib/ios/MapView/CircleManager.m +11 -0
- package/lib/ios/MapView/CircleManager.swift +30 -0
- package/lib/ios/MapView/HeatMapManager.m +9 -0
- package/lib/ios/MapView/HeatMapManager.swift +29 -0
- package/lib/ios/MapView/MapViewManager.m +35 -0
- package/lib/ios/MapView/MapViewManager.swift +159 -0
- package/lib/ios/MapView/MarkerManager.m +18 -0
- package/lib/ios/MapView/MarkerManager.swift +100 -0
- package/lib/ios/MapView/MultiPointManager.m +9 -0
- package/lib/ios/MapView/MultiPointManager.swift +47 -0
- package/lib/ios/MapView/Overlay.swift +4 -0
- package/lib/ios/MapView/PolygonManager.m +10 -0
- package/lib/ios/MapView/PolygonManager.swift +30 -0
- package/lib/ios/MapView/PolylineManager.m +12 -0
- package/lib/ios/MapView/PolylineManager.swift +41 -0
- package/lib/ios/Modules/SdkModule.m +8 -0
- package/lib/ios/Modules/SdkModule.swift +16 -0
- package/lib/ios/Utils.swift +104 -0
- package/lib/ios/react-native-amap3d.podspec +20 -0
- package/lib/src/circle.tsx +36 -0
- package/lib/src/cluster/cluster-view.tsx +47 -0
- package/lib/src/cluster/index.tsx +159 -0
- package/lib/src/component.ts +31 -0
- package/lib/src/heat-map.tsx +21 -0
- package/lib/src/index.ts +11 -0
- package/lib/src/map-view.tsx +230 -0
- package/lib/src/marker.tsx +128 -0
- package/lib/src/multi-point.tsx +28 -0
- package/lib/src/polygon.tsx +31 -0
- package/lib/src/polyline.tsx +65 -0
- package/lib/src/sdk.ts +11 -0
- package/lib/src/types.ts +137 -0
- package/license +21 -0
- package/package.json +56 -0
- package/react-native-amap3d.podspec +20 -0
- package/react-native.config.js +20 -0
- package/readme.md +186 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
apply plugin: 'com.android.library'
|
2
|
+
apply plugin: 'kotlin-android'
|
3
|
+
|
4
|
+
def getExt(prop, fallback) {
|
5
|
+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
6
|
+
}
|
7
|
+
|
8
|
+
buildscript {
|
9
|
+
ext.kotlin_version = '1.7.21'
|
10
|
+
|
11
|
+
repositories {
|
12
|
+
mavenCentral()
|
13
|
+
}
|
14
|
+
|
15
|
+
dependencies {
|
16
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
android {
|
21
|
+
compileSdkVersion getExt('compileSdkVersion', 33)
|
22
|
+
buildToolsVersion getExt('buildToolsVersion', '33.0.0')
|
23
|
+
|
24
|
+
defaultConfig {
|
25
|
+
minSdkVersion getExt('minSdkVersion', 21)
|
26
|
+
targetSdkVersion getExt('targetSdkVersion', 33)
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
dependencies {
|
31
|
+
compileOnly 'com.facebook.react:react-native:+'
|
32
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
33
|
+
implementation 'com.amap.api:3dmap:9.6.0'
|
34
|
+
}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
2
|
+
package="qiuxiang.amap3d">
|
3
|
+
|
4
|
+
<uses-permission android:name="android.permission.INTERNET" />
|
5
|
+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
6
|
+
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
7
|
+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
8
|
+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
9
|
+
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
|
10
|
+
</manifest>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
package qiuxiang.amap3d
|
2
|
+
|
3
|
+
import com.facebook.react.ReactPackage
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
6
|
+
import com.facebook.react.uimanager.ViewManager
|
7
|
+
import qiuxiang.amap3d.map_view.*
|
8
|
+
import qiuxiang.amap3d.modules.SdkModule
|
9
|
+
|
10
|
+
class AMap3DPackage : ReactPackage {
|
11
|
+
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
|
12
|
+
return listOf(
|
13
|
+
SdkModule(reactContext),
|
14
|
+
)
|
15
|
+
}
|
16
|
+
|
17
|
+
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
18
|
+
return listOf(
|
19
|
+
MapViewManager(),
|
20
|
+
MarkerManager(),
|
21
|
+
PolylineManager(),
|
22
|
+
PolygonManager(),
|
23
|
+
CircleManager(),
|
24
|
+
HeatMapManager(),
|
25
|
+
MultiPointManager()
|
26
|
+
)
|
27
|
+
}
|
28
|
+
}
|
@@ -0,0 +1,114 @@
|
|
1
|
+
package qiuxiang.amap3d
|
2
|
+
|
3
|
+
import android.content.res.Resources
|
4
|
+
import android.graphics.Bitmap
|
5
|
+
import android.graphics.Point
|
6
|
+
import android.location.Location
|
7
|
+
import android.view.View
|
8
|
+
import com.amap.api.maps.model.*
|
9
|
+
import com.facebook.drawee.backends.pipeline.Fresco
|
10
|
+
import com.facebook.imagepipeline.common.ResizeOptions
|
11
|
+
import com.facebook.imagepipeline.request.BasePostprocessor
|
12
|
+
import com.facebook.imagepipeline.request.ImageRequestBuilder
|
13
|
+
import com.facebook.react.bridge.Arguments
|
14
|
+
import com.facebook.react.bridge.ReadableArray
|
15
|
+
import com.facebook.react.bridge.ReadableMap
|
16
|
+
import com.facebook.react.bridge.WritableMap
|
17
|
+
import com.facebook.react.views.imagehelper.ImageSource
|
18
|
+
|
19
|
+
fun Float.toPx(): Int {
|
20
|
+
return (this * Resources.getSystem().displayMetrics.density).toInt()
|
21
|
+
}
|
22
|
+
|
23
|
+
fun Int.toPx(): Int {
|
24
|
+
return (this * Resources.getSystem().displayMetrics.density).toInt()
|
25
|
+
}
|
26
|
+
|
27
|
+
fun ReadableMap.toPoint(): Point {
|
28
|
+
return Point(getDouble("x").toFloat().toPx(), getDouble("y").toFloat().toPx())
|
29
|
+
}
|
30
|
+
|
31
|
+
fun ReadableMap.toLatLng(): LatLng {
|
32
|
+
return LatLng(getDouble("latitude"), getDouble("longitude"))
|
33
|
+
}
|
34
|
+
|
35
|
+
fun ReadableArray.toLatLngList(): List<LatLng> {
|
36
|
+
return (0 until size()).map {
|
37
|
+
// @todo 暂时兼容 0.63
|
38
|
+
@Suppress("UNNECESSARY_NOT_NULL_ASSERTION")
|
39
|
+
getMap(it)!!.toLatLng()
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
fun LatLng.toJson(): WritableMap {
|
44
|
+
return Arguments.createMap().apply {
|
45
|
+
putDouble("latitude", latitude)
|
46
|
+
putDouble("longitude", longitude)
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
fun Poi.toJson(): WritableMap {
|
51
|
+
return Arguments.createMap().apply {
|
52
|
+
putMap("position", coordinate.toJson())
|
53
|
+
putString("id", poiId)
|
54
|
+
putString("name", name)
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
fun CameraPosition.toJson(): WritableMap {
|
59
|
+
return Arguments.createMap().apply {
|
60
|
+
putMap("target", target.toJson())
|
61
|
+
putDouble("zoom", zoom.toDouble())
|
62
|
+
putDouble("tilt", tilt.toDouble())
|
63
|
+
putDouble("bearing", bearing.toDouble())
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
fun Location.toJson(): WritableMap {
|
68
|
+
return Arguments.createMap().apply {
|
69
|
+
putDouble("timestamp", time.toDouble())
|
70
|
+
putMap("coords", Arguments.createMap().apply {
|
71
|
+
putDouble("latitude", latitude)
|
72
|
+
putDouble("longitude", longitude)
|
73
|
+
putDouble("latitude", latitude)
|
74
|
+
putDouble("accuracy", accuracy.toDouble())
|
75
|
+
putDouble("heading", bearing.toDouble())
|
76
|
+
putDouble("speed", speed.toDouble())
|
77
|
+
})
|
78
|
+
}
|
79
|
+
}
|
80
|
+
|
81
|
+
fun LatLngBounds.toJson(): WritableMap {
|
82
|
+
return Arguments.createMap().apply {
|
83
|
+
putMap("southwest", southwest.toJson())
|
84
|
+
putMap("northeast", northeast.toJson())
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
fun ReadableMap.getFloat(key: String): Float? {
|
89
|
+
if (hasKey(key)) return getDouble(key).toFloat()
|
90
|
+
return null
|
91
|
+
}
|
92
|
+
|
93
|
+
fun getEventTypeConstants(vararg list: String): Map<String, Any> {
|
94
|
+
return list.associateWith { mapOf("phasedRegistrationNames" to mapOf("bubbled" to it)) }
|
95
|
+
}
|
96
|
+
|
97
|
+
fun View.fetchImage(source: ReadableMap, callback: (BitmapDescriptor) -> Unit) {
|
98
|
+
val uri = ImageSource(context, source.getString("uri")).uri
|
99
|
+
val request = ImageRequestBuilder.newBuilderWithSource(uri).let {
|
100
|
+
it.postprocessor = object : BasePostprocessor() {
|
101
|
+
override fun process(bitmap: Bitmap) {
|
102
|
+
callback(BitmapDescriptorFactory.fromBitmap(bitmap))
|
103
|
+
}
|
104
|
+
}
|
105
|
+
if (source.hasKey("width") && source.hasKey("height")) {
|
106
|
+
it.resizeOptions = ResizeOptions.forDimensions(
|
107
|
+
source.getInt("width").toPx(),
|
108
|
+
source.getInt("height").toPx()
|
109
|
+
)
|
110
|
+
}
|
111
|
+
it.build()
|
112
|
+
}
|
113
|
+
Fresco.getImagePipeline().fetchDecodedImage(request, this)
|
114
|
+
}
|
@@ -0,0 +1,65 @@
|
|
1
|
+
package qiuxiang.amap3d.map_view
|
2
|
+
|
3
|
+
import android.content.Context
|
4
|
+
import android.graphics.Color
|
5
|
+
import com.amap.api.maps.AMap
|
6
|
+
import com.amap.api.maps.model.Circle
|
7
|
+
import com.amap.api.maps.model.CircleOptions
|
8
|
+
import com.amap.api.maps.model.LatLng
|
9
|
+
import com.facebook.react.views.view.ReactViewGroup
|
10
|
+
|
11
|
+
class Circle(context: Context) : ReactViewGroup(context), Overlay {
|
12
|
+
private var circle: Circle? = null
|
13
|
+
|
14
|
+
var center: LatLng? = null
|
15
|
+
set(value) {
|
16
|
+
field = value
|
17
|
+
circle?.center = value
|
18
|
+
}
|
19
|
+
|
20
|
+
var radius: Double = 0.0
|
21
|
+
set(value) {
|
22
|
+
field = value
|
23
|
+
circle?.radius = value
|
24
|
+
}
|
25
|
+
|
26
|
+
var strokeWidth: Float = 1f
|
27
|
+
set(value) {
|
28
|
+
field = value
|
29
|
+
circle?.strokeWidth = value
|
30
|
+
}
|
31
|
+
|
32
|
+
var strokeColor: Int = Color.BLACK
|
33
|
+
set(value) {
|
34
|
+
field = value
|
35
|
+
circle?.strokeColor = value
|
36
|
+
}
|
37
|
+
|
38
|
+
var fillColor: Int = Color.BLACK
|
39
|
+
set(value) {
|
40
|
+
field = value
|
41
|
+
circle?.fillColor = value
|
42
|
+
}
|
43
|
+
|
44
|
+
var zIndex: Float = 0f
|
45
|
+
set(value) {
|
46
|
+
field = value
|
47
|
+
circle?.zIndex = value
|
48
|
+
}
|
49
|
+
|
50
|
+
override fun add(map: AMap) {
|
51
|
+
circle = map.addCircle(
|
52
|
+
CircleOptions()
|
53
|
+
.center(center)
|
54
|
+
.radius(radius)
|
55
|
+
.strokeColor(strokeColor)
|
56
|
+
.strokeWidth(strokeWidth)
|
57
|
+
.fillColor(fillColor)
|
58
|
+
.zIndex(zIndex)
|
59
|
+
)
|
60
|
+
}
|
61
|
+
|
62
|
+
override fun remove() {
|
63
|
+
circle?.remove()
|
64
|
+
}
|
65
|
+
}
|
@@ -0,0 +1,49 @@
|
|
1
|
+
package qiuxiang.amap3d.map_view
|
2
|
+
|
3
|
+
import com.facebook.react.bridge.ReadableMap
|
4
|
+
import com.facebook.react.uimanager.SimpleViewManager
|
5
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
6
|
+
import com.facebook.react.uimanager.annotations.ReactProp
|
7
|
+
import qiuxiang.amap3d.toLatLng
|
8
|
+
import qiuxiang.amap3d.toPx
|
9
|
+
|
10
|
+
@Suppress("unused")
|
11
|
+
internal class CircleManager : SimpleViewManager<Circle>() {
|
12
|
+
override fun getName(): String {
|
13
|
+
return "AMapCircle"
|
14
|
+
}
|
15
|
+
|
16
|
+
override fun createViewInstance(reactContext: ThemedReactContext): Circle {
|
17
|
+
return Circle(reactContext)
|
18
|
+
}
|
19
|
+
|
20
|
+
@ReactProp(name = "center")
|
21
|
+
fun setCenter(circle: Circle, center: ReadableMap) {
|
22
|
+
circle.center = center.toLatLng()
|
23
|
+
}
|
24
|
+
|
25
|
+
@ReactProp(name = "radius")
|
26
|
+
fun setRadius(circle: Circle, radius: Double) {
|
27
|
+
circle.radius = radius
|
28
|
+
}
|
29
|
+
|
30
|
+
@ReactProp(name = "fillColor", customType = "Color")
|
31
|
+
fun setFillColor(circle: Circle, fillColor: Int) {
|
32
|
+
circle.fillColor = fillColor
|
33
|
+
}
|
34
|
+
|
35
|
+
@ReactProp(name = "strokeColor", customType = "Color")
|
36
|
+
fun setStrokeColor(circle: Circle, strokeColor: Int) {
|
37
|
+
circle.strokeColor = strokeColor
|
38
|
+
}
|
39
|
+
|
40
|
+
@ReactProp(name = "strokeWidth")
|
41
|
+
fun setStrokeWidth(circle: Circle, strokeWidth: Float) {
|
42
|
+
circle.strokeWidth = strokeWidth.toPx().toFloat()
|
43
|
+
}
|
44
|
+
|
45
|
+
@ReactProp(name = "zIndex")
|
46
|
+
fun setIndex(circle: Circle, zIndex: Float) {
|
47
|
+
circle.zIndex = zIndex
|
48
|
+
}
|
49
|
+
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
package qiuxiang.amap3d.map_view
|
2
|
+
|
3
|
+
import android.content.Context
|
4
|
+
import com.amap.api.maps.AMap
|
5
|
+
import com.amap.api.maps.model.HeatmapTileProvider
|
6
|
+
import com.amap.api.maps.model.LatLng
|
7
|
+
import com.amap.api.maps.model.TileOverlay
|
8
|
+
import com.amap.api.maps.model.TileOverlayOptions
|
9
|
+
import com.facebook.react.views.view.ReactViewGroup
|
10
|
+
|
11
|
+
class HeatMap(context: Context) : ReactViewGroup(context), Overlay {
|
12
|
+
private var overlay: TileOverlay? = null
|
13
|
+
var data: List<LatLng> = emptyList()
|
14
|
+
var opacity: Double = 0.6
|
15
|
+
var radius: Int = 12
|
16
|
+
|
17
|
+
override fun add(map: AMap) {
|
18
|
+
overlay = map.addTileOverlay(
|
19
|
+
TileOverlayOptions().tileProvider(
|
20
|
+
HeatmapTileProvider.Builder()
|
21
|
+
.data(data)
|
22
|
+
.radius(radius)
|
23
|
+
.transparency(opacity)
|
24
|
+
.build()
|
25
|
+
)
|
26
|
+
)
|
27
|
+
}
|
28
|
+
|
29
|
+
override fun remove() {
|
30
|
+
overlay?.remove()
|
31
|
+
}
|
32
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
package qiuxiang.amap3d.map_view
|
2
|
+
|
3
|
+
import com.facebook.react.bridge.ReadableArray
|
4
|
+
import com.facebook.react.uimanager.SimpleViewManager
|
5
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
6
|
+
import com.facebook.react.uimanager.annotations.ReactProp
|
7
|
+
import qiuxiang.amap3d.toLatLngList
|
8
|
+
|
9
|
+
@Suppress("unused")
|
10
|
+
internal class HeatMapManager : SimpleViewManager<HeatMap>() {
|
11
|
+
override fun getName(): String {
|
12
|
+
return "AMapHeatMap"
|
13
|
+
}
|
14
|
+
|
15
|
+
override fun createViewInstance(reactContext: ThemedReactContext): HeatMap {
|
16
|
+
return HeatMap(reactContext)
|
17
|
+
}
|
18
|
+
|
19
|
+
@ReactProp(name = "data")
|
20
|
+
fun setData(heatMap: HeatMap, data: ReadableArray) {
|
21
|
+
heatMap.data = data.toLatLngList()
|
22
|
+
}
|
23
|
+
|
24
|
+
@ReactProp(name = "radius")
|
25
|
+
fun setRadius(heatMap: HeatMap, radius: Int) {
|
26
|
+
heatMap.radius = radius
|
27
|
+
}
|
28
|
+
|
29
|
+
@ReactProp(name = "opacity")
|
30
|
+
fun setOpacity(heatMap: HeatMap, opacity: Double) {
|
31
|
+
heatMap.opacity = opacity
|
32
|
+
}
|
33
|
+
}
|
@@ -0,0 +1,174 @@
|
|
1
|
+
package qiuxiang.amap3d.map_view
|
2
|
+
|
3
|
+
import android.annotation.SuppressLint
|
4
|
+
import android.view.View
|
5
|
+
import com.amap.api.maps.AMap
|
6
|
+
import com.amap.api.maps.CameraUpdateFactory
|
7
|
+
import com.amap.api.maps.TextureMapView
|
8
|
+
import com.amap.api.maps.model.CameraPosition
|
9
|
+
import com.amap.api.maps.model.Marker
|
10
|
+
import com.amap.api.maps.model.MyLocationStyle
|
11
|
+
import com.facebook.react.bridge.Arguments
|
12
|
+
import com.facebook.react.bridge.ReadableArray
|
13
|
+
import com.facebook.react.bridge.ReadableMap
|
14
|
+
import com.facebook.react.bridge.WritableMap
|
15
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
16
|
+
import qiuxiang.amap3d.getFloat
|
17
|
+
import qiuxiang.amap3d.toJson
|
18
|
+
import qiuxiang.amap3d.toLatLng
|
19
|
+
import qiuxiang.amap3d.toPoint
|
20
|
+
|
21
|
+
@SuppressLint("ViewConstructor")
|
22
|
+
class MapView(context: ThemedReactContext) : TextureMapView(context) {
|
23
|
+
@Suppress("Deprecation")
|
24
|
+
private val eventEmitter =
|
25
|
+
context.getJSModule(com.facebook.react.uimanager.events.RCTEventEmitter::class.java)
|
26
|
+
private val markerMap = HashMap<String, qiuxiang.amap3d.map_view.Marker>()
|
27
|
+
private val polylineMap = HashMap<String, Polyline>()
|
28
|
+
private var initialCameraPosition: ReadableMap? = null
|
29
|
+
private var locationStyle: MyLocationStyle
|
30
|
+
|
31
|
+
init {
|
32
|
+
super.onCreate(null)
|
33
|
+
|
34
|
+
locationStyle = MyLocationStyle()
|
35
|
+
locationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER)
|
36
|
+
map.myLocationStyle = locationStyle
|
37
|
+
|
38
|
+
map.setOnMapLoadedListener { emit(id, "onLoad") }
|
39
|
+
map.setOnMapClickListener { latLng -> emit(id, "onPress", latLng.toJson()) }
|
40
|
+
map.setOnPOIClickListener { poi -> emit(id, "onPressPoi", poi.toJson()) }
|
41
|
+
map.setOnMapLongClickListener { latLng -> emit(id, "onLongPress", latLng.toJson()) }
|
42
|
+
map.setOnPolylineClickListener { polyline -> emit(polylineMap[polyline.id]?.id, "onPress") }
|
43
|
+
|
44
|
+
map.setOnMarkerClickListener { marker ->
|
45
|
+
markerMap[marker.id]?.let { emit(it.id, "onPress") }
|
46
|
+
true
|
47
|
+
}
|
48
|
+
|
49
|
+
map.setOnMarkerDragListener(object : AMap.OnMarkerDragListener {
|
50
|
+
override fun onMarkerDragStart(marker: Marker) {
|
51
|
+
emit(markerMap[marker.id]?.id, "onDragStart")
|
52
|
+
}
|
53
|
+
|
54
|
+
override fun onMarkerDrag(marker: Marker) {
|
55
|
+
emit(markerMap[marker.id]?.id, "onDrag")
|
56
|
+
}
|
57
|
+
|
58
|
+
override fun onMarkerDragEnd(marker: Marker) {
|
59
|
+
emit(markerMap[marker.id]?.id, "onDragEnd", marker.position.toJson())
|
60
|
+
}
|
61
|
+
})
|
62
|
+
|
63
|
+
map.setOnCameraChangeListener(object : AMap.OnCameraChangeListener {
|
64
|
+
override fun onCameraChangeFinish(position: CameraPosition) {
|
65
|
+
emit(id, "onCameraIdle", Arguments.createMap().apply {
|
66
|
+
putMap("cameraPosition", position.toJson())
|
67
|
+
putMap("latLngBounds", map.projection.visibleRegion.latLngBounds.toJson())
|
68
|
+
})
|
69
|
+
}
|
70
|
+
|
71
|
+
override fun onCameraChange(position: CameraPosition) {
|
72
|
+
emit(id, "onCameraMove", Arguments.createMap().apply {
|
73
|
+
putMap("cameraPosition", position.toJson())
|
74
|
+
putMap("latLngBounds", map.projection.visibleRegion.latLngBounds.toJson())
|
75
|
+
})
|
76
|
+
}
|
77
|
+
})
|
78
|
+
|
79
|
+
map.setOnMultiPointClickListener { item ->
|
80
|
+
item.customerId.split("_").let {
|
81
|
+
emit(
|
82
|
+
it[0].toInt(),
|
83
|
+
"onPress",
|
84
|
+
Arguments.createMap().apply { putInt("index", it[1].toInt()) },
|
85
|
+
)
|
86
|
+
}
|
87
|
+
false
|
88
|
+
}
|
89
|
+
|
90
|
+
map.setOnMyLocationChangeListener {
|
91
|
+
if (it.time > 0) {
|
92
|
+
emit(id, "onLocation", it.toJson())
|
93
|
+
}
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
fun emit(id: Int?, event: String, data: WritableMap = Arguments.createMap()) {
|
98
|
+
@Suppress("Deprecation")
|
99
|
+
id?.let { eventEmitter.receiveEvent(it, event, data) }
|
100
|
+
}
|
101
|
+
|
102
|
+
fun add(child: View) {
|
103
|
+
if (child is Overlay) {
|
104
|
+
child.add(map)
|
105
|
+
if (child is qiuxiang.amap3d.map_view.Marker) {
|
106
|
+
markerMap[child.marker?.id!!] = child
|
107
|
+
}
|
108
|
+
if (child is Polyline) {
|
109
|
+
polylineMap[child.polyline?.id!!] = child
|
110
|
+
}
|
111
|
+
}
|
112
|
+
}
|
113
|
+
|
114
|
+
fun remove(child: View) {
|
115
|
+
if (child is Overlay) {
|
116
|
+
child.remove()
|
117
|
+
if (child is qiuxiang.amap3d.map_view.Marker) {
|
118
|
+
markerMap.remove(child.marker?.id)
|
119
|
+
}
|
120
|
+
if (child is Polyline) {
|
121
|
+
polylineMap.remove(child.polyline?.id)
|
122
|
+
}
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
private val animateCallback = object : AMap.CancelableCallback {
|
127
|
+
override fun onCancel() {}
|
128
|
+
override fun onFinish() {}
|
129
|
+
}
|
130
|
+
|
131
|
+
fun moveCamera(args: ReadableArray?) {
|
132
|
+
val current = map.cameraPosition
|
133
|
+
val position = args?.getMap(0)!!
|
134
|
+
val target = position.getMap("target")?.toLatLng() ?: current.target
|
135
|
+
val zoom = position.getFloat("zoom") ?: current.zoom
|
136
|
+
val tilt = position.getFloat("tilt") ?: current.tilt
|
137
|
+
val bearing = position.getFloat("bearing") ?: current.bearing
|
138
|
+
val cameraUpdate = CameraUpdateFactory.newCameraPosition(
|
139
|
+
CameraPosition(target, zoom, tilt, bearing)
|
140
|
+
)
|
141
|
+
map.animateCamera(cameraUpdate, args.getInt(1).toLong(), animateCallback)
|
142
|
+
}
|
143
|
+
|
144
|
+
fun setInitialCameraPosition(position: ReadableMap) {
|
145
|
+
if (initialCameraPosition == null) {
|
146
|
+
initialCameraPosition = position
|
147
|
+
moveCamera(Arguments.createArray().apply {
|
148
|
+
pushMap(Arguments.createMap().apply { merge(position) })
|
149
|
+
pushInt(0)
|
150
|
+
})
|
151
|
+
}
|
152
|
+
}
|
153
|
+
|
154
|
+
fun call(args: ReadableArray?) {
|
155
|
+
val id = args?.getDouble(0)!!
|
156
|
+
when (args.getString(1)) {
|
157
|
+
"getLatLng" -> callback(
|
158
|
+
id,
|
159
|
+
// @todo 暂时兼容 0.63
|
160
|
+
@Suppress("UNNECESSARY_NOT_NULL_ASSERTION")
|
161
|
+
map.projection.fromScreenLocation(args.getMap(2)!!.toPoint()).toJson()
|
162
|
+
)
|
163
|
+
}
|
164
|
+
}
|
165
|
+
|
166
|
+
private fun callback(id: Double, data: Any) {
|
167
|
+
emit(this.id, "onCallback", Arguments.createMap().apply {
|
168
|
+
putDouble("id", id)
|
169
|
+
when (data) {
|
170
|
+
is WritableMap -> putMap("data", data)
|
171
|
+
}
|
172
|
+
})
|
173
|
+
}
|
174
|
+
}
|
@@ -0,0 +1,153 @@
|
|
1
|
+
package qiuxiang.amap3d.map_view
|
2
|
+
|
3
|
+
import android.view.View
|
4
|
+
import com.amap.api.maps.CameraUpdateFactory
|
5
|
+
import com.facebook.react.bridge.ReadableArray
|
6
|
+
import com.facebook.react.bridge.ReadableMap
|
7
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
8
|
+
import com.facebook.react.uimanager.ViewGroupManager
|
9
|
+
import com.facebook.react.uimanager.annotations.ReactProp
|
10
|
+
import qiuxiang.amap3d.getEventTypeConstants
|
11
|
+
import qiuxiang.amap3d.toLatLng
|
12
|
+
|
13
|
+
@Suppress("unused")
|
14
|
+
internal class MapViewManager : ViewGroupManager<MapView>() {
|
15
|
+
private val commands = mapOf(
|
16
|
+
"moveCamera" to { view: MapView, args: ReadableArray? -> view.moveCamera(args) },
|
17
|
+
"call" to { view: MapView, args: ReadableArray? -> view.call(args) },
|
18
|
+
)
|
19
|
+
|
20
|
+
override fun getName(): String {
|
21
|
+
return "AMapView"
|
22
|
+
}
|
23
|
+
|
24
|
+
override fun createViewInstance(reactContext: ThemedReactContext): MapView {
|
25
|
+
return MapView(reactContext)
|
26
|
+
}
|
27
|
+
|
28
|
+
override fun onDropViewInstance(view: MapView) {
|
29
|
+
super.onDropViewInstance(view)
|
30
|
+
view.onDestroy()
|
31
|
+
}
|
32
|
+
|
33
|
+
override fun getCommandsMap(): Map<String, Int> {
|
34
|
+
return commands.keys.mapIndexed { index, key -> key to index }.toMap()
|
35
|
+
}
|
36
|
+
|
37
|
+
override fun receiveCommand(view: MapView, command: Int, args: ReadableArray?) {
|
38
|
+
commands.values.toList()[command](view, args)
|
39
|
+
}
|
40
|
+
|
41
|
+
override fun addView(mapView: MapView, child: View, index: Int) {
|
42
|
+
mapView.add(child)
|
43
|
+
super.addView(mapView, child, index)
|
44
|
+
}
|
45
|
+
|
46
|
+
override fun removeViewAt(parent: MapView, index: Int) {
|
47
|
+
parent.remove(parent.getChildAt(index))
|
48
|
+
super.removeViewAt(parent, index)
|
49
|
+
}
|
50
|
+
|
51
|
+
override fun getExportedCustomBubblingEventTypeConstants(): Map<String, Any> {
|
52
|
+
return getEventTypeConstants(
|
53
|
+
"onLoad",
|
54
|
+
"onPress",
|
55
|
+
"onPressPoi",
|
56
|
+
"onLongPress",
|
57
|
+
"onCameraMove",
|
58
|
+
"onCameraIdle",
|
59
|
+
"onLocation",
|
60
|
+
"onCallback",
|
61
|
+
)
|
62
|
+
}
|
63
|
+
|
64
|
+
@ReactProp(name = "initialCameraPosition")
|
65
|
+
fun setInitialCameraPosition(view: MapView, position: ReadableMap) {
|
66
|
+
view.setInitialCameraPosition(position)
|
67
|
+
}
|
68
|
+
|
69
|
+
@ReactProp(name = "myLocationEnabled")
|
70
|
+
fun setMyLocationEnabled(view: MapView, enabled: Boolean) {
|
71
|
+
view.map.isMyLocationEnabled = enabled
|
72
|
+
}
|
73
|
+
|
74
|
+
@ReactProp(name = "indoorViewEnabled")
|
75
|
+
fun setIndoorViewEnabled(view: MapView, enabled: Boolean) {
|
76
|
+
view.map.showIndoorMap(enabled)
|
77
|
+
}
|
78
|
+
|
79
|
+
@ReactProp(name = "buildingsEnabled")
|
80
|
+
fun setBuildingsEnabled(view: MapView, enabled: Boolean) {
|
81
|
+
view.map.showBuildings(enabled)
|
82
|
+
}
|
83
|
+
|
84
|
+
@ReactProp(name = "compassEnabled")
|
85
|
+
fun setCompassEnabled(view: MapView, show: Boolean) {
|
86
|
+
view.map.uiSettings.isCompassEnabled = show
|
87
|
+
}
|
88
|
+
|
89
|
+
@ReactProp(name = "zoomControlsEnabled")
|
90
|
+
fun setZoomControlsEnabled(view: MapView, enabled: Boolean) {
|
91
|
+
view.map.uiSettings.isZoomControlsEnabled = enabled
|
92
|
+
}
|
93
|
+
|
94
|
+
@ReactProp(name = "scaleControlsEnabled")
|
95
|
+
fun setScaleControlsEnabled(view: MapView, enabled: Boolean) {
|
96
|
+
view.map.uiSettings.isScaleControlsEnabled = enabled
|
97
|
+
}
|
98
|
+
|
99
|
+
@ReactProp(name = "language")
|
100
|
+
fun setLanguage(view: MapView, language: String) {
|
101
|
+
view.map.setMapLanguage(language)
|
102
|
+
}
|
103
|
+
|
104
|
+
@ReactProp(name = "myLocationButtonEnabled")
|
105
|
+
fun setMyLocationButtonEnabled(view: MapView, enabled: Boolean) {
|
106
|
+
view.map.uiSettings.isMyLocationButtonEnabled = enabled
|
107
|
+
}
|
108
|
+
|
109
|
+
@ReactProp(name = "trafficEnabled")
|
110
|
+
fun setTrafficEnabled(view: MapView, enabled: Boolean) {
|
111
|
+
view.map.isTrafficEnabled = enabled
|
112
|
+
}
|
113
|
+
|
114
|
+
@ReactProp(name = "maxZoom")
|
115
|
+
fun setMaxZoom(view: MapView, zoomLevel: Float) {
|
116
|
+
view.map.maxZoomLevel = zoomLevel
|
117
|
+
}
|
118
|
+
|
119
|
+
@ReactProp(name = "minZoom")
|
120
|
+
fun setMinZoom(view: MapView, zoomLevel: Float) {
|
121
|
+
view.map.minZoomLevel = zoomLevel
|
122
|
+
}
|
123
|
+
|
124
|
+
@ReactProp(name = "mapType")
|
125
|
+
fun setMapType(view: MapView, mapType: Int) {
|
126
|
+
view.map.mapType = mapType + 1
|
127
|
+
}
|
128
|
+
|
129
|
+
@ReactProp(name = "zoomGesturesEnabled")
|
130
|
+
fun setZoomGesturesEnabled(view: MapView, enabled: Boolean) {
|
131
|
+
view.map.uiSettings.isZoomGesturesEnabled = enabled
|
132
|
+
}
|
133
|
+
|
134
|
+
@ReactProp(name = "scrollGesturesEnabled")
|
135
|
+
fun setScrollGesturesEnabled(view: MapView, enabled: Boolean) {
|
136
|
+
view.map.uiSettings.isScrollGesturesEnabled = enabled
|
137
|
+
}
|
138
|
+
|
139
|
+
@ReactProp(name = "rotateGesturesEnabled")
|
140
|
+
fun setRotateGesturesEnabled(view: MapView, enabled: Boolean) {
|
141
|
+
view.map.uiSettings.isRotateGesturesEnabled = enabled
|
142
|
+
}
|
143
|
+
|
144
|
+
@ReactProp(name = "tiltGesturesEnabled")
|
145
|
+
fun setTiltGesturesEnabled(view: MapView, enabled: Boolean) {
|
146
|
+
view.map.uiSettings.isTiltGesturesEnabled = enabled
|
147
|
+
}
|
148
|
+
|
149
|
+
@ReactProp(name = "cameraPosition")
|
150
|
+
fun setCameraPosition(view: MapView, center: ReadableMap) {
|
151
|
+
view.map.moveCamera(CameraUpdateFactory.changeLatLng(center.toLatLng()))
|
152
|
+
}
|
153
|
+
}
|