Loading android/src/main/java/cn/qiuxiang/react/amap3d/AMapView.kt +27 −1 Original line number Diff line number Diff line Loading @@ -2,14 +2,16 @@ package cn.qiuxiang.react.amap3d import android.view.View import com.amap.api.maps.AMap import com.amap.api.maps.CameraUpdateFactory import com.amap.api.maps.MapView import com.amap.api.maps.model.LatLng import com.amap.api.maps.model.Marker import com.amap.api.maps.model.MyLocationStyle import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.WritableMap import com.facebook.react.uimanager.ThemedReactContext import com.facebook.react.uimanager.events.RCTEventEmitter import com.facebook.react.views.view.ReactViewGroup class AMapView(context: ThemedReactContext) : MapView(context) { private val eventEmitter: RCTEventEmitter = context.getJSModule(RCTEventEmitter::class.java) Loading Loading @@ -120,4 +122,28 @@ class AMapView(context: ThemedReactContext) : MapView(context) { } } } val animateCallback = object: AMap.CancelableCallback { override fun onCancel() { TODO("not implemented") } override fun onFinish() { TODO("not implemented") } } fun animateToCoordinate(args: ReadableArray?) { val coordinate = args?.getMap(0)!! val duration = args.getInt(1) val cameraUpdate = CameraUpdateFactory.newLatLng(LatLng( coordinate.getDouble("latitude"), coordinate.getDouble("longitude"))) map.animateCamera(cameraUpdate, duration.toLong(), animateCallback) } fun animateToZoomLevel(args: ReadableArray?) { val zoomLevel = args?.getDouble(0)!! val duration = args.getInt(1) map.animateCamera(CameraUpdateFactory.zoomTo(zoomLevel.toFloat()), duration.toLong(), animateCallback) } } android/src/main/java/cn/qiuxiang/react/amap3d/AMapViewManager.kt +19 −0 Original line number Diff line number Diff line Loading @@ -4,12 +4,18 @@ import android.view.View import com.amap.api.maps.AMap import com.amap.api.maps.CameraUpdateFactory import com.amap.api.maps.model.LatLng import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.ReadableMap import com.facebook.react.uimanager.ThemedReactContext import com.facebook.react.uimanager.ViewGroupManager import com.facebook.react.uimanager.annotations.ReactProp internal class AMapViewManager : ViewGroupManager<AMapView>() { companion object { val ANIMATE_TO_COORDINATE = 1 val ANIMATE_TO_ZOOM_LEVEL = 2 } override fun getName(): String { return "AMapView" } Loading @@ -18,6 +24,19 @@ internal class AMapViewManager : ViewGroupManager<AMapView>() { return AMapView(reactContext) } override fun getCommandsMap(): Map<String, Int> { return mapOf( "animateToCoordinate" to ANIMATE_TO_COORDINATE, "animateToZoomLevel" to ANIMATE_TO_ZOOM_LEVEL) } override fun receiveCommand(overlay: AMapView, commandId: Int, args: ReadableArray?) { when (commandId) { ANIMATE_TO_COORDINATE -> overlay.animateToCoordinate(args) ANIMATE_TO_ZOOM_LEVEL -> overlay.animateToZoomLevel(args) } } override fun addView(mapView: AMapView, child: View, index: Int) { super.addView(mapView, child, index) when (child) { Loading components/MapView.js +22 −1 Original line number Diff line number Diff line import React, {PropTypes, Component} from 'react' import {requireNativeComponent, View} from 'react-native' import { requireNativeComponent, findNodeHandle, View, UIManager, } from 'react-native' import Marker from './Marker' import InfoWindow from './InfoWindow' import Overlay from './Overlay' Loading Loading @@ -142,6 +147,22 @@ class MapView extends Component { onLocation: React.PropTypes.func, } animateToCoordinate(coordinate, duration = 1000) { this._sendCommand('animateToCoordinate', [coordinate, duration]) } animateToZoomLevel(zoomLevel, duration = 1000) { this._sendCommand('animateToZoomLevel', [zoomLevel, duration]) } _sendCommand(command, params = null) { UIManager.dispatchViewManagerCommand( findNodeHandle(this), UIManager.AMapView.Commands[command], params, ) } render() { return <AMapView {...this.props}/> } Loading Loading
android/src/main/java/cn/qiuxiang/react/amap3d/AMapView.kt +27 −1 Original line number Diff line number Diff line Loading @@ -2,14 +2,16 @@ package cn.qiuxiang.react.amap3d import android.view.View import com.amap.api.maps.AMap import com.amap.api.maps.CameraUpdateFactory import com.amap.api.maps.MapView import com.amap.api.maps.model.LatLng import com.amap.api.maps.model.Marker import com.amap.api.maps.model.MyLocationStyle import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.WritableMap import com.facebook.react.uimanager.ThemedReactContext import com.facebook.react.uimanager.events.RCTEventEmitter import com.facebook.react.views.view.ReactViewGroup class AMapView(context: ThemedReactContext) : MapView(context) { private val eventEmitter: RCTEventEmitter = context.getJSModule(RCTEventEmitter::class.java) Loading Loading @@ -120,4 +122,28 @@ class AMapView(context: ThemedReactContext) : MapView(context) { } } } val animateCallback = object: AMap.CancelableCallback { override fun onCancel() { TODO("not implemented") } override fun onFinish() { TODO("not implemented") } } fun animateToCoordinate(args: ReadableArray?) { val coordinate = args?.getMap(0)!! val duration = args.getInt(1) val cameraUpdate = CameraUpdateFactory.newLatLng(LatLng( coordinate.getDouble("latitude"), coordinate.getDouble("longitude"))) map.animateCamera(cameraUpdate, duration.toLong(), animateCallback) } fun animateToZoomLevel(args: ReadableArray?) { val zoomLevel = args?.getDouble(0)!! val duration = args.getInt(1) map.animateCamera(CameraUpdateFactory.zoomTo(zoomLevel.toFloat()), duration.toLong(), animateCallback) } }
android/src/main/java/cn/qiuxiang/react/amap3d/AMapViewManager.kt +19 −0 Original line number Diff line number Diff line Loading @@ -4,12 +4,18 @@ import android.view.View import com.amap.api.maps.AMap import com.amap.api.maps.CameraUpdateFactory import com.amap.api.maps.model.LatLng import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.ReadableMap import com.facebook.react.uimanager.ThemedReactContext import com.facebook.react.uimanager.ViewGroupManager import com.facebook.react.uimanager.annotations.ReactProp internal class AMapViewManager : ViewGroupManager<AMapView>() { companion object { val ANIMATE_TO_COORDINATE = 1 val ANIMATE_TO_ZOOM_LEVEL = 2 } override fun getName(): String { return "AMapView" } Loading @@ -18,6 +24,19 @@ internal class AMapViewManager : ViewGroupManager<AMapView>() { return AMapView(reactContext) } override fun getCommandsMap(): Map<String, Int> { return mapOf( "animateToCoordinate" to ANIMATE_TO_COORDINATE, "animateToZoomLevel" to ANIMATE_TO_ZOOM_LEVEL) } override fun receiveCommand(overlay: AMapView, commandId: Int, args: ReadableArray?) { when (commandId) { ANIMATE_TO_COORDINATE -> overlay.animateToCoordinate(args) ANIMATE_TO_ZOOM_LEVEL -> overlay.animateToZoomLevel(args) } } override fun addView(mapView: AMapView, child: View, index: Int) { super.addView(mapView, child, index) when (child) { Loading
components/MapView.js +22 −1 Original line number Diff line number Diff line import React, {PropTypes, Component} from 'react' import {requireNativeComponent, View} from 'react-native' import { requireNativeComponent, findNodeHandle, View, UIManager, } from 'react-native' import Marker from './Marker' import InfoWindow from './InfoWindow' import Overlay from './Overlay' Loading Loading @@ -142,6 +147,22 @@ class MapView extends Component { onLocation: React.PropTypes.func, } animateToCoordinate(coordinate, duration = 1000) { this._sendCommand('animateToCoordinate', [coordinate, duration]) } animateToZoomLevel(zoomLevel, duration = 1000) { this._sendCommand('animateToZoomLevel', [zoomLevel, duration]) } _sendCommand(command, params = null) { UIManager.dispatchViewManagerCommand( findNodeHandle(this), UIManager.AMapView.Commands[command], params, ) } render() { return <AMapView {...this.props}/> } Loading