Commit b64dd204 authored by 7c00's avatar 7c00

添加更多类型标注

parent 6cc75801
......@@ -132,13 +132,12 @@ import MapView from 'react-native-amap3d'
### 自定义标记图片及信息窗体
```jsx
<Marker
image='flag'
coordinate={{
latitude: 39.706901,
longitude: 116.397972,
}}
>
const coordinate = {
latitude: 39.706901,
longitude: 116.397972,
}
<Marker image='flag' coordinate={coordinate}>
<View style={styles.customInfoWindow}>
<Text>自定义信息窗体</Text>
</View>
......@@ -151,13 +150,13 @@ import MapView from 'react-native-amap3d'
## 接口
请参考注释文档:
- [MapView](https://github.com/qiuxiang/react-native-amap3d/tree/v0.7.3/components/maps/MapView.js#L15)
- [Marker](https://github.com/qiuxiang/react-native-amap3d/tree/v0.7.3/components/maps/Marker.js#L8)
- [Polyline](https://github.com/qiuxiang/react-native-amap3d/tree/v0.7.3/components/maps/Polyline.js#L6)
- [Polygon](https://github.com/qiuxiang/react-native-amap3d/tree/v0.7.3/components/maps/Polygon.js#L6)
- [Circle](https://github.com/qiuxiang/react-native-amap3d/tree/v0.7.3/components/maps/Circle.js#L6)
- [HeatMap](https://github.com/qiuxiang/react-native-amap3d/tree/v0.7.3/components/maps/HeatMap.js#L6)
- [MultiPoint](https://github.com/qiuxiang/react-native-amap3d/tree/v0.7.3/components/maps/MultiPoint.js#L5)
- [MapView](https://github.com/qiuxiang/react-native-amap3d/tree/master/components/maps/MapView.js#L15)
- [Marker](https://github.com/qiuxiang/react-native-amap3d/tree/master/components/maps/Marker.js#L8)
- [Polyline](https://github.com/qiuxiang/react-native-amap3d/tree/master/components/maps/Polyline.js#L6)
- [Polygon](https://github.com/qiuxiang/react-native-amap3d/tree/master/components/maps/Polygon.js#L6)
- [Circle](https://github.com/qiuxiang/react-native-amap3d/tree/master/components/maps/Circle.js#L6)
- [HeatMap](https://github.com/qiuxiang/react-native-amap3d/tree/master/components/maps/HeatMap.js#L6)
- [MultiPoint](https://github.com/qiuxiang/react-native-amap3d/tree/master/components/maps/MultiPoint.js#L5)
## 关于问题反馈
......
declare module 'react-native' {
declare module.exports: any
}
\ No newline at end of file
}
declare module 'react-native/Libraries/vendor/emitter/EmitterSubscription' {
declare module.exports: any
}
// @flow
import { NativeModules, NativeEventEmitter } from 'react-native'
import type EmitterSubscription from 'react-native/Libraries/vendor/emitter/EmitterSubscription'
const { AMapOffline } = NativeModules
const eventEmitter = new NativeEventEmitter(AMapOffline)
export type State = 'waiting' | 'downloading' | 'unzip' | 'downloaded' | 'expired' | ''
export type City = {
name: string,
size: number,
state: State,
}
export type Province = {
cities: City[],
} | City
export type Callback = (state: {
name: string,
progress: number,
state: State,
}) => void
export default {
getProvinces: () => AMapOffline.getProvinces(),
getCities: () => AMapOffline.getCities(),
download: name => AMapOffline.download(name),
remove: name => AMapOffline.remove(name),
addDownloadListener: callback => eventEmitter.addListener('download', callback),
getProvinces: (): Promise<Province[]> => AMapOffline.getProvinces(),
getCities: (): Promise<City[]> => AMapOffline.getCities(),
download: (name: string) => AMapOffline.download(name),
remove: (name: string) => AMapOffline.remove(name),
addDownloadListener: (callback: Callback): EmitterSubscription => eventEmitter.addListener('download', callback),
}
......@@ -12,5 +12,5 @@ export default {
lng1: number,
lat2: number,
lng2: number,
) => AMapUtils.distance(lat1, lng1, lat2, lng2),
): Promise<number> => AMapUtils.distance(lat1, lng1, lat2, lng2),
}
......@@ -7,7 +7,7 @@ export default requireNativeComponent('AMapCircle', {
...ViewPropTypes,
/**
* 圆点
* 圆点坐标
*/
coordinate: LatLng.isRequired,
......
......@@ -10,12 +10,12 @@ export default requireNativeComponent('AMapHeatMap', {
...ViewPropTypes,
/**
* 节点
* 节点坐标
*/
coordinates: PropTypes.arrayOf(LatLng).isRequired,
/**
* 半径
* 半径(米)
*/
radius: PropTypes.number,
......
......@@ -5,7 +5,7 @@ import { requireNativeComponent, ViewPropTypes } from 'react-native'
import { LatLng, Region } from '../PropTypes'
import Component from '../Component'
type Target = {
export type MapStatus = {
zoomLevel?: number,
coordinate?: LatLng,
titl?: number,
......@@ -159,16 +159,31 @@ export default class MapView extends Component<any> {
/**
* 点击事件
*
* @param {{ nativeEvent: LatLng }}
*/
onPress: PropTypes.func,
/**
* 长按事件
*
* @param {{ nativeEvent: LatLng }}
*/
onLongPress: PropTypes.func,
/**
* 定位事件
*
* @param {{
* nativeEvent: {
* timestamp: number,
* speed: number,
* accuracy: number,
* altitude: number,
* longitude: number,
* latitude: number,
* }
* }}
*/
onLocation: PropTypes.func,
......@@ -184,11 +199,33 @@ export default class MapView extends Component<any> {
/**
* 地图状态变化事件
*
* @param {{
* nativeEvent: {
* longitude: number,
* latitude: number,
* rotation: number,
* zoomLevel: number,
* tilt: number,
* }
* }}
*/
onStatusChange: PropTypes.func,
/**
* 地图状态变化完成事件
*
* @param {{
* nativeEvent: {
* longitude: number,
* latitude: number,
* longitudeDelta: number,
* latitudeDelta: number,
* rotation: number,
* zoomLevel: number,
* tilt: number,
* }
* }}
*/
onStatusChangeComplete: PropTypes.func,
}
......@@ -198,7 +235,7 @@ export default class MapView extends Component<any> {
/**
* 动画过渡到某个状态(坐标、缩放级别、倾斜度、旋转角度)
*/
animateTo(target: Target, duration?: number = 500) {
animateTo(target: MapStatus, duration?: number = 500) {
this.sendCommand('animateTo', [target, duration])
}
......
/* eslint-disable class-methods-use-this */
// @flow
import React from 'react'
import PropTypes from 'prop-types'
import { Platform, requireNativeComponent, StyleSheet, ViewPropTypes, View } from 'react-native'
......@@ -11,7 +11,7 @@ const style = StyleSheet.create({
},
})
export default class Marker extends Component {
export default class Marker extends Component<any> {
static propTypes = {
...ViewPropTypes,
......@@ -149,16 +149,17 @@ export default class Marker extends Component {
}
name = 'AMapMarker'
icon: View = null
active() {
this.sendCommand('active')
}
lockToScreen(x, y) {
lockToScreen(x: number, y: number) {
this.sendCommand('lockToScreen', [x, y])
}
renderCustomMarker(icon) {
renderCustomMarker(icon: () => View) {
if (icon) {
this.icon = <View style={style.overlay}>{icon()}</View>
return this.icon
......@@ -166,7 +167,8 @@ export default class Marker extends Component {
return null
}
renderInfoWindow(view) {
/* eslint-disable class-methods-use-this */
renderInfoWindow(view: View) {
if (view) {
return <InfoWindow style={style.overlay}>{view}</InfoWindow>
}
......
// @flow
import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import { requireNativeComponent, ViewPropTypes } from 'react-native'
export default class MultiPoint extends PureComponent {
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<any> {
static propTypes = {
...ViewPropTypes,
/**
* 节点
*/
points: PropTypes.arrayOf(PropTypes.shape({
latitude: PropTypes.number.isRequired,
longitude: PropTypes.number.isRequired,
title: PropTypes.string,
subtitle: PropTypes.string,
})).isRequired,
points: PropTypes.arrayOf(Point).isRequired,
/**
* 图标
* 图标,只接受原生图片名字
*/
image: PropTypes.string,
/**
* 点击事件
*
* @param {Point}
*/
onItemPress: PropTypes.func,
}
onItemPress = ({ nativeEvent }) => {
onItemPress = ({ nativeEvent } : { nativeEvent: { index: number } }) => {
if (this.props.onItemPress) {
this.props.onItemPress(this.props.points[nativeEvent.index])
}
......
......@@ -7,7 +7,7 @@ export default requireNativeComponent('AMapPolygon', {
...ViewPropTypes,
/**
* 节点
* 节点坐标
*/
coordinates: PropTypes.arrayOf(LatLng).isRequired,
......
// @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 {
export default class Polyline extends PureComponent<any> {
static propTypes = {
...ViewPropTypes,
/**
* 节点
* 节点坐标
*/
coordinates: PropTypes.arrayOf(LatLng).isRequired,
......
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