AMap-ios.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*
  2. * A smart AMap Library for react-native apps
  3. * https://github.com/react-native-component/react-native-smart-amap/
  4. * Released under the MIT license
  5. * Copyright (c) 2016 react-native-component <moonsunfall@aliyun.com>
  6. */
  7. import React, {
  8. Component,
  9. } from 'react'
  10. import {
  11. View,
  12. requireNativeComponent,
  13. NativeModules,
  14. findNodeHandle,
  15. Platform,
  16. Event
  17. } from 'react-native';
  18. import PropTypes from 'prop-types';
  19. const AMapManager = Platform.OS == 'ios' ? NativeModules.AMap : null
  20. function isFunction(fn) {
  21. return typeof fn === 'function';
  22. }
  23. function safeCallback(callback) {
  24. return isFunction(callback) ? callback : function() {};
  25. }
  26. export default class AMap extends Component {
  27. static propTypes = {
  28. mapType: PropTypes.number,
  29. showsUserLocation: PropTypes.bool,
  30. bearing: PropTypes.number,
  31. tilt: PropTypes.number,
  32. centerCoordinate: PropTypes.shape({
  33. latitude: PropTypes.number,
  34. longitude: PropTypes.number
  35. }),
  36. mapViewType: PropTypes.number,
  37. customMapStyleFileName: PropTypes.string,
  38. frame: PropTypes.shape({
  39. width: PropTypes.number,
  40. height: PropTypes.number
  41. }).isRequired,
  42. zoomLevel: PropTypes.number,
  43. onDidMoveByUser: PropTypes.func,
  44. onSingleTapped: PropTypes.func,
  45. onLongTapped: PropTypes.func,
  46. onMapZoomChange: PropTypes.func,
  47. onAnnotationDragChange: PropTypes.func,
  48. onAnnotationClick: PropTypes.func,
  49. circles: PropTypes.array,
  50. markers: PropTypes.array,
  51. polygons: PropTypes.array,
  52. polylines: PropTypes.array,
  53. region: PropTypes.object
  54. }
  55. constructor(props) {
  56. super(props)
  57. this.state = {}
  58. }
  59. render() {
  60. return (
  61. <NativeAMap
  62. {...this.props}
  63. />
  64. )
  65. }
  66. setCenterCoordinate(coordinate) {
  67. AMapManager.setCenterCoordinate(findNodeHandle(this), coordinate)
  68. }
  69. setRegion(region) {
  70. AMapManager.setRegion(findNodeHandle(this), region)
  71. }
  72. setRegionByLatLngs(region) {
  73. AMapManager.setRegionByLatLngs(findNodeHandle(this), region)
  74. }
  75. movieToUserLocation() {
  76. AMapManager.movieToUserLocation(findNodeHandle(this))
  77. }
  78. setBearing(degree) {
  79. AMapManager.setBearing(findNodeHandle(this), degree);
  80. }
  81. setTilt(degree) {
  82. AMapManager.setTilt(findNodeHandle(this), degree);
  83. }
  84. zoomLevel(callback) {
  85. AMapManager.zoomLevel(findNodeHandle(this), safeCallback(callback))
  86. }
  87. minZoomLevel(callback) {
  88. AMapManager.minZoomLevel(findNodeHandle(this), safeCallback(callback))
  89. }
  90. maxZoomLevel(callback) {
  91. AMapManager.maxZoomLevel(findNodeHandle(this), safeCallback(callback))
  92. }
  93. addAnnotation(annotationConfig, callback) {
  94. AMapManager.addAnnotation(findNodeHandle(this), annotationConfig, safeCallback(callback))
  95. }
  96. addAnnotations(annotationConfigs, callback) {
  97. AMapManager.addAnnotations(findNodeHandle(this), annotationConfigs, safeCallback(callback))
  98. }
  99. removeAnnotation(key) {
  100. AMapManager.removeAnnotation(findNodeHandle(this), key)
  101. }
  102. removeAnnotations(keys) {
  103. AMapManager.removeAnnotations(findNodeHandle(this), keys)
  104. }
  105. removeAllAnnotations(callback) {
  106. AMapManager.removeAllAnnotations(findNodeHandle(this), safeCallback(callback))
  107. }
  108. addCircle(circleConfig, callback) {
  109. AMapManager.addCircle(findNodeHandle(this), circleConfig, safeCallback(callback))
  110. }
  111. addCircles(circleConfigs, callback) {
  112. AMapManager.addCircles(findNodeHandle(this), circleConfigs, safeCallback(callback))
  113. }
  114. removeCircle(key) {
  115. AMapManager.removeCircle(findNodeHandle(this), key)
  116. }
  117. removeCircles(keys) {
  118. AMapManager.removeCircles(findNodeHandle(this), keys)
  119. }
  120. removeAllCircles(callback) {
  121. AMapManager.removeAllCircles(findNodeHandle(this), safeCallback(callback))
  122. }
  123. addPolyline(polylineConfig, callback) {
  124. AMapManager.addPolyline(findNodeHandle(this), polylineConfig, safeCallback(callback))
  125. }
  126. addPolylines(polylineConfigs, callback) {
  127. AMapManager.addPolylines(findNodeHandle(this), polylineConfigs, safeCallback(callback))
  128. }
  129. removePolyline(key) {
  130. AMapManager.removePolyline(findNodeHandle(this), key)
  131. }
  132. removePolylines(keys) {
  133. AMapManager.removePolylines(findNodeHandle(this), keys)
  134. }
  135. removeAllPolylines(callback) {
  136. AMapManager.removeAllPolylines(findNodeHandle(this), safeCallback(callback))
  137. }
  138. addPolygon(polygonConfig, callback) {
  139. AMapManager.addPolygon(findNodeHandle(this), polygonConfig, safeCallback(callback))
  140. }
  141. addPolygons(polygonConfigs, callback) {
  142. AMapManager.addPolygons(findNodeHandle(this), polygonConfigs, safeCallback(callback))
  143. }
  144. removePolygon(key) {
  145. AMapManager.removePolygon(findNodeHandle(this), key)
  146. }
  147. removePolygons(keys) {
  148. AMapManager.removePolygons(findNodeHandle(this), keys)
  149. }
  150. removeAllPolygons(callback) {
  151. AMapManager.removeAllPolygons(findNodeHandle(this), safeCallback(callback))
  152. }
  153. }
  154. export let AMapUtilityIOS = {
  155. isLinesInCircle(center, radius, lines, callback) {
  156. AMapManager.isLinesInCircle(center, radius, lines, safeCallback(callback));
  157. }
  158. }
  159. export let AMapSearchIOS = {
  160. searchPoiByCenterCoordinate(params) {
  161. AMapManager.searchPoiByCenterCoordinate(params) //传null为默认参数配置
  162. },
  163. searchPoiByUid(uid) {
  164. AMapManager.searchPoiByUid(uid)
  165. },
  166. reGoecodeSearch(params) {
  167. AMapManager.reGoecodeSearch(params)
  168. },
  169. OnPOISearchDoneEvent: AMapManager != null ? AMapManager.OnPOISearchDoneEvent : null,
  170. OnReGeocodeSearchDoneEvent: AMapManager != null ? AMapManager.OnReGeocodeSearchDoneEvent : null
  171. }
  172. const NativeAMap = Platform.OS == 'ios' ? requireNativeComponent('RCTAMap', AMap) : View