Commit b9d36b50 authored by wind.wang's avatar wind.wang

update amap3d

parent ce425048
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin/default"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<projectDescription> <projectDescription>
<name>locationamap</name> <name>react-native-amap-location</name>
<comment>Project locationamap created by Buildship.</comment> <comment>Project react-native-amap-location created by Buildship.</comment>
<projects> <projects>
</projects> </projects>
<buildSpec> <buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand> <buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name> <name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments> <arguments>
...@@ -12,6 +17,7 @@ ...@@ -12,6 +17,7 @@
</buildCommand> </buildCommand>
</buildSpec> </buildSpec>
<natures> <natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature> <nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures> </natures>
</projectDescription> </projectDescription>
connection.project.dir= connection.project.dir=../../../../../android
eclipse.preferences.version=1 eclipse.preferences.version=1
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin/default"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>react-native-amap-map</name>
<comment>Project react-native-amap-map created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>
connection.project.dir=../../../../../android
eclipse.preferences.version=1
...@@ -27,6 +27,6 @@ android { ...@@ -27,6 +27,6 @@ android {
dependencies { dependencies {
provided 'com.facebook.react:react-native:+' provided 'com.facebook.react:react-native:+'
compile 'com.amap.api:map2d:5.2.0' compile 'com.amap.api:3dmap:6.6.0'
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
} }
...@@ -8,7 +8,9 @@ import com.facebook.react.uimanager.ViewManager ...@@ -8,7 +8,9 @@ import com.facebook.react.uimanager.ViewManager
class AMap3DPackage : ReactPackage { class AMap3DPackage : ReactPackage {
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> { override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
return listOf() return listOf(
AMapOfflineModule(reactContext)
)
} }
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> { override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
...@@ -18,7 +20,9 @@ class AMap3DPackage : ReactPackage { ...@@ -18,7 +20,9 @@ class AMap3DPackage : ReactPackage {
AMapInfoWindowManager(), AMapInfoWindowManager(),
AMapPolylineManager(), AMapPolylineManager(),
AMapPolygonManager(), AMapPolygonManager(),
AMapCircleManager() AMapCircleManager(),
AMapHeatMapManager(),
AMapMultiPointManager()
) )
} }
} }
package cn.qiuxiang.react.amap3d
import com.amap.api.maps.offlinemap.OfflineMapCity
import com.amap.api.maps.offlinemap.OfflineMapManager
import com.amap.api.maps.offlinemap.OfflineMapProvince
import com.amap.api.maps.offlinemap.OfflineMapStatus
import com.facebook.react.bridge.*
import com.facebook.react.modules.core.DeviceEventManagerModule
@Suppress("unused")
class AMapOfflineModule(private val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext), OfflineMapManager.OfflineMapDownloadListener {
private val manager = OfflineMapManager(reactContext, this)
override fun getName(): String {
return "AMapOffline"
}
@ReactMethod
fun getProvinces(promise: Promise) {
val provinces = Arguments.createArray()
manager.offlineMapProvinceList.forEach { provinces.pushMap(buildProvince(it)) }
promise.resolve(provinces)
}
@ReactMethod
fun getCities(promise: Promise) {
val cities = Arguments.createArray()
manager.offlineMapCityList.forEach { cities.pushMap(buildCity(it)) }
promise.resolve(cities)
}
@ReactMethod
fun download(name: String) {
manager.offlineMapProvinceList.forEach {
if (it.provinceName == name) {
return manager.downloadByProvinceName(name)
}
it.cityList.forEach {
if (it.city == name) {
return manager.downloadByCityName(name)
}
}
}
}
@ReactMethod
fun stop() {
manager.stop()
}
@ReactMethod
fun remove(name: String) {
manager.remove(name)
}
private fun buildCity(city: OfflineMapCity): WritableMap {
val map = Arguments.createMap()
map.putString("name", city.city)
map.putString("code", city.code)
map.putString("state", getState(city.state))
map.putInt("size", city.size.toInt())
return map
}
private fun buildProvince(province: OfflineMapProvince): WritableMap {
val map = Arguments.createMap()
map.putString("name", province.provinceName)
map.putString("state", getState(province.state))
map.putInt("size", province.size.toInt())
val cities = Arguments.createArray()
province.cityList.forEach { cities.pushMap(buildCity(it)) }
map.putArray("cities", cities)
return map
}
private fun getState(code: Int): String {
var state = ""
when (code) {
OfflineMapStatus.SUCCESS -> state = "downloaded"
OfflineMapStatus.LOADING -> state = "downloading"
OfflineMapStatus.NEW_VERSION -> state = "expired"
OfflineMapStatus.WAITING -> state = "waiting"
OfflineMapStatus.UNZIP -> state = "unzip"
}
return state
}
override fun onDownload(state: Int, progress: Int, name: String?) {
val data = Arguments.createMap()
data.putString("name", name)
data.putString("state", getState(state))
data.putInt("progress", progress)
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java).emit("download", data)
}
override fun onCheckUpdate(p0: Boolean, p1: String?) {}
override fun onRemove(p0: Boolean, p1: String?, p2: String?) {}
}
\ No newline at end of file
package cn.qiuxiang.react.amap3d package cn.qiuxiang.react.amap3d
import android.content.res.Resources import android.content.res.Resources
import com.amap.api.maps2d.model.LatLng import com.amap.api.maps.model.LatLng
import com.amap.api.maps2d.model.LatLngBounds import com.amap.api.maps.model.LatLngBounds
import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.ReadableArray
import com.facebook.react.bridge.ReadableMap import com.facebook.react.bridge.ReadableMap
......
...@@ -2,10 +2,10 @@ package cn.qiuxiang.react.amap3d.maps ...@@ -2,10 +2,10 @@ package cn.qiuxiang.react.amap3d.maps
import android.content.Context import android.content.Context
import android.graphics.Color import android.graphics.Color
import com.amap.api.maps2d.AMap import com.amap.api.maps.AMap
import com.amap.api.maps2d.model.Circle import com.amap.api.maps.model.Circle
import com.amap.api.maps2d.model.CircleOptions import com.amap.api.maps.model.CircleOptions
import com.amap.api.maps2d.model.LatLng import com.amap.api.maps.model.LatLng
import com.facebook.react.views.view.ReactViewGroup import com.facebook.react.views.view.ReactViewGroup
class AMapCircle(context: Context) : ReactViewGroup(context), AMapOverlay { class AMapCircle(context: Context) : ReactViewGroup(context), AMapOverlay {
......
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
import com.amap.api.maps.model.TileOverlay
import com.amap.api.maps.model.TileOverlayOptions
import com.facebook.react.bridge.ReadableArray
import com.facebook.react.views.view.ReactViewGroup
class AMapHeatMap(context: Context) : ReactViewGroup(context), AMapOverlay {
private var overlay: TileOverlay? = null
private var coordinates: ArrayList<LatLng> = ArrayList()
var opacity: Double = 0.6
var radius: Int = 12
fun setCoordinates(coordinates: ReadableArray) {
this.coordinates = coordinates.toLatLngList()
}
override fun add(map: AMap) {
overlay = map.addTileOverlay(TileOverlayOptions().tileProvider(
HeatmapTileProvider.Builder()
.data(coordinates)
.radius(radius)
.transparency(opacity)
.build()))
}
override fun remove() {
overlay?.remove()
}
}
\ No newline at end of file
package cn.qiuxiang.react.amap3d.maps
import com.facebook.react.bridge.ReadableArray
import com.facebook.react.uimanager.SimpleViewManager
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.annotations.ReactProp
@Suppress("unused")
internal class AMapHeatMapManager : SimpleViewManager<AMapHeatMap>() {
override fun getName(): String {
return "AMapHeatMap"
}
override fun createViewInstance(reactContext: ThemedReactContext): AMapHeatMap {
return AMapHeatMap(reactContext)
}
@ReactProp(name = "coordinates")
fun setCoordinate(heatMap: AMapHeatMap, coordinates: ReadableArray) {
heatMap.setCoordinates(coordinates)
}
@ReactProp(name = "radius")
fun setRadius(heatMap: AMapHeatMap, radius: Int) {
heatMap.radius = radius
}
@ReactProp(name = "opacity")
fun setOpacity(heatMap: AMapHeatMap, opacity: Double) {
heatMap.opacity = opacity
}
}
\ No newline at end of file
...@@ -5,13 +5,13 @@ import android.graphics.Color ...@@ -5,13 +5,13 @@ import android.graphics.Color
import android.view.View import android.view.View
import android.widget.LinearLayout import android.widget.LinearLayout
import android.widget.TextView import android.widget.TextView
import com.amap.api.maps2d.AMap import com.amap.api.maps.AMap.InfoWindowAdapter
import com.amap.api.maps2d.model.Marker import com.amap.api.maps.model.Marker
class AMapInfoWindowAdapter( class AMapInfoWindowAdapter(
private val context: Context, private val context: Context,
private val markers: HashMap<String, AMapMarker> private val markers: HashMap<String, AMapMarker>
) : AMap.InfoWindowAdapter { ) : InfoWindowAdapter {
val paddingTop = context.resources.displayMetrics.density val paddingTop = context.resources.displayMetrics.density
override fun getInfoWindow(marker: Marker): View? { override fun getInfoWindow(marker: Marker): View? {
......
...@@ -5,8 +5,8 @@ import android.graphics.Bitmap ...@@ -5,8 +5,8 @@ import android.graphics.Bitmap
import android.graphics.Canvas import android.graphics.Canvas
import android.view.View import android.view.View
import cn.qiuxiang.react.amap3d.toPx import cn.qiuxiang.react.amap3d.toPx
import com.amap.api.maps2d.AMap import com.amap.api.maps.AMap
import com.amap.api.maps2d.model.* import com.amap.api.maps.model.*
import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.ReadableArray
import com.facebook.react.views.view.ReactViewGroup import com.facebook.react.views.view.ReactViewGroup
...@@ -59,12 +59,36 @@ class AMapMarker(context: Context) : ReactViewGroup(context), AMapOverlay { ...@@ -59,12 +59,36 @@ class AMapMarker(context: Context) : ReactViewGroup(context), AMapOverlay {
marker?.snippet = 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 var draggable: Boolean = false
set(value) { set(value) {
field = value field = value
marker?.isDraggable = value marker?.isDraggable = value
} }
var clickDisabled: Boolean = false
set(value) {
field = value
marker?.isClickable = !value
}
var infoWindowDisabled: Boolean = false
set(value) {
field = value
marker?.isInfoWindowEnable = !value
}
var active: Boolean = false var active: Boolean = false
set(value) { set(value) {
field = value field = value
...@@ -83,14 +107,18 @@ class AMapMarker(context: Context) : ReactViewGroup(context), AMapOverlay { ...@@ -83,14 +107,18 @@ class AMapMarker(context: Context) : ReactViewGroup(context), AMapOverlay {
override fun add(map: AMap) { override fun add(map: AMap) {
marker = map.addMarker(MarkerOptions() marker = map.addMarker(MarkerOptions()
.setFlat(flat)
.icon(bitmapDescriptor) .icon(bitmapDescriptor)
.alpha(opacity)
.draggable(draggable) .draggable(draggable)
.position(position) .position(position)
.anchor(anchorU, anchorV) .anchor(anchorU, anchorV)
.infoWindowEnable(!infoWindowDisabled)
.title(title) .title(title)
.snippet(snippet) .snippet(snippet)
.zIndex(zIndex)) .zIndex(zIndex))
this.clickDisabled = clickDisabled
this.active = active this.active = active
} }
......
...@@ -2,6 +2,7 @@ package cn.qiuxiang.react.amap3d.maps ...@@ -2,6 +2,7 @@ package cn.qiuxiang.react.amap3d.maps
import android.view.View import android.view.View
import cn.qiuxiang.react.amap3d.toLatLng import cn.qiuxiang.react.amap3d.toLatLng
import com.amap.api.maps.model.LatLng
import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.ReadableArray
import com.facebook.react.bridge.ReadableMap import com.facebook.react.bridge.ReadableMap
import com.facebook.react.common.MapBuilder import com.facebook.react.common.MapBuilder
...@@ -73,11 +74,31 @@ internal class AMapMarkerManager : ViewGroupManager<AMapMarker>() { ...@@ -73,11 +74,31 @@ internal class AMapMarkerManager : ViewGroupManager<AMapMarker>() {
view.position = coordinate.toLatLng() view.position = coordinate.toLatLng()
} }
@ReactProp(name = "flat")
fun setFlat(marker: AMapMarker, flat: Boolean) {
marker.flat = flat
}
@ReactProp(name = "opacity")
override fun setOpacity(marker: AMapMarker, opacity: Float) {
marker.opacity = opacity
}
@ReactProp(name = "draggable") @ReactProp(name = "draggable")
fun setDraggable(marker: AMapMarker, draggable: Boolean) { fun setDraggable(marker: AMapMarker, draggable: Boolean) {
marker.draggable = draggable marker.draggable = draggable
} }
@ReactProp(name = "clickDisabled")
fun setClickDisabled(marker: AMapMarker, disabled: Boolean) {
marker.clickDisabled = disabled
}
@ReactProp(name = "infoWindowDisabled")
fun setInfoWindowDisabled(marker: AMapMarker, disabled: Boolean) {
marker.infoWindowDisabled = disabled
}
@ReactProp(name = "active") @ReactProp(name = "active")
fun setSelected(marker: AMapMarker, active: Boolean) { fun setSelected(marker: AMapMarker, active: Boolean) {
marker.active = active marker.active = active
......
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
import com.facebook.react.views.view.ReactViewGroup
class AMapMultiPoint(context: Context) : ReactViewGroup(context), AMapOverlay {
private var overlay: MultiPointOverlay? = null
private var items: ArrayList<MultiPointItem> = ArrayList()
private var icon: BitmapDescriptor? = null
fun setPoints(points: ReadableArray) {
items = ArrayList((0 until points.size())
.map {
val data = points.getMap(it)
val item = MultiPointItem(data.toLatLng())
if (data.hasKey("title")) {
item.title = data.getString("title")
}
if (data.hasKey("subtitle")) {
item.snippet = data.getString("subtitle")
}
item.customerId = id.toString() + "_" + it
item
})
overlay?.setItems(items)
}
override fun add(map: AMap) {
overlay = map.addMultiPointOverlay(MultiPointOverlayOptions().icon(icon))
overlay?.setItems(items)
overlay?.setEnable(true)
}
override fun remove() {
overlay?.destroy()
}
fun setImage(image: String) {
val drawable = context.resources.getIdentifier(image, "drawable", context.packageName)
icon = BitmapDescriptorFactory.fromResource(drawable)
}
}
\ No newline at end of file
package cn.qiuxiang.react.amap3d.maps
import com.facebook.react.bridge.ReadableArray
import com.facebook.react.common.MapBuilder
import com.facebook.react.uimanager.SimpleViewManager
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.annotations.ReactProp
@Suppress("unused")
internal class AMapMultiPointManager : SimpleViewManager<AMapMultiPoint>() {
override fun getName(): String {
return "AMapMultiPoint"
}
override fun createViewInstance(reactContext: ThemedReactContext): AMapMultiPoint {
return AMapMultiPoint(reactContext)
}
override fun getExportedCustomDirectEventTypeConstants(): Map<String, Any>? {
return MapBuilder.of(
"onItemPress", MapBuilder.of("registrationName", "onItemPress")
)
}
@ReactProp(name = "points")
fun setPoints(multiPoint: AMapMultiPoint, points: ReadableArray) {
multiPoint.setPoints(points)
}
@ReactProp(name = "image")
fun setImage(multiPoint: AMapMultiPoint, image: String) {
multiPoint.setImage(image);
}
}
\ No newline at end of file
package cn.qiuxiang.react.amap3d.maps package cn.qiuxiang.react.amap3d.maps
import com.amap.api.maps2d.AMap import com.amap.api.maps.AMap
interface AMapOverlay { interface AMapOverlay {
fun add(map: AMap) fun add(map: AMap)
......
...@@ -3,10 +3,10 @@ package cn.qiuxiang.react.amap3d.maps ...@@ -3,10 +3,10 @@ package cn.qiuxiang.react.amap3d.maps
import android.content.Context import android.content.Context
import android.graphics.Color import android.graphics.Color
import cn.qiuxiang.react.amap3d.toLatLngList import cn.qiuxiang.react.amap3d.toLatLngList
import com.amap.api.maps2d.AMap import com.amap.api.maps.AMap
import com.amap.api.maps2d.model.LatLng import com.amap.api.maps.model.LatLng
import com.amap.api.maps2d.model.Polygon import com.amap.api.maps.model.Polygon
import com.amap.api.maps2d.model.PolygonOptions import com.amap.api.maps.model.PolygonOptions
import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.ReadableArray
import com.facebook.react.views.view.ReactViewGroup import com.facebook.react.views.view.ReactViewGroup
......
...@@ -3,10 +3,10 @@ package cn.qiuxiang.react.amap3d.maps ...@@ -3,10 +3,10 @@ package cn.qiuxiang.react.amap3d.maps
import android.content.Context import android.content.Context
import android.graphics.Color import android.graphics.Color
import cn.qiuxiang.react.amap3d.toLatLngList import cn.qiuxiang.react.amap3d.toLatLngList
import com.amap.api.maps2d.AMap import com.amap.api.maps.AMap
import com.amap.api.maps2d.model.LatLng import com.amap.api.maps.model.LatLng
import com.amap.api.maps2d.model.Polyline import com.amap.api.maps.model.Polyline
import com.amap.api.maps2d.model.PolylineOptions import com.amap.api.maps.model.PolylineOptions
import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.ReadableArray
import com.facebook.react.views.view.ReactViewGroup import com.facebook.react.views.view.ReactViewGroup
...@@ -62,7 +62,9 @@ class AMapPolyline(context: Context) : ReactViewGroup(context), AMapOverlay { ...@@ -62,7 +62,9 @@ class AMapPolyline(context: Context) : ReactViewGroup(context), AMapOverlay {
polyline = map.addPolyline(PolylineOptions() polyline = map.addPolyline(PolylineOptions()
.addAll(coordinates) .addAll(coordinates)
.color(color) .color(color)
.colorValues(colors)
.width(width) .width(width)
.useGradient(gradient)
.geodesic(geodesic) .geodesic(geodesic)
.setDottedLine(dashed) .setDottedLine(dashed)
.zIndex(zIndex)) .zIndex(zIndex))
......
package cn.qiuxiang.react.amap3d.maps package cn.qiuxiang.react.amap3d.maps
import android.content.Context import android.content.Context
import android.view.MotionEvent
import android.view.View import android.view.View
import cn.qiuxiang.react.amap3d.toLatLng import cn.qiuxiang.react.amap3d.toLatLng
import cn.qiuxiang.react.amap3d.toLatLngBounds import cn.qiuxiang.react.amap3d.toLatLngBounds
import cn.qiuxiang.react.amap3d.toWritableMap import cn.qiuxiang.react.amap3d.toWritableMap
import com.amap.api.maps2d.AMap import com.amap.api.maps.AMap
import com.amap.api.maps2d.CameraUpdateFactory import com.amap.api.maps.CameraUpdateFactory
import com.amap.api.maps2d.MapView import com.amap.api.maps.TextureMapView
import com.amap.api.maps2d.model.BitmapDescriptorFactory import com.amap.api.maps.model.BitmapDescriptorFactory
import com.amap.api.maps2d.model.CameraPosition import com.amap.api.maps.model.CameraPosition
import com.amap.api.maps2d.model.Marker import com.amap.api.maps.model.Marker
import com.amap.api.maps2d.model.MyLocationStyle import com.amap.api.maps.model.MyLocationStyle
import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.ReadableArray
import com.facebook.react.bridge.ReadableMap import com.facebook.react.bridge.ReadableMap
...@@ -20,18 +19,13 @@ import com.facebook.react.bridge.WritableMap ...@@ -20,18 +19,13 @@ import com.facebook.react.bridge.WritableMap
import com.facebook.react.uimanager.ThemedReactContext import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.events.RCTEventEmitter import com.facebook.react.uimanager.events.RCTEventEmitter
class AMapView(context: Context) : MapView(context) { class AMapView(context: Context) : TextureMapView(context) {
private val eventEmitter: RCTEventEmitter = (context as ThemedReactContext).getJSModule(RCTEventEmitter::class.java) private val eventEmitter: RCTEventEmitter = (context as ThemedReactContext).getJSModule(RCTEventEmitter::class.java)
private val markers = HashMap<String, AMapMarker>() private val markers = HashMap<String, AMapMarker>()
private val lines = HashMap<String, AMapPolyline>() private val lines = HashMap<String, AMapPolyline>()
var touchEnable: Boolean = true
private val locationStyle by lazy { private val locationStyle by lazy {
val locationStyle = MyLocationStyle() val locationStyle = MyLocationStyle()
locationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_FOLLOW_NO_CENTER) locationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER)
locationStyle locationStyle
} }
...@@ -43,7 +37,7 @@ class AMapView(context: Context) : MapView(context) { ...@@ -43,7 +37,7 @@ class AMapView(context: Context) : MapView(context) {
marker.active = false marker.active = false
} }
emit(id, "onMapPress", latLng.toWritableMap()) emit(id, "onPress", latLng.toWritableMap())
} }
map.setOnMapLongClickListener { latLng -> map.setOnMapLongClickListener { latLng ->
...@@ -97,6 +91,18 @@ class AMapView(context: Context) : MapView(context) { ...@@ -97,6 +91,18 @@ class AMapView(context: Context) : MapView(context) {
emit(markers[marker.id]?.id, "onInfoWindowPress") emit(markers[marker.id]?.id, "onInfoWindowPress")
} }
map.setOnPolylineClickListener { polyline ->
emit(lines[polyline.id]?.id, "onPress")
}
map.setOnMultiPointClickListener { item ->
val slice = item.customerId.split("_")
val data = Arguments.createMap()
data.putInt("index", slice[1].toInt())
emit(slice[0].toInt(), "onItemPress", data)
false
}
map.setInfoWindowAdapter(AMapInfoWindowAdapter(context, markers)) map.setInfoWindowAdapter(AMapInfoWindowAdapter(context, markers))
} }
...@@ -189,9 +195,13 @@ class AMapView(context: Context) : MapView(context) { ...@@ -189,9 +195,13 @@ class AMapView(context: Context) : MapView(context) {
map.moveCamera(CameraUpdateFactory.newLatLngBounds(region.toLatLngBounds(), 0)) map.moveCamera(CameraUpdateFactory.newLatLngBounds(region.toLatLngBounds(), 0))
} }
fun setLimitRegion(region: ReadableMap) {
map.setMapStatusLimits(region.toLatLngBounds())
}
fun setLocationEnabled(enabled: Boolean) { fun setLocationEnabled(enabled: Boolean) {
map.isMyLocationEnabled = enabled map.isMyLocationEnabled = enabled
map.setMyLocationStyle(locationStyle) map.myLocationStyle = locationStyle
} }
fun setLocationInterval(interval: Long) { fun setLocationInterval(interval: Long) {
...@@ -220,10 +230,6 @@ class AMapView(context: Context) : MapView(context) { ...@@ -220,10 +230,6 @@ class AMapView(context: Context) : MapView(context) {
fun setLocationType(type: Int) { fun setLocationType(type: Int) {
locationStyle.myLocationType(type) locationStyle.myLocationType(type)
map.setMyLocationStyle(locationStyle) map.myLocationStyle = locationStyle
}
override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean {
return !touchEnable
} }
} }
package cn.qiuxiang.react.amap3d.maps package cn.qiuxiang.react.amap3d.maps
import android.view.View import android.view.View
import com.amap.api.maps2d.AMap import com.amap.api.maps.AMap
import com.amap.api.maps2d.CameraUpdateFactory import com.amap.api.maps.CameraUpdateFactory
import com.amap.api.maps2d.model.LatLng import com.amap.api.maps.model.LatLng
import com.amap.api.maps2d.model.MyLocationStyle import com.amap.api.maps.model.MyLocationStyle
import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.ReadableArray
import com.facebook.react.bridge.ReadableMap import com.facebook.react.bridge.ReadableMap
import com.facebook.react.common.MapBuilder import com.facebook.react.common.MapBuilder
...@@ -53,7 +53,7 @@ internal class AMapViewManager : ViewGroupManager<AMapView>() { ...@@ -53,7 +53,7 @@ internal class AMapViewManager : ViewGroupManager<AMapView>() {
override fun getExportedCustomDirectEventTypeConstants(): Map<String, Any> { override fun getExportedCustomDirectEventTypeConstants(): Map<String, Any> {
return MapBuilder.of( return MapBuilder.of(
"onMapPress", MapBuilder.of("registrationName", "onMapPress"), "onPress", MapBuilder.of("registrationName", "onPress"),
"onLongPress", MapBuilder.of("registrationName", "onLongPress"), "onLongPress", MapBuilder.of("registrationName", "onLongPress"),
"onAnimateCancel", MapBuilder.of("registrationName", "onAnimateCancel"), "onAnimateCancel", MapBuilder.of("registrationName", "onAnimateCancel"),
"onAnimateFinish", MapBuilder.of("registrationName", "onAnimateFinish"), "onAnimateFinish", MapBuilder.of("registrationName", "onAnimateFinish"),
...@@ -68,6 +68,26 @@ internal class AMapViewManager : ViewGroupManager<AMapView>() { ...@@ -68,6 +68,26 @@ internal class AMapViewManager : ViewGroupManager<AMapView>() {
view.setLocationEnabled(enabled) view.setLocationEnabled(enabled)
} }
@ReactProp(name = "showsIndoorMap")
fun showIndoorMap(view: AMapView, show: Boolean) {
view.map.showIndoorMap(show)
}
@ReactProp(name = "showsIndoorSwitch")
fun setIndoorSwitchEnabled(view: AMapView, show: Boolean) {
view.map.uiSettings.isIndoorSwitchEnabled = show
}
@ReactProp(name = "showsBuildings")
fun showBuildings(view: AMapView, show: Boolean) {
view.map.showBuildings(show)
}
@ReactProp(name = "showsLabels")
fun showMapText(view: AMapView, show: Boolean) {
view.map.showMapText(show)
}
@ReactProp(name = "showsCompass") @ReactProp(name = "showsCompass")
fun setCompassEnabled(view: AMapView, show: Boolean) { fun setCompassEnabled(view: AMapView, show: Boolean) {
view.map.uiSettings.isCompassEnabled = show view.map.uiSettings.isCompassEnabled = show
...@@ -93,6 +113,16 @@ internal class AMapViewManager : ViewGroupManager<AMapView>() { ...@@ -93,6 +113,16 @@ internal class AMapViewManager : ViewGroupManager<AMapView>() {
view.map.isTrafficEnabled = enabled view.map.isTrafficEnabled = enabled
} }
@ReactProp(name = "maxZoomLevel")
fun setMaxZoomLevel(view: AMapView, zoomLevel: Float) {
view.map.maxZoomLevel = zoomLevel
}
@ReactProp(name = "minZoomLevel")
fun setMinZoomLevel(view: AMapView, zoomLevel: Float) {
view.map.minZoomLevel = zoomLevel
}
@ReactProp(name = "zoomLevel") @ReactProp(name = "zoomLevel")
fun setZoomLevel(view: AMapView, zoomLevel: Float) { fun setZoomLevel(view: AMapView, zoomLevel: Float) {
view.map.moveCamera(CameraUpdateFactory.zoomTo(zoomLevel)) view.map.moveCamera(CameraUpdateFactory.zoomTo(zoomLevel))
...@@ -103,6 +133,9 @@ internal class AMapViewManager : ViewGroupManager<AMapView>() { ...@@ -103,6 +133,9 @@ internal class AMapViewManager : ViewGroupManager<AMapView>() {
when (mapType) { when (mapType) {
"standard" -> view.map.mapType = AMap.MAP_TYPE_NORMAL "standard" -> view.map.mapType = AMap.MAP_TYPE_NORMAL
"satellite" -> view.map.mapType = AMap.MAP_TYPE_SATELLITE "satellite" -> view.map.mapType = AMap.MAP_TYPE_SATELLITE
"navigation" -> view.map.mapType = AMap.MAP_TYPE_NAVI
"night" -> view.map.mapType = AMap.MAP_TYPE_NIGHT
"bus" -> view.map.mapType = AMap.MAP_TYPE_BUS
} }
} }
...@@ -116,6 +149,16 @@ internal class AMapViewManager : ViewGroupManager<AMapView>() { ...@@ -116,6 +149,16 @@ internal class AMapViewManager : ViewGroupManager<AMapView>() {
view.map.uiSettings.isScrollGesturesEnabled = enabled view.map.uiSettings.isScrollGesturesEnabled = enabled
} }
@ReactProp(name = "rotateEnabled")
fun setRotateGesturesEnabled(view: AMapView, enabled: Boolean) {
view.map.uiSettings.isRotateGesturesEnabled = enabled
}
@ReactProp(name = "tiltEnabled")
fun setTiltGesturesEnabled(view: AMapView, enabled: Boolean) {
view.map.uiSettings.isTiltGesturesEnabled = enabled
}
@ReactProp(name = "coordinate") @ReactProp(name = "coordinate")
fun moveToCoordinate(view: AMapView, coordinate: ReadableMap) { fun moveToCoordinate(view: AMapView, coordinate: ReadableMap) {
view.map.moveCamera(CameraUpdateFactory.changeLatLng(LatLng( view.map.moveCamera(CameraUpdateFactory.changeLatLng(LatLng(
...@@ -128,6 +171,21 @@ internal class AMapViewManager : ViewGroupManager<AMapView>() { ...@@ -128,6 +171,21 @@ internal class AMapViewManager : ViewGroupManager<AMapView>() {
view.setRegion(region) view.setRegion(region)
} }
@ReactProp(name = "limitRegion")
fun setLimitRegion(view: AMapView, limitRegion: ReadableMap) {
view.setLimitRegion(limitRegion)
}
@ReactProp(name = "tilt")
fun changeTilt(view: AMapView, tilt: Float) {
view.map.moveCamera(CameraUpdateFactory.changeTilt(tilt))
}
@ReactProp(name = "rotation")
fun changeRotation(view: AMapView, rotation: Float) {
view.map.moveCamera(CameraUpdateFactory.changeBearing(rotation))
}
@ReactProp(name = "locationInterval") @ReactProp(name = "locationInterval")
fun setLocationInterval(view: AMapView, interval: Int) { fun setLocationInterval(view: AMapView, interval: Int) {
view.setLocationInterval(interval.toLong()) view.setLocationInterval(interval.toLong())
...@@ -138,17 +196,17 @@ internal class AMapViewManager : ViewGroupManager<AMapView>() { ...@@ -138,17 +196,17 @@ internal class AMapViewManager : ViewGroupManager<AMapView>() {
view.setLocationStyle(style) view.setLocationStyle(style)
} }
@ReactProp(name = "touchEnable")
fun setViewTouchEnable(view: AMapView, enabled: Boolean){
view.touchEnable = enabled
}
@ReactProp(name = "locationType") @ReactProp(name = "locationType")
fun setLocationStyle(view: AMapView, type: String) { fun setLocationStyle(view: AMapView, type: String) {
when (type) { when (type) {
"show" -> view.setLocationType(MyLocationStyle.LOCATION_TYPE_SHOW) "show" -> view.setLocationType(MyLocationStyle.LOCATION_TYPE_SHOW)
"locate" -> view.setLocationType(MyLocationStyle.LOCATION_TYPE_LOCATE) "locate" -> view.setLocationType(MyLocationStyle.LOCATION_TYPE_LOCATE)
"follow" -> view.setLocationType(MyLocationStyle.LOCATION_TYPE_FOLLOW)"follow_no_center" -> view.setLocationType(MyLocationStyle.LOCATION_TYPE_FOLLOW_NO_CENTER) "follow" -> view.setLocationType(MyLocationStyle.LOCATION_TYPE_FOLLOW)
} "map_rotate" -> view.setLocationType(MyLocationStyle.LOCATION_TYPE_MAP_ROTATE)
"location_rotate" -> view.setLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE)
"location_rotate_no_center" -> view.setLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER)
"follow_no_center" -> view.setLocationType(MyLocationStyle.LOCATION_TYPE_FOLLOW_NO_CENTER)
"map_rotate_no_center" -> view.setLocationType(MyLocationStyle.LOCATION_TYPE_MAP_ROTATE_NO_CENTER)
}
} }
} }
/** /**
* 基础组件,包含一些公共方法 * 基础组件,包含一些公共方法
*
* @flow
*/ */
import { PureComponent } from 'react' import { PureComponent } from "react";
import { findNodeHandle, UIManager } from 'react-native' import { findNodeHandle, UIManager } from "react-native";
export default class Component<T> extends PureComponent<T> { export default class Component extends PureComponent {
/** /**
* 原生组件名称 * 原生组件名称
*/ */
name: string name;
/** /**
* 调用原生方法 * 调用原生方法
* *
* @private * @private
*/ */
sendCommand(command: string, params?: any[]) { sendCommand(command, params = []) {
UIManager.dispatchViewManagerCommand( UIManager.dispatchViewManagerCommand(
findNodeHandle(this), findNodeHandle(this),
UIManager[this.name].Commands[command], UIManager[this.name].Commands[command],
params, params
) );
} }
} }
import { NativeModules, NativeEventEmitter } from "react-native";
const { AMapOffline } = NativeModules;
const eventEmitter = new NativeEventEmitter(AMapOffline);
export default {
getProvinces: () => AMapOffline.getProvinces(),
getCities: () => AMapOffline.getCities(),
download: name => AMapOffline.download(name),
remove: name => AMapOffline.remove(name),
addDownloadListener: callback => eventEmitter.addListener("download", callback)
};
import PropTypes from 'prop-types' import PropTypes from "prop-types";
const LatLng = PropTypes.shape({ const LatLng = PropTypes.shape({
latitude: PropTypes.number.isRequired, latitude: PropTypes.number.isRequired,
longitude: PropTypes.number.isRequired, longitude: PropTypes.number.isRequired
}) });
const Region = PropTypes.shape({ const Region = PropTypes.shape({
latitude: PropTypes.number.isRequired, latitude: PropTypes.number.isRequired,
longitude: PropTypes.number.isRequired, longitude: PropTypes.number.isRequired,
latitudeDelta: PropTypes.number.isRequired, latitudeDelta: PropTypes.number.isRequired,
longitudeDelta: PropTypes.number.isRequired, longitudeDelta: PropTypes.number.isRequired
}) });
const Point = PropTypes.shape({ const Point = PropTypes.shape({
x: PropTypes.number.isRequired, x: PropTypes.number.isRequired,
y: PropTypes.number.isRequired, y: PropTypes.number.isRequired
}) });
export { LatLng, Region, Point } export { LatLng, Region, Point };
import MapView from './maps/MapView' import MapView from "./maps/MapView";
import Marker from './maps/Marker' import Marker from "./maps/Marker";
import Polygon from './maps/Polygon' import Polyline from "./maps/Polyline";
import Circle from './maps/Circle' import Polygon from "./maps/Polygon";
import Circle from "./maps/Circle";
import HeatMap from "./maps/HeatMap";
import MultiPoint from "./maps/MultiPoint";
import Offline from "./Offline";
MapView.Marker = Marker MapView.Marker = Marker;
MapView.Polygon = Polygon MapView.Polyline = Polyline;
MapView.Circle = Circle MapView.Polygon = Polygon;
MapView.Circle = Circle;
MapView.HeatMap = HeatMap;
MapView.MultiPoint = MultiPoint;
export default MapView export default MapView;
export { export { MapView, Marker, Polyline, Polygon, Circle, HeatMap, MultiPoint, Offline };
MapView,
Marker,
Polygon,
Circle,
}
// import MapView from './maps/MapView'
// import Marker from './maps/Marker'
// import Polygon from './maps/Polygon'
// import Circle from './maps/Circle'
import React from 'react';
import { Map, Marker as RMarker, InfoWindow } from 'react-amap';
const MapView = (props) => {
return <Map {...props} center={props.coordinate}></Map>
}
const Marker = (props) => {
return <RMarker {...props} position={props.coordinate} />
}
MapView.Marker = Marker
export default MapView
export {
MapView,
Marker,
InfoWindow,
}
import PropTypes from 'prop-types' import PropTypes from "prop-types";
import { ColorPropType, requireNativeComponent, ViewPropTypes } from 'react-native' import { ColorPropType, requireNativeComponent, ViewPropTypes } from "react-native";
import { LatLng } from '../PropTypes' import { LatLng } from "../PropTypes";
export default requireNativeComponent('AMapCircle', { export default requireNativeComponent("AMapCircle", {
propTypes: { propTypes: {
...ViewPropTypes, ...ViewPropTypes,
...@@ -34,6 +34,6 @@ export default requireNativeComponent('AMapCircle', { ...@@ -34,6 +34,6 @@ export default requireNativeComponent('AMapCircle', {
/** /**
* 层级 * 层级
*/ */
zIndex: PropTypes.number, zIndex: PropTypes.number
}, }
}) });
import PropTypes from "prop-types";
import { requireNativeComponent, ViewPropTypes } from "react-native";
import { LatLng } from "../PropTypes";
/**
* 注意,热力图组件的 props 设置过一次之后便不能再更改
*/
export default requireNativeComponent("AMapHeatMap", {
propTypes: {
...ViewPropTypes,
/**
* 节点坐标
*/
coordinates: PropTypes.arrayOf(LatLng).isRequired,
/**
* 半径(米)
*/
radius: PropTypes.number,
/**
* 透明度
*/
opacity: PropTypes.number
}
});
// @flow // @flow
import React from 'react' import React from "react";
import PropTypes from 'prop-types' import PropTypes from "prop-types";
import { processColor, requireNativeComponent, ViewPropTypes, Platform } from 'react-native' import { processColor, requireNativeComponent, ViewPropTypes } from "react-native";
import { LatLng, Region } from '../PropTypes' import { LatLng, Region } from "../PropTypes";
import Component from '../Component' import Component from "../Component";
export type MapStatus = {
zoomLevel?: number,
coordinate?: LatLng,
titl?: number,
rotation?: number,
}
export const LocationStyle = PropTypes.shape({ export const LocationStyle = PropTypes.shape({
image: PropTypes.string, image: PropTypes.string,
fillColor: PropTypes.string, fillColor: PropTypes.string,
strokeColor: PropTypes.string, strokeColor: PropTypes.string,
strokeWidth: PropTypes.number, strokeWidth: PropTypes.number
}) });
const isIos = Platform.OS === 'ios'
export default class MapView extends Component<any> { export default class MapView extends Component {
static propTypes = { static propTypes = {
...ViewPropTypes, ...ViewPropTypes,
...@@ -34,22 +25,7 @@ export default class MapView extends Component<any> { ...@@ -34,22 +25,7 @@ export default class MapView extends Component<any> {
* - night: 夜间地图 * - night: 夜间地图
* - bus: 公交地图 * - bus: 公交地图
*/ */
mapType: PropTypes.oneOf(['standard', 'satellite', 'navigation', 'night', 'bus']), mapType: PropTypes.oneOf(["standard", "satellite", "navigation", "night", "bus"]),
/**
* 是否启用跟踪模式
* 0: 不跟踪
* 1: 跟踪用户定位
* 2: 跟踪用户定位和方向
*/
userTrackingMode: PropTypes.oneOf(0, 1, 2),
/**
* 是否跟踪用户位置
*/
showsUserLocation: PropTypes.bool,
/**
* 缩放尺寸,范围是:[3-19]
*/
zoomLevel: PropTypes.number,
/** /**
* 设置定位图标的样式 * 设置定位图标的样式
...@@ -61,8 +37,16 @@ export default class MapView extends Component<any> { ...@@ -61,8 +37,16 @@ export default class MapView extends Component<any> {
* *
* @platform android * @platform android
*/ */
locationType: PropTypes.oneOf(['show', 'locate', 'follow', 'map_rotate', 'location_rotate', locationType: PropTypes.oneOf([
'location_rotate_no_center', 'follow_no_center', 'map_rotate_no_center']), "show",
"locate",
"follow",
"map_rotate",
"location_rotate",
"location_rotate_no_center",
"follow_no_center",
"map_rotate_no_center"
]),
/** /**
* 是否启用定位 * 是否启用定位
...@@ -194,28 +178,12 @@ export default class MapView extends Component<any> { ...@@ -194,28 +178,12 @@ export default class MapView extends Component<any> {
*/ */
tiltEnabled: PropTypes.bool, tiltEnabled: PropTypes.bool,
/**
* 是否可以触摸
*/
touchEnable: PropTypes.bool,
/**
* 是否启用定位
*/
showsUserLocation: PropTypes.bool,
/**
* 中心坐标
*/
centerLocation: LatLng,
/** /**
* 点击事件 * 点击事件
* *
* @param {{ nativeEvent: LatLng }} * @param {{ nativeEvent: LatLng }}
*/ */
onMapPress: PropTypes.func, onPress: PropTypes.func,
/** /**
* 长按事件 * 长按事件
...@@ -280,86 +248,30 @@ export default class MapView extends Component<any> { ...@@ -280,86 +248,30 @@ export default class MapView extends Component<any> {
* } * }
* }} * }}
*/ */
onStatusChangeComplete: PropTypes.func, onStatusChangeComplete: PropTypes.func
} };
name = 'AMapView' name = "AMapView";
isMapFirstLoaded = false
_isMoveByUser = true
lastCompleteTime = 0
_onMoveComplete = (event) => {
const oldLastCompleteTime = this.lastCompleteTime
this.lastCompleteTime = new Date().getTime()
if ((this.lastCompleteTime - oldLastCompleteTime) < 700) {
this._isMoveByUser = true
return
}
if (isIos && !this.isMapFirstLoaded) {
this.isMapFirstLoaded = true
this._isMoveByUser = true
return
}
this.props.onStatusChangeComplete && this.props.onStatusChangeComplete(event, this._isMoveByUser)
this._isMoveByUser = true
}
componentWillReceiveProps({ coordinate }) {
const oldCoordinate = this.props.coordinate
if (coordinate && oldCoordinate) {
const { latitude, longitude } = coordinate
const oldLatitude = oldCoordinate.latitude
const oldLongitude = oldCoordinate.longitude
if ((latitude != oldLatitude) && (longitude != oldLongitude)) {
this._isMoveByUser = false
}
} else if (coordinate) {
this._isMoveByUser = false
}
}
_onMovingChange = (event) => {
if (isIos && !this.isMapFirstLoaded) {
return
}
this.props.onStatusChange && this.props.onStatusChange(event, this._isMoveByUser)
}
/** /**
* 动画过渡到某个状态(坐标、缩放级别、倾斜度、旋转角度) * 动画过渡到某个状态(坐标、缩放级别、倾斜度、旋转角度)
*/ */
animateTo(target: MapStatus, duration?: number = 500) { animateTo(target, duration = 500) {
this.sendCommand('animateTo', [target, duration]) this.sendCommand("animateTo", [target, duration]);
}
onMapPress = (event) => {
if (this.props.onMapPress) {
this.props.onMapPress(event)
}
} }
render() { render() {
const props = { ...this.props } const props = { ...this.props };
const { centerLocation } = this.props
if (centerLocation) {
delete props.centerLocation
props.coordinate = centerLocation
}
if (props.locationStyle) { if (props.locationStyle) {
if (props.locationStyle.strokeColor) { if (props.locationStyle.strokeColor) {
props.locationStyle.strokeColor = processColor(props.locationStyle.strokeColor) props.locationStyle.strokeColor = processColor(props.locationStyle.strokeColor);
} }
if (props.locationStyle.fillColor) { if (props.locationStyle.fillColor) {
props.locationStyle.fillColor = processColor(props.locationStyle.fillColor) props.locationStyle.fillColor = processColor(props.locationStyle.fillColor);
} }
} }
return <AMapView {...props} onMapPress={this.onMapPress} onStatusChange={this._onMovingChange} onStatusChangeComplete={this._onMoveComplete} /> return <AMapView {...props} />;
} }
} }
const AMapView = requireNativeComponent('AMapView', MapView) const AMapView = requireNativeComponent("AMapView", MapView);
// @flow // @flow
import React from 'react' import React from "react";
import PropTypes from 'prop-types' import PropTypes from "prop-types";
import { Platform, requireNativeComponent, StyleSheet, ViewPropTypes, View } from 'react-native' import { Platform, requireNativeComponent, StyleSheet, ViewPropTypes, View } from "react-native";
import { LatLng, Point } from '../PropTypes' import { LatLng, Point } from "../PropTypes";
import Component from '../Component' import Component from "../Component";
const style = StyleSheet.create({ const style = StyleSheet.create({
overlay: { overlay: {
position: 'absolute', position: "absolute"
}, }
}) });
export default class Marker extends Component<any> { export default class Marker extends Component {
static propTypes = { static propTypes = {
...ViewPropTypes, ...ViewPropTypes,
/**
* key
*/
markKey: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
]),
/** /**
* 坐标 * 坐标
*/ */
...@@ -43,22 +35,18 @@ export default class Marker extends Component<any> { ...@@ -43,22 +35,18 @@ export default class Marker extends Component<any> {
*/ */
color: Platform.select({ color: Platform.select({
android: PropTypes.oneOf([ android: PropTypes.oneOf([
'azure', "azure",
'blue', "blue",
'cyan', "cyan",
'green', "green",
'magenta', "magenta",
'orange', "orange",
'red', "red",
'rose', "rose",
'violet', "violet",
'yellow', "yellow"
]),
ios: PropTypes.oneOf([
'red',
'green',
'purple',
]), ]),
ios: PropTypes.oneOf(["red", "green", "purple"])
}), }),
/** /**
...@@ -147,61 +135,51 @@ export default class Marker extends Component<any> { ...@@ -147,61 +135,51 @@ export default class Marker extends Component<any> {
* *
* 注意,对于自定义信息窗体,该事件是无效的 * 注意,对于自定义信息窗体,该事件是无效的
*/ */
onInfoWindowPress: PropTypes.func, onInfoWindowPress: PropTypes.func
} };
componentDidUpdate() { componentDidUpdate() {
if (this.icon && Platform.OS === 'android') { if (this.icon && Platform.OS === "android") {
setTimeout(() => this.sendCommand('update'), 0) setTimeout(() => this.sendCommand("update"), 0);
} }
} }
name = 'AMapMarker' name = "AMapMarker";
icon: View = null icon = null;
onMarkPress = () => {
if (this.props.onPress) {
this.props.onPress(this.props.markKey)
}
}
active() { active() {
this.sendCommand('active') this.sendCommand("active");
} }
lockToScreen(x: number, y: number) { lockToScreen(x, y) {
this.sendCommand('lockToScreen', [x, y]) this.sendCommand("lockToScreen", [x, y]);
} }
renderCustomMarker(icon: () => View) { renderCustomMarker(icon) {
if (icon) { if (icon) {
this.icon = <View style={style.overlay}>{icon()}</View> this.icon = <View style={style.overlay}>{icon()}</View>;
return this.icon return this.icon;
} }
return null return null;
} }
/* eslint-disable class-methods-use-this */ /* eslint-disable class-methods-use-this */
renderInfoWindow(view: View) { renderInfoWindow(view) {
if (view) { if (view) {
return <InfoWindow style={style.overlay}>{view}</InfoWindow> return <InfoWindow style={style.overlay}>{view}</InfoWindow>;
} }
return null return null;
} }
render() { render() {
return ( return (
<AMapMarker {...this.props} onPress={this.onMarkPress}> <AMapMarker {...this.props}>
{this.renderCustomMarker(this.props.icon)} {this.renderCustomMarker(this.props.icon)}
{this.renderInfoWindow(this.props.children)} {this.renderInfoWindow(this.props.children)}
</AMapMarker> </AMapMarker>
) );
} }
} }
const AMapMarker = requireNativeComponent('AMapMarker', Marker) const AMapMarker = requireNativeComponent("AMapMarker", Marker);
const InfoWindow = requireNativeComponent('AMapInfoWindow', { const InfoWindow = requireNativeComponent("AMapInfoWindow", { propTypes: { ...ViewPropTypes } });
propTypes: {
...ViewPropTypes,
},
})
import React, { PureComponent } from "react";
import PropTypes from "prop-types";
import { requireNativeComponent, ViewPropTypes } from "react-native";
export const Point = PropTypes.shape({
latitude: PropTypes.number.isRequired,
longitude: PropTypes.number.isRequired,
title: PropTypes.string,
subtitle: PropTypes.string
});
export default class MultiPoint extends PureComponent {
static propTypes = {
...ViewPropTypes,
/**
* 节点
*/
points: PropTypes.arrayOf(Point).isRequired,
/**
* 图标,只接受原生图片名字
*/
image: PropTypes.string,
/**
* 点击事件
*
* @param {Point}
*/
onItemPress: PropTypes.func
};
onItemPress = ({ nativeEvent }) => {
if (this.props.onItemPress) {
this.props.onItemPress(this.props.points[nativeEvent.index]);
}
};
render() {
return <AMapMultiPoint {...this.props} onItemPress={this.onItemPress} />;
}
}
const AMapMultiPoint = requireNativeComponent("AMapMultiPoint", MultiPoint);
import PropTypes from 'prop-types' import PropTypes from "prop-types";
import { ColorPropType, requireNativeComponent, ViewPropTypes } from 'react-native' import { ColorPropType, requireNativeComponent, ViewPropTypes } from "react-native";
import { LatLng } from '../PropTypes' import { LatLng } from "../PropTypes";
export default requireNativeComponent('AMapPolygon', { export default requireNativeComponent("AMapPolygon", {
propTypes: { propTypes: {
...ViewPropTypes, ...ViewPropTypes,
...@@ -29,6 +29,6 @@ export default requireNativeComponent('AMapPolygon', { ...@@ -29,6 +29,6 @@ export default requireNativeComponent('AMapPolygon', {
/** /**
* 层级 * 层级
*/ */
zIndex: PropTypes.number, zIndex: PropTypes.number
}, }
}) });
// @flow
import React, { PureComponent } from "react";
import PropTypes from "prop-types";
import {
ColorPropType,
Platform,
processColor,
requireNativeComponent,
ViewPropTypes
} from "react-native";
import { LatLng } from "../PropTypes";
export default class Polyline extends PureComponent {
static propTypes = {
...ViewPropTypes,
/**
* 节点坐标
*/
coordinates: PropTypes.arrayOf(LatLng).isRequired,
/**
* 线段宽度
*/
width: PropTypes.number,
/**
* 线段颜色
*/
color: ColorPropType,
/**
* 层级
*/
zIndex: PropTypes.number,
/**
* 多段颜色
*/
colors: PropTypes.arrayOf(ColorPropType),
/**
* 是否使用颜色渐变
*/
gradient: PropTypes.bool,
/**
* 是否绘制大地线
*/
geodesic: PropTypes.bool,
/**
* 是否绘制虚线
*/
dashed: PropTypes.bool,
/**
* 点击事件
*/
onPress: PropTypes.func
};
static defaultProps = {
colors: []
};
render() {
const props = {
...this.props,
...Platform.select({
android: {
colors: this.props.colors.map(processColor)
}
})
};
return <AMapPolyline {...props} />;
}
}
const AMapPolyline = requireNativeComponent("AMapPolyline", Polyline);
#import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h>
#import <MAMapKit/MAOfflineMap.h>
#pragma ide diagnostic ignored "OCUnusedClassInspection"
@interface AMapOffline : RCTEventEmitter <RCTBridgeModule>
@end
@implementation AMapOffline
RCT_EXPORT_MODULE()
RCT_REMAP_METHOD(getProvinces,
resolveProvinces: (RCTPromiseResolveBlock) resolve
reject: (RCTPromiseRejectBlock) reject) {
NSMutableArray *provinces = [NSMutableArray new];
for (id item in MAOfflineMap.sharedOfflineMap.provinces) {
MAOfflineProvince *province = (MAOfflineProvince *) item;
NSMutableArray *cities = [NSMutableArray new];
for (id city in province.cities) {
[cities addObject:[self itemData:(MAOfflineCity *) city]];
}
[provinces addObject:@{
@"name": province.name,
@"size": @(province.size),
@"state": [self stateString:province.itemStatus],
@"cities": cities,
}];
}
for (id item in MAOfflineMap.sharedOfflineMap.municipalities) {
[provinces addObject:[self itemData:item]];
}
resolve(provinces);
}
RCT_REMAP_METHOD(getCities,
resolveCities: (RCTPromiseResolveBlock) resolve
reject: (RCTPromiseRejectBlock) reject) {
NSMutableArray *cities = [NSMutableArray new];
for (id city in MAOfflineMap.sharedOfflineMap.cities) {
[cities addObject:[self itemData:(MAOfflineCity *) city]];
}
resolve(cities);
}
RCT_EXPORT_METHOD(download:(NSString *)name) {
MAOfflineItem *item = [self getItem:name];
void (^downloadBlock)(MAOfflineItem *, MAOfflineMapDownloadStatus, id)=^(MAOfflineItem *downloadItem, MAOfflineMapDownloadStatus state, id info) {
NSDictionary *data = (NSDictionary *) info;
double progress = 0;
if (state == MAOfflineMapDownloadStatusProgress) {
progress = [data[MAOfflineMapDownloadReceivedSizeKey] doubleValue] / [data[MAOfflineMapDownloadExpectedSizeKey] doubleValue] * 100;
}
[self sendEventWithName:@"download" body:@{
@"name": name,
@"state": [self downloadStateString:state],
@"progress": @(progress),
}];
};
if (item != nil) {
[MAOfflineMap.sharedOfflineMap downloadItem:item
shouldContinueWhenAppEntersBackground:YES
downloadBlock:downloadBlock];
}
}
RCT_EXPORT_METHOD(remove:(NSString *)name) {
MAOfflineItem *item = [self getItem:name];
if (item != nil) {
[MAOfflineMap.sharedOfflineMap deleteItem:item];
}
}
- (MAOfflineItem *)getItem:(NSString *)name {
BOOL (^predicate)(MAOfflineItem *, NSUInteger, BOOL *)=^BOOL (MAOfflineItem * item, NSUInteger _, BOOL *stop) {
return [name isEqual:item.name];
};
NSUInteger i = [MAOfflineMap.sharedOfflineMap.provinces indexOfObjectPassingTest:predicate];
if (i != NSNotFound) {
return MAOfflineMap.sharedOfflineMap.provinces[i];
}
i = [MAOfflineMap.sharedOfflineMap.municipalities indexOfObjectPassingTest:predicate];
if (i != NSNotFound) {
return MAOfflineMap.sharedOfflineMap.municipalities[i];
}
i = [MAOfflineMap.sharedOfflineMap.cities indexOfObjectPassingTest:predicate];
if (i != NSNotFound) {
return MAOfflineMap.sharedOfflineMap.cities[i];
}
return nil;
}
- (NSString *)downloadStateString:(MAOfflineMapDownloadStatus)code {
switch (code) {
case MAOfflineMapDownloadStatusWaiting: return @"waiting";
case MAOfflineMapDownloadStatusStart: return @"downloading";
case MAOfflineMapDownloadStatusProgress: return @"downloading";
case MAOfflineMapDownloadStatusCompleted: return @"unzip";
case MAOfflineMapDownloadStatusUnzip: return @"unzip";
case MAOfflineMapDownloadStatusFinished: return @"downloaded";
default: return @"";
}
}
- (NSString *)stateString:(MAOfflineItemStatus)code {
switch (code) {
case MAOfflineItemStatusCached: return @"downloading";
case MAOfflineItemStatusExpired: return @"expired";
case MAOfflineItemStatusInstalled: return @"downloaded";
default: return @"";
}
}
- (NSDictionary *)itemData:(MAOfflineCity *)city {
return @{
@"name": city.name,
@"size": @(city.size),
@"state": [self stateString:city.itemStatus],
};
}
- (NSArray<NSString *> *)supportedEvents {
return @[@"download"];
}
@end
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
RCT_ENUM_CONVERTER(MAMapType, (@{ RCT_ENUM_CONVERTER(MAMapType, (@{
@"standard": @(MAMapTypeStandard), @"standard": @(MAMapTypeStandard),
@"satellite": @(MAMapTypeSatellite), @"satellite": @(MAMapTypeSatellite),
@"navigation": @(MAMapTypeNavi),
@"night": @(MAMapTypeStandardNight),
@"bus": @(MAMapTypeBus),
}), MAMapTypeStandard, integerValue) }), MAMapTypeStandard, integerValue)
RCT_ENUM_CONVERTER(MAPinAnnotationColor, (@{ RCT_ENUM_CONVERTER(MAPinAnnotationColor, (@{
...@@ -37,6 +40,12 @@ RCT_ENUM_CONVERTER(MAPinAnnotationColor, (@{ ...@@ -37,6 +40,12 @@ RCT_ENUM_CONVERTER(MAPinAnnotationColor, (@{
return node; return node;
} }
+ (MAMultiPointItem *)MAMultiPointItem:(id)json {
MAMultiPointItem *item = [MAMultiPointItem new];
item.coordinate = [self CLLocationCoordinate2D:json];
return item;
}
+ (MACoordinateRegion)MACoordinateRegion:(id)json { + (MACoordinateRegion)MACoordinateRegion:(id)json {
return MACoordinateRegionMake( return MACoordinateRegionMake(
[self CLLocationCoordinate2D:json], [self CLLocationCoordinate2D:json],
...@@ -47,5 +56,6 @@ RCT_ENUM_CONVERTER(MAPinAnnotationColor, (@{ ...@@ -47,5 +56,6 @@ RCT_ENUM_CONVERTER(MAPinAnnotationColor, (@{
RCT_ARRAY_CONVERTER(Coordinate) RCT_ARRAY_CONVERTER(Coordinate)
RCT_ARRAY_CONVERTER(MAHeatMapNode) RCT_ARRAY_CONVERTER(MAHeatMapNode)
RCT_ARRAY_CONVERTER(MAMultiPointItem)
@end @end
...@@ -17,6 +17,11 @@ ...@@ -17,6 +17,11 @@
_circle.coordinate = coordinate; _circle.coordinate = coordinate;
} }
- (void)setRadius:(CLLocationDistance)radius {
_radius = radius;
_circle.radius = radius;
}
- (void)setStrokeWidth:(CGFloat)strokeWidth { - (void)setStrokeWidth:(CGFloat)strokeWidth {
_strokeWidth = strokeWidth; _strokeWidth = strokeWidth;
_renderer.lineWidth = strokeWidth; _renderer.lineWidth = strokeWidth;
...@@ -40,10 +45,6 @@ ...@@ -40,10 +45,6 @@
return _circle.boundingMapRect; return _circle.boundingMapRect;
} }
- (void)setRadius:(CLLocationDistance)radius {
_radius = radius;
}
- (MAOverlayRenderer *)renderer { - (MAOverlayRenderer *)renderer {
if (_strokeColor == nil) { if (_strokeColor == nil) {
_strokeColor = UIColor.blackColor; _strokeColor = UIColor.blackColor;
......
#import <MAMapKit/MAMapKit.h>
#import "AMapOverlay.h"
@interface AMapHeatMap : AMapOverlay
@end
#import "AMapHeatMap.h"
#pragma ide diagnostic ignored "OCUnusedMethodInspection"
@implementation AMapHeatMap {
NSArray<MAHeatMapNode *> *_data;
MATileOverlayRenderer *_renderer;
MAHeatMapTileOverlay *_heatMap;
NSInteger _radius;
CGFloat _opacity;
}
- (void)setCoordinates:(NSArray<MAHeatMapNode *> *)coordinates {
_data = coordinates;
}
- (void)setRadius:(NSInteger)radius {
_radius = radius;
}
- (void)setOpacity:(CGFloat)opacity {
_opacity = opacity;
}
- (MAOverlayRenderer *)renderer {
if (_renderer == nil) {
if (_opacity == 0) {
_opacity = 0.6;
}
if (_radius == 0) {
_radius = 12;
}
_heatMap = [MAHeatMapTileOverlay new];
_heatMap.data = _data;
_heatMap.opacity = _opacity;
_heatMap.radius = _radius;
_renderer = [[MATileOverlayRenderer alloc] initWithTileOverlay:_heatMap];
}
return _renderer;
}
@end
#import <MAMapKit/MAMapView.h>
#import <React/RCTViewManager.h>
#import "AMapHeatMap.h"
#pragma ide diagnostic ignored "OCUnusedClassInspection"
@interface AMapHeatMapManager : RCTViewManager
@end
@implementation AMapHeatMapManager {
}
RCT_EXPORT_MODULE()
- (UIView *)view {
return [AMapHeatMap new];
}
RCT_EXPORT_VIEW_PROPERTY(coordinates, MAHeatMapNodeArray)
RCT_EXPORT_VIEW_PROPERTY(radius, NSInteger)
RCT_EXPORT_VIEW_PROPERTY(opacity, CGFloat)
@end
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
@implementation AMapMarker { @implementation AMapMarker {
MAPointAnnotation *_annotation; MAPointAnnotation *_annotation;
MAAnnotationView *_annotationView; MAAnnotationView *_annotationView;
MACustomCalloutView *_calloutView;
UIView *_customView; UIView *_customView;
__weak AMapView *_mapView; __weak AMapView *_mapView;
MAPinAnnotationColor _pinColor; MAPinAnnotationColor _pinColor;
...@@ -114,21 +115,12 @@ ...@@ -114,21 +115,12 @@
- (MAAnnotationView *)annotationView { - (MAAnnotationView *)annotationView {
if (_annotationView == nil) { if (_annotationView == nil) {
if (_customView) { if (_customView) {
if ([_customView isKindOfClass:[AMapCallout class]]) { _customView.hidden = NO;
_customView.hidden = NO; _annotationView = [[MAAnnotationView alloc] initWithAnnotation:_annotation reuseIdentifier:nil];
_customView.center = CGPointMake(_customView.center.x, 200); _annotationView.bounds = _customView.bounds;
_annotationView = [[MAAnnotationView alloc] initWithAnnotation:_annotation reuseIdentifier:nil]; [_annotationView addSubview:_customView];
_annotationView.bounds = CGRectMake(_customView.bounds.origin.x, _customView.bounds.origin.y - 100, _customView.bounds.size.width + 100, _customView.bounds.size.height + 100);; [_annotationView addGestureRecognizer:[
[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(_handleTap:)]];
[_annotationView addSubview:_customView];
} else {
_customView.hidden = NO;
_annotationView = [[MAAnnotationView alloc] initWithAnnotation:_annotation reuseIdentifier:nil];
_annotationView.bounds = _customView.bounds;
[_annotationView addSubview:_customView];
[_annotationView addGestureRecognizer:[
[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(_handleTap:)]];
}
} else { } else {
_annotationView = [[MAPinAnnotationView alloc] initWithAnnotation:_annotation reuseIdentifier:nil]; _annotationView = [[MAPinAnnotationView alloc] initWithAnnotation:_annotation reuseIdentifier:nil];
((MAPinAnnotationView *) _annotationView).pinColor = _pinColor; ((MAPinAnnotationView *) _annotationView).pinColor = _pinColor;
...@@ -137,6 +129,7 @@ ...@@ -137,6 +129,7 @@
_annotationView.enabled = _enabled; _annotationView.enabled = _enabled;
_annotationView.canShowCallout = _canShowCallout; _annotationView.canShowCallout = _canShowCallout;
_annotationView.draggable = _draggable; _annotationView.draggable = _draggable;
_annotationView.customCalloutView = _calloutView;
_annotationView.centerOffset = _centerOffset; _annotationView.centerOffset = _centerOffset;
if (_zIndex) { if (_zIndex) {
...@@ -154,8 +147,8 @@ ...@@ -154,8 +147,8 @@
- (void)didAddSubview:(UIView *)subview { - (void)didAddSubview:(UIView *)subview {
if ([subview isKindOfClass:[AMapCallout class]]) { if ([subview isKindOfClass:[AMapCallout class]]) {
_customView = subview; _calloutView = [[MACustomCalloutView alloc] initWithCustomView:subview];
_customView.hidden = YES; _annotationView.customCalloutView = _calloutView;
} else { } else {
_customView = subview; _customView = subview;
_customView.hidden = YES; _customView.hidden = YES;
......
#import <React/RCTComponent.h>
#import <MAMapKit/MAMapKit.h>
#import "AMapOverlay.h"
@interface AMapMultiPoint : AMapOverlay <MAMultiPointOverlayRendererDelegate>
@property(nonatomic, copy) RCTBubblingEventBlock onItemPress;
@end
#import "AMapMultiPoint.h"
#pragma ide diagnostic ignored "OCUnusedMethodInspection"
@implementation AMapMultiPoint {
NSArray<MAMultiPointItem *> *_items;
MAMultiPointOverlayRenderer *_renderer;
MAMultiPointOverlay *_overlay;
UIImage *_image;
}
- (void)setPoints:(NSArray<MAMultiPointItem *> *)points {
_items = points;
}
- (void)setImage:(NSString *)name {
_image = [UIImage imageNamed:name];
}
- (MAOverlayRenderer *)renderer {
if (_renderer == nil) {
_overlay = [[MAMultiPointOverlay alloc] initWithMultiPointItems:_items];
_renderer = [[MAMultiPointOverlayRenderer alloc] initWithMultiPointOverlay:_overlay];
_renderer.delegate = self;
if (_image != nil) {
_renderer.icon = _image;
}
}
return _renderer;
}
- (void)multiPointOverlayRenderer:(MAMultiPointOverlayRenderer *)renderer didItemTapped:(MAMultiPointItem *)item {
self.onItemPress(@{
@"index": @([_items indexOfObject:item]),
});
}
@end
#import <MAMapKit/MAMapView.h>
#import <React/RCTViewManager.h>
#import "AMapMultiPoint.h"
#pragma ide diagnostic ignored "OCUnusedClassInspection"
@interface AMapMultiPointManager : RCTViewManager
@end
@implementation AMapMultiPointManager {
}
RCT_EXPORT_MODULE()
- (UIView *)view {
return [AMapMultiPoint new];
}
RCT_EXPORT_VIEW_PROPERTY(points, MAMultiPointItemArray)
RCT_EXPORT_VIEW_PROPERTY(image, NSString)
RCT_EXPORT_VIEW_PROPERTY(onItemPress, RCTBubblingEventBlock)
@end
#import <MAMapKit/MAMapKit.h>
#import "AMapOverlay.h"
#pragma ide diagnostic ignored "OCUnusedPropertyInspection"
@interface AMapPolyline : AMapOverlay
@property(nonatomic, readonly) CLLocationCoordinate2D coordinate;
@property(nonatomic, readonly) MAMapRect boundingMapRect;
@end
#import "AMapPolyline.h"
#import "Coordinate.h"
#pragma ide diagnostic ignored "OCUnusedMethodInspection"
@implementation AMapPolyline {
MAMultiPolyline *_polyline;
MAMultiColoredPolylineRenderer *_renderer;
CGFloat _width;
UIColor *_color;
NSArray *_colors;
BOOL _dashed;
BOOL _gradient;
}
- (instancetype)init {
if (self = [super init]) {
_polyline = [MAMultiPolyline polylineWithCoordinates:nil count:0 drawStyleIndexes:nil];
}
return self;
}
- (void)setCoordinates:(NSArray<Coordinate *> *)coordinates {
CLLocationCoordinate2D coords[coordinates.count];
for (NSUInteger i = 0; i < coordinates.count; i++) {
coords[i] = coordinates[i].coordinate;
}
[_polyline setPolylineWithCoordinates:coords count:coordinates.count];
}
- (void)setWidth:(CGFloat)width {
_width = width;
_renderer.lineWidth = width;
}
- (void)setColor:(UIColor *)color {
_color = color;
_renderer.strokeColor = color;
}
- (void)setColors:(NSArray *)colors {
// colors -> strokeColors
// egg: [black, black, black, white, white, black] => [black, white, black] + [3, 5]
NSMutableArray *strokeColors = [[NSMutableArray alloc] init];
NSMutableArray *indexs = [[NSMutableArray alloc] init];
if (colors.count > 0) {
UIColor *lastColor = [colors firstObject];
[strokeColors addObject:lastColor];
for (NSUInteger index = 1; index < colors.count; index++) {
UIColor *color = colors[index];
if (![color isEqual:lastColor]) {
[strokeColors addObject:color];
[indexs addObject:@(index)]; // index is the NEXT color
lastColor = color;
}
}
if (strokeColors.count == 1) {
[indexs addObject:@(colors.count)];
}
}
_colors = strokeColors;
_renderer.strokeColors = strokeColors;
// change polyline
[_polyline setDrawStyleIndexes:@[@(1), @(2)]];
}
- (void)setDashed:(BOOL)dashed {
_dashed = dashed;
_renderer.lineDash = dashed;
}
- (void)setGradient:(BOOL)gradient {
_gradient = gradient;
_renderer.gradient = gradient;
}
- (CLLocationCoordinate2D)coordinate {
return _polyline.coordinate;
}
- (MAMapRect)boundingMapRect {
return _polyline.boundingMapRect;
}
- (MAOverlayRenderer *)renderer {
if (_color == nil) {
_color = UIColor.blackColor;
}
if (_renderer == nil) {
_renderer = [[MAMultiColoredPolylineRenderer alloc] initWithMultiPolyline:_polyline];
_renderer.lineWidth = _width;
_renderer.strokeColor = _color;
_renderer.strokeColors = _colors;
_renderer.lineDash = _dashed;
_renderer.gradient = _gradient;
}
return _renderer;
}
@end
#import <MAMapKit/MAMapView.h>
#import <React/RCTViewManager.h>
#import "AMapPolyline.h"
#pragma ide diagnostic ignored "OCUnusedClassInspection"
@interface AMapPolylineManager : RCTViewManager
@end
@implementation AMapPolylineManager {
}
RCT_EXPORT_MODULE()
- (UIView *)view {
return [AMapPolyline new];
}
RCT_EXPORT_VIEW_PROPERTY(coordinates, CoordinateArray)
RCT_EXPORT_VIEW_PROPERTY(width, CGFloat)
RCT_EXPORT_VIEW_PROPERTY(color, UIColor)
RCT_EXPORT_VIEW_PROPERTY(dashed, BOOL)
RCT_EXPORT_VIEW_PROPERTY(gradient, BOOL)
RCT_EXPORT_VIEW_PROPERTY(colors, UIColorArray)
@end
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
@interface AMapView : MAMapView @interface AMapView : MAMapView
@property(nonatomic, copy) RCTBubblingEventBlock onLocation; @property(nonatomic, copy) RCTBubblingEventBlock onLocation;
@property(nonatomic, copy) RCTBubblingEventBlock onMapPress; @property(nonatomic, copy) RCTBubblingEventBlock onPress;
@property(nonatomic, copy) RCTBubblingEventBlock onLongPress; @property(nonatomic, copy) RCTBubblingEventBlock onLongPress;
@property(nonatomic, copy) RCTBubblingEventBlock onStatusChange; @property(nonatomic, copy) RCTBubblingEventBlock onStatusChange;
@property(nonatomic, copy) RCTBubblingEventBlock onStatusChangeComplete; @property(nonatomic, copy) RCTBubblingEventBlock onStatusChangeComplete;
...@@ -15,4 +15,4 @@ ...@@ -15,4 +15,4 @@
- (AMapMarker *)getMarker:(id <MAAnnotation>)annotation; - (AMapMarker *)getMarker:(id <MAAnnotation>)annotation;
@end @end
\ No newline at end of file
#import <React/UIView+React.h> #import <React/UIView+React.h>
#import "AMapView.h" #import "AMapView.h"
#import "AMapMarker.h" #import "AMapMarker.h"
#import "AMapOverlay.h" #import "AMapPolyline.h"
#import "LocationStyle.h" #import "LocationStyle.h"
#pragma ide diagnostic ignored "OCUnusedMethodInspection" #pragma ide diagnostic ignored "OCUnusedMethodInspection"
...@@ -9,18 +9,34 @@ ...@@ -9,18 +9,34 @@
@implementation AMapView { @implementation AMapView {
NSMutableDictionary *_markers; NSMutableDictionary *_markers;
MAUserLocationRepresentation *_locationStyle; MAUserLocationRepresentation *_locationStyle;
BOOL _isBoundsInit;
} }
- (instancetype)init { - (instancetype)init {
_isBoundsInit = NO;
_markers = [NSMutableDictionary new]; _markers = [NSMutableDictionary new];
self = [super init]; self = [super init];
return self; return self;
} }
- (void)setFrame:(CGRect)frame {
if (!_isBoundsInit) {
[super setFrame:frame];
}
}
- (void)setBounds:(CGRect)bounds {
_isBoundsInit = YES;
[super setBounds:bounds];
}
- (void)setShowsTraffic:(BOOL)shows { - (void)setShowsTraffic:(BOOL)shows {
self.showTraffic = shows; self.showTraffic = shows;
} }
- (void)setTiltEnabled:(BOOL)enabled {
self.rotateCameraEnabled = enabled;
}
- (void)setLocationEnabled:(BOOL)enabled { - (void)setLocationEnabled:(BOOL)enabled {
self.showsUserLocation = enabled; self.showsUserLocation = enabled;
...@@ -34,6 +50,13 @@ ...@@ -34,6 +50,13 @@
self.centerCoordinate = coordinate; self.centerCoordinate = coordinate;
} }
- (void)setTilt:(CGFloat)degree {
self.cameraDegree = degree;
}
- (void)setRotation:(CGFloat)degree {
self.rotationDegree = degree;
}
- (void)setLocationStyle:(LocationStyle *)locationStyle { - (void)setLocationStyle:(LocationStyle *)locationStyle {
if (!_locationStyle) { if (!_locationStyle) {
...@@ -84,10 +107,4 @@ ...@@ -84,10 +107,4 @@
return _markers[[@(annotation.hash) stringValue]]; return _markers[[@(annotation.hash) stringValue]];
} }
- (void)setFrame:(CGRect)frame{
if (CGRectGetWidth(frame) <= [UIScreen mainScreen].bounds.size.width) {
[super setFrame:frame];
}
}
@end @end
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#pragma ide diagnostic ignored "-Woverriding-method-mismatch" #pragma ide diagnostic ignored "-Woverriding-method-mismatch"
@interface AMapViewManager : RCTViewManager <MAMapViewDelegate> @interface AMapViewManager : RCTViewManager <MAMapViewDelegate>
@end @end
@implementation AMapViewManager @implementation AMapViewManager
...@@ -16,7 +15,6 @@ RCT_EXPORT_MODULE() ...@@ -16,7 +15,6 @@ RCT_EXPORT_MODULE()
- (UIView *)view { - (UIView *)view {
AMapView *mapView = [AMapView new]; AMapView *mapView = [AMapView new];
mapView.frame = [UIScreen mainScreen].bounds;
mapView.centerCoordinate = CLLocationCoordinate2DMake(39.9242, 116.3979); mapView.centerCoordinate = CLLocationCoordinate2DMake(39.9242, 116.3979);
mapView.zoomLevel = 10; mapView.zoomLevel = 10;
mapView.delegate = self; mapView.delegate = self;
...@@ -25,15 +23,20 @@ RCT_EXPORT_MODULE() ...@@ -25,15 +23,20 @@ RCT_EXPORT_MODULE()
RCT_EXPORT_VIEW_PROPERTY(locationEnabled, BOOL) RCT_EXPORT_VIEW_PROPERTY(locationEnabled, BOOL)
RCT_REMAP_VIEW_PROPERTY(showsCompass, showCompass, BOOL) RCT_REMAP_VIEW_PROPERTY(showsCompass, showCompass, BOOL)
RCT_EXPORT_VIEW_PROPERTY(showsScale, BOOL)
RCT_EXPORT_VIEW_PROPERTY(showsIndoorMap, BOOL)
RCT_EXPORT_VIEW_PROPERTY(showsLabels, BOOL)
RCT_EXPORT_VIEW_PROPERTY(showsTraffic, BOOL) RCT_EXPORT_VIEW_PROPERTY(showsTraffic, BOOL)
RCT_EXPORT_VIEW_PROPERTY(showsBuildings, BOOL) RCT_EXPORT_VIEW_PROPERTY(showsBuildings, BOOL)
RCT_EXPORT_VIEW_PROPERTY(zoomLevel, double) RCT_EXPORT_VIEW_PROPERTY(zoomLevel, CGFloat)
RCT_EXPORT_VIEW_PROPERTY(maxZoomLevel, CGFloat) RCT_EXPORT_VIEW_PROPERTY(maxZoomLevel, CGFloat)
RCT_EXPORT_VIEW_PROPERTY(minZoomLevel, CGFloat) RCT_EXPORT_VIEW_PROPERTY(minZoomLevel, CGFloat)
RCT_EXPORT_VIEW_PROPERTY(zoomEnabled, BOOL) RCT_EXPORT_VIEW_PROPERTY(zoomEnabled, BOOL)
RCT_EXPORT_VIEW_PROPERTY(scrollEnabled, BOOL) RCT_EXPORT_VIEW_PROPERTY(scrollEnabled, BOOL)
RCT_EXPORT_VIEW_PROPERTY(rotateEnabled, BOOL) RCT_EXPORT_VIEW_PROPERTY(rotateEnabled, BOOL)
RCT_EXPORT_VIEW_PROPERTY(tiltEnabled, BOOL)
RCT_EXPORT_VIEW_PROPERTY(mapType, MAMapType) RCT_EXPORT_VIEW_PROPERTY(mapType, MAMapType)
RCT_EXPORT_VIEW_PROPERTY(coordinate, CLLocationCoordinate2D)
RCT_EXPORT_VIEW_PROPERTY(limitRegion, MACoordinateRegion) RCT_EXPORT_VIEW_PROPERTY(limitRegion, MACoordinateRegion)
RCT_EXPORT_VIEW_PROPERTY(region, MACoordinateRegion) RCT_EXPORT_VIEW_PROPERTY(region, MACoordinateRegion)
RCT_EXPORT_VIEW_PROPERTY(tilt, CGFloat) RCT_EXPORT_VIEW_PROPERTY(tilt, CGFloat)
...@@ -41,53 +44,41 @@ RCT_EXPORT_VIEW_PROPERTY(rotation, CGFloat) ...@@ -41,53 +44,41 @@ RCT_EXPORT_VIEW_PROPERTY(rotation, CGFloat)
RCT_EXPORT_VIEW_PROPERTY(distanceFilter, CLLocationDistance) RCT_EXPORT_VIEW_PROPERTY(distanceFilter, CLLocationDistance)
RCT_EXPORT_VIEW_PROPERTY(locationStyle, LocationStyle) RCT_EXPORT_VIEW_PROPERTY(locationStyle, LocationStyle)
RCT_EXPORT_VIEW_PROPERTY(onPress, RCTBubblingEventBlock)
RCT_CUSTOM_VIEW_PROPERTY(touchEnable, BOOL, AMapViewManager){
((AMapView*)view).userInteractionEnabled = [json boolValue];
}
RCT_EXPORT_VIEW_PROPERTY(onMapPress, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onLongPress, RCTBubblingEventBlock) RCT_EXPORT_VIEW_PROPERTY(onLongPress, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onLocation, RCTBubblingEventBlock) RCT_EXPORT_VIEW_PROPERTY(onLocation, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onStatusChange, RCTBubblingEventBlock) RCT_EXPORT_VIEW_PROPERTY(onStatusChange, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onStatusChangeComplete, RCTBubblingEventBlock) RCT_EXPORT_VIEW_PROPERTY(onStatusChangeComplete, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(showsUserLocation, BOOL)
RCT_EXPORT_VIEW_PROPERTY(userTrackingMode, NSInteger)
RCT_CUSTOM_VIEW_PROPERTY(coordinate, MKCoordinateRegion, AMapViewManager){
NSLog(@"RCT_CUSTOM_VIEW_PROPERTY");
if(json[@"latitude"] && json[@"longitude"]){
double latitude = ((NSString*)json[@"latitude"]).doubleValue;
double longitude = ((NSString*)json[@"longitude"]).doubleValue;
CLLocationCoordinate2D location = CLLocationCoordinate2DMake(latitude, longitude);
[((AMapView*)view) setCenterCoordinate:location animated:NO];
}
}
RCT_EXPORT_METHOD(animateTo:(nonnull NSNumber *)reactTag params:(NSDictionary *)params duration:(NSInteger)duration) { RCT_EXPORT_METHOD(animateTo:(nonnull NSNumber *)reactTag params:(NSDictionary *)params duration:(NSInteger)duration) {
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) { [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
AMapView *mapView = (AMapView *) viewRegistry[reactTag]; AMapView *mapView = (AMapView *) viewRegistry[reactTag];
MAMapStatus *mapStatus = mapView.getMapStatus;
if (params[@"zoomLevel"]) {
mapStatus.zoomLevel = [params[@"zoomLevel"] floatValue];
}
if (params[@"coordinate"]) { if (params[@"coordinate"]) {
NSDictionary *coordinate = params[@"coordinate"]; NSDictionary *coordinate = params[@"coordinate"];
mapStatus.centerCoordinate = CLLocationCoordinate2DMake(
CLLocationCoordinate2D location = CLLocationCoordinate2DMake([coordinate[@"latitude"] doubleValue], [coordinate[@"latitude"] doubleValue],
[coordinate[@"longitude"] doubleValue]); [coordinate[@"longitude"] doubleValue]);
[mapView setCenterCoordinate:location animated:NO]; }
if (params[@"tilt"]) {
mapStatus.cameraDegree = [params[@"tilt"] floatValue];
}
if (params[@"rotation"]) {
mapStatus.rotationDegree = [params[@"rotation"] floatValue];
} }
[mapView setMapStatus:mapStatus animated:YES duration:duration / 1000.0];
}]; }];
} }
- (void)mapView:(AMapView *)mapView didSingleTappedAtCoordinate:(CLLocationCoordinate2D)coordinate { - (void)mapView:(AMapView *)mapView didSingleTappedAtCoordinate:(CLLocationCoordinate2D)coordinate {
if (mapView.onMapPress) { if (mapView.onPress) {
mapView.onMapPress(@{ mapView.onPress(@{
@"latitude": @(coordinate.latitude), @"latitude": @(coordinate.latitude),
@"longitude": @(coordinate.longitude), @"longitude": @(coordinate.longitude),
}); });
} }
} }
...@@ -128,8 +119,7 @@ RCT_EXPORT_METHOD(animateTo:(nonnull NSNumber *)reactTag params:(NSDictionary *) ...@@ -128,8 +119,7 @@ RCT_EXPORT_METHOD(animateTo:(nonnull NSNumber *)reactTag params:(NSDictionary *)
return nil; return nil;
} }
- (void)mapView:(AMapView *)mapView didAnnotationViewTapped:(MAAnnotationView *)view - (void)mapView:(AMapView *)mapView didSelectAnnotationView:(MAAnnotationView *)view {
{
AMapMarker *marker = [mapView getMarker:view.annotation]; AMapMarker *marker = [mapView getMarker:view.annotation];
if (marker.onPress) { if (marker.onPress) {
marker.onPress(nil); marker.onPress(nil);
...@@ -164,25 +154,28 @@ RCT_EXPORT_METHOD(animateTo:(nonnull NSNumber *)reactTag params:(NSDictionary *) ...@@ -164,25 +154,28 @@ RCT_EXPORT_METHOD(animateTo:(nonnull NSNumber *)reactTag params:(NSDictionary *)
- (void)mapViewRegionChanged:(AMapView *)mapView { - (void)mapViewRegionChanged:(AMapView *)mapView {
if (mapView.onStatusChange) { if (mapView.onStatusChange) {
MAMapStatus *status = mapView.getMapStatus;
MACoordinateRegion status = mapView.region;
mapView.onStatusChange(@{ mapView.onStatusChange(@{
@"latitude": @(status.center.latitude), @"zoomLevel": @(status.zoomLevel),
@"longitude": @(status.center.longitude), @"tilt": @(status.cameraDegree),
@"rotation": @(status.rotationDegree),
@"latitude": @(status.centerCoordinate.latitude),
@"longitude": @(status.centerCoordinate.longitude),
}); });
} }
} }
- (void)mapView:(AMapView *)mapView regionDidChangeAnimated:(BOOL)animated { - (void)mapView:(AMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
if (mapView.onStatusChangeComplete) { if (mapView.onStatusChangeComplete) {
MACoordinateRegion status = mapView.region; MAMapStatus *status = mapView.getMapStatus;
mapView.onStatusChangeComplete(@{ mapView.onStatusChangeComplete(@{
@"latitude": @(status.center.latitude), @"zoomLevel": @(status.zoomLevel),
@"longitude": @(status.center.longitude), @"tilt": @(status.cameraDegree),
@"latitudeDelta": @(status.span.latitudeDelta), @"rotation": @(status.rotationDegree),
@"longitudeDelta": @(status.span.longitudeDelta), @"latitude": @(status.centerCoordinate.latitude),
@"longitude": @(status.centerCoordinate.longitude),
@"latitudeDelta": @(mapView.region.span.latitudeDelta),
@"longitudeDelta": @(mapView.region.span.longitudeDelta),
}); });
} }
} }
......
...@@ -4,7 +4,7 @@ package = JSON.parse(File.read(File.join(__dir__, '../package.json'))) ...@@ -4,7 +4,7 @@ package = JSON.parse(File.read(File.join(__dir__, '../package.json')))
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = "react-native-amap-sdk" s.name = "react-native-amap-sdk"
s.version = "2.0.1" s.version = package['version']
s.summary = package['description'] s.summary = package['description']
s.description = <<-DESC s.description = <<-DESC
React Native apps are built using the React JS React Native apps are built using the React JS
...@@ -19,12 +19,12 @@ Pod::Spec.new do |s| ...@@ -19,12 +19,12 @@ Pod::Spec.new do |s|
beautiful and fast products with no compromises in beautiful and fast products with no compromises in
quality or capability. quality or capability.
DESC DESC
s.homepage = "http://git.terminus.io/reactnastive/RNAMapLocation" s.homepage = "http://gitlab.shop.hisense.com/wangduo3/react-native-amap-sdk.git"
s.license = package['license'] s.license = package['license']
s.author = "Jianglei" s.author = "Wind.Wang"
s.source = { :git => "git.terminus.io:reactnative/RNAMapLocation.git", :tag => "v#{s.version}" } s.source = { :git => "gitlab.shop.hisense.com/wangduo3/react-native-amap-sdk.git", :tag => "v#{s.version}" }
s.requires_arc = true s.requires_arc = true
s.platform = :ios, "7.0" s.platform = :ios, "8.0"
s.preserve_paths = "*.framework" s.preserve_paths = "*.framework"
s.subspec 'LocationAmap' do |ls| s.subspec 'LocationAmap' do |ls|
...@@ -35,8 +35,8 @@ Pod::Spec.new do |s| ...@@ -35,8 +35,8 @@ Pod::Spec.new do |s|
end end
s.subspec 'Map3dAmap' do |ms| s.subspec 'Map3dAmap' do |ms|
ms.source_files = 'map3damap/**/*.{h,m}' # ms.source_files = 'map3damap/**/*.{h,m}'
ms.dependency 'AMap2DMap', "~> 5.6.0" ms.dependency 'AMap3DMap', "~> 6.6.0"
end end
s.dependency 'React' s.dependency 'React'
......
...@@ -9,11 +9,15 @@ ...@@ -9,11 +9,15 @@
], ],
"name": "@hisense/react-native-amap-sdk", "name": "@hisense/react-native-amap-sdk",
"license": "MIT", "license": "MIT",
"author": "Allen.Chiang", "author": "Wind.Wang",
"version": "2.0.0", "version": "1.0.0",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"repository": {
"type": "git",
"url": "http://gitlab.shop.hisense.com/wangduo3/react-native-amap-sdk"
},
"keywords": [ "keywords": [
"react", "react",
"native", "native",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment