Commit b29650e5 authored by Qiu Xiang's avatar Qiu Xiang
Browse files

完善 android 动画移动接口

parent f5195cca
Loading
Loading
Loading
Loading
+25 −10
Original line number Original line Diff line number Diff line
@@ -4,11 +4,13 @@ import android.view.View
import com.amap.api.maps.AMap
import com.amap.api.maps.AMap
import com.amap.api.maps.CameraUpdateFactory
import com.amap.api.maps.CameraUpdateFactory
import com.amap.api.maps.MapView
import com.amap.api.maps.MapView
import com.amap.api.maps.model.CameraPosition
import com.amap.api.maps.model.LatLng
import com.amap.api.maps.model.LatLng
import com.amap.api.maps.model.Marker
import com.amap.api.maps.model.Marker
import com.amap.api.maps.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.WritableMap
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
@@ -139,17 +141,30 @@ class AMapView(context: ThemedReactContext) : MapView(context) {
        }
        }
    }
    }


    fun animateToCoordinate(args: ReadableArray?) {
    fun animateTo(args: ReadableArray?) {
        val coordinate = args?.getMap(0)!!
        val currentCameraPosition = map.cameraPosition
        val target = args?.getMap(0)!!
        val duration = args.getInt(1)
        val duration = args.getInt(1)
        val cameraUpdate = CameraUpdateFactory.newLatLng(LatLng(

                coordinate.getDouble("latitude"), coordinate.getDouble("longitude")))
        var coordinate = currentCameraPosition.target
        map.animateCamera(cameraUpdate, duration.toLong(), animateCallback)
        var zoomLevel = currentCameraPosition.zoom
        var tilt = currentCameraPosition.tilt

        if (target.hasKey("coordinate")) {
            val json = target.getMap("coordinate")
            coordinate = LatLng(json.getDouble("latitude"), json.getDouble("longitude"))
        }
        }


    fun animateToZoomLevel(args: ReadableArray?) {
        if (target.hasKey("zoomLevel")) {
        val zoomLevel = args?.getDouble(0)!!
            zoomLevel = target.getDouble("zoomLevel").toFloat()
        val duration = args.getInt(1)
        }
        map.animateCamera(CameraUpdateFactory.zoomTo(zoomLevel.toFloat()), duration.toLong(), animateCallback)

        if (target.hasKey("tilt")) {
            tilt = target.getDouble("tilt").toFloat()
        }

        val cameraUpdate = CameraUpdateFactory.newCameraPosition(CameraPosition(
                coordinate, zoomLevel, tilt, currentCameraPosition.bearing))
        map.animateCamera(cameraUpdate, duration.toLong(), animateCallback)
    }
    }
}
}
+3 −5
Original line number Original line Diff line number Diff line
@@ -15,6 +15,7 @@ internal class AMapViewManager : ViewGroupManager<AMapView>() {
    companion object {
    companion object {
        val ANIMATE_TO_COORDINATE = 1
        val ANIMATE_TO_COORDINATE = 1
        val ANIMATE_TO_ZOOM_LEVEL = 2
        val ANIMATE_TO_ZOOM_LEVEL = 2
        val ANIMATE_TO = 3
    }
    }


    override fun getName(): String {
    override fun getName(): String {
@@ -26,15 +27,12 @@ internal class AMapViewManager : ViewGroupManager<AMapView>() {
    }
    }


    override fun getCommandsMap(): Map<String, Int> {
    override fun getCommandsMap(): Map<String, Int> {
        return mapOf(
        return mapOf("animateTo" to ANIMATE_TO)
                "animateToCoordinate" to ANIMATE_TO_COORDINATE,
                "animateToZoomLevel" to ANIMATE_TO_ZOOM_LEVEL)
    }
    }


    override fun receiveCommand(overlay: AMapView, commandId: Int, args: ReadableArray?) {
    override fun receiveCommand(overlay: AMapView, commandId: Int, args: ReadableArray?) {
        when (commandId) {
        when (commandId) {
            ANIMATE_TO_COORDINATE -> overlay.animateToCoordinate(args)
            ANIMATE_TO -> overlay.animateTo(args)
            ANIMATE_TO_ZOOM_LEVEL -> overlay.animateToZoomLevel(args)
        }
        }
    }
    }


+16 −14
Original line number Original line Diff line number Diff line
import React, {PropTypes, Component} from 'react'
import React, {PropTypes, Component} from 'react'
import {
import {
  requireNativeComponent,
  findNodeHandle,
  View,
  View,
  UIManager,
  UIManager,
  findNodeHandle,
  requireNativeComponent,
} from 'react-native'
} from 'react-native'
import {LatLng} from './PropTypes'
import {LatLng} from './PropTypes'
import Marker from './Marker'
import Marker from './Marker'
@@ -17,7 +17,7 @@ class MapView extends Component {
    ...View.propTypes,
    ...View.propTypes,


    /**
    /**
     * 设置地图类型
     * 地图类型
     *
     *
     * - standard: 标准地图
     * - standard: 标准地图
     * - satellite: 卫星地图
     * - satellite: 卫星地图
@@ -78,27 +78,27 @@ class MapView extends Component {
    showsTraffic: PropTypes.bool,
    showsTraffic: PropTypes.bool,


    /**
    /**
     * 设置最大缩放级别
     * 最大缩放级别
     */
     */
    maxZoomLevel: PropTypes.number,
    maxZoomLevel: PropTypes.number,


    /**
    /**
     * 设置最小缩放级别
     * 最小缩放级别
     */
     */
    minZoomLevel: PropTypes.number,
    minZoomLevel: PropTypes.number,


    /**
    /**
     * 设置当前缩放级别,取值范围 [3, 20]
     * 当前缩放级别,取值范围 [3, 20]
     */
     */
    zoomLevel: PropTypes.number,
    zoomLevel: PropTypes.number,


    /**
    /**
     * 设置中心坐标
     * 中心坐标
     */
     */
    coordinate: LatLng,
    coordinate: LatLng,


    /**
    /**
     * 设置倾斜角度,取值范围 [0, 60]
     * 倾斜角度,取值范围 [0, 60]
     */
     */
    tilt: PropTypes.number,
    tilt: PropTypes.number,


@@ -148,12 +148,14 @@ class MapView extends Component {
    onAnimateCancel: React.PropTypes.func,
    onAnimateCancel: React.PropTypes.func,
  }
  }


  animateToCoordinate(coordinate, duration = 1000) {
  /**
    this._sendCommand('animateToCoordinate', [coordinate, duration])
   * 动画过渡到某个位置(坐标、缩放级别、倾斜度)
  }
   *

   * @param {{zoomLevel: ?number, coordinate: ?LatLng, titl: ?number}} target
  animateToZoomLevel(zoomLevel, duration = 1000) {
   * @param duration
    this._sendCommand('animateToZoomLevel', [zoomLevel, duration])
   */
  animateTo(target, duration = 1000) {
    this._sendCommand('animateTo', [target, duration])
  }
  }


  _sendCommand(command, params = null) {
  _sendCommand(command, params = null) {
+8 −10
Original line number Original line Diff line number Diff line
# Project-wide Gradle settings.
## Project-wide Gradle settings.

#
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# http://www.gradle.org/docs/current/userguide/build_environment.html

#
# Specifies the JVM arguments used for the daemon process.
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

#
# When configured, Gradle will run in incubating parallel mode.
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# org.gradle.parallel=true

#Wed Jun 28 18:08:07 CST 2017
systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=8123
android.useDeprecatedNdk=true
android.useDeprecatedNdk=true
+1 −0
Original line number Original line Diff line number Diff line
@@ -4,6 +4,7 @@
    "init": "rm -r node_modules/react-native-amap3d; mkdir node_modules/react-native-amap3d; cp -r ../components node_modules/react-native-amap3d; cp -r ../package.json node_modules/react-native-amap3d",
    "init": "rm -r node_modules/react-native-amap3d; mkdir node_modules/react-native-amap3d; cp -r ../components node_modules/react-native-amap3d; cp -r ../package.json node_modules/react-native-amap3d",
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "android": "node node_modules/react-native/local-cli/cli.js run-android",
    "android": "node node_modules/react-native/local-cli/cli.js run-android",
    "android-log": "node node_modules/react-native/local-cli/cli.js log-android",
    "ios": "node node_modules/react-native/local-cli/cli.js run-ios"
    "ios": "node node_modules/react-native/local-cli/cli.js run-ios"
  },
  },
  "dependencies": {
  "dependencies": {
Loading