AMap-android.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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. } from 'react-native';
  17. import PropTypes from 'prop-types';
  18. const AMapManager = Platform.OS == 'ios' ? null : NativeModules.AMapModule;
  19. function isFunction(fn) {
  20. return typeof fn === 'function';
  21. }
  22. function safeCallback(callback) {
  23. return isFunction(callback) ? callback : function() {};
  24. }
  25. export default class AMap extends Component {
  26. static propTypes = {
  27. ...View.propTypes,
  28. frame: PropTypes.shape({
  29. width: PropTypes.number.isRequired,
  30. height: PropTypes.number.isRequired,
  31. }),
  32. mapViewType: PropTypes.number,
  33. customMapStyleFileName: PropTypes.string,
  34. showsUserLocation: PropTypes.bool,
  35. mapType: PropTypes.number,
  36. zoomLevel: PropTypes.number,
  37. centerCoordinate: PropTypes.shape({
  38. latitude: PropTypes.number.isRequired,
  39. longitude: PropTypes.number.isRequired,
  40. }),
  41. scaleControls: PropTypes.bool,
  42. tiltGestures: PropTypes.bool,
  43. rotateGestures: PropTypes.bool,
  44. infoWindowClass: PropTypes.string,
  45. onDidMoveByUser: PropTypes.func,
  46. onSingleTapped: PropTypes.func,
  47. onLongTapped: PropTypes.func,
  48. onMapZoomChange: PropTypes.func,
  49. onAnnotationDragChange: PropTypes.func,
  50. onAttachedToWindow: PropTypes.func,
  51. onAnnotationClick: PropTypes.func,
  52. onInfoWindowClick: PropTypes.func,
  53. circles: PropTypes.array,
  54. markers: PropTypes.array,
  55. polygons: PropTypes.array,
  56. polylines: PropTypes.array,
  57. region: PropTypes.object,
  58. bearing: PropTypes.number,
  59. tilt: PropTypes.number
  60. }
  61. constructor(props) {
  62. super(props)
  63. this.state = {}
  64. }
  65. render() {
  66. return (
  67. <NativeAMap
  68. {...this.props}
  69. />
  70. )
  71. }
  72. printCurrentMapShot(){
  73. AMapManager.printCurrentMapShot(findNodeHandle(this));
  74. }
  75. setCenterCoordinate(coordinate) {
  76. //console.log('findNodeHandle => ')
  77. //console.log(findNodeHandle)
  78. AMapManager.setCenterCoordinate(findNodeHandle(this), coordinate)
  79. }
  80. setRegion(region) {
  81. AMapManager.setRegion(findNodeHandle(this), region)
  82. }
  83. setRegionByLatLngs(region) {
  84. AMapManager.setRegionByLatLngs(findNodeHandle(this), region)
  85. }
  86. setLatLngZoom(config) {
  87. AMapManager.setLatLngZoom(findNodeHandle(this), config)
  88. }
  89. setMapType(mapType) {
  90. AMapManager.setMapType(findNodeHandle(this), mapType)
  91. }
  92. movieToUserLocation() {
  93. AMapManager.movieToUserLocation(findNodeHandle(this))
  94. }
  95. setZoomLevel(zoomLevel) {
  96. AMapManager.setZoomLevel(findNodeHandle(this), zoomLevel)
  97. }
  98. zoomLevel(callback) {
  99. AMapManager.zoomLevel(findNodeHandle(this), safeCallback(callback))
  100. }
  101. minZoomLevel(callback) {
  102. AMapManager.minZoomLevel(findNodeHandle(this), safeCallback(callback))
  103. }
  104. maxZoomLevel(callback) {
  105. AMapManager.maxZoomLevel(findNodeHandle(this), safeCallback(callback))
  106. }
  107. addAnnotation(annotationConfig, callback) {
  108. AMapManager.addAnnotation(findNodeHandle(this), annotationConfig, safeCallback(callback))
  109. }
  110. addAnnotations(annotationConfigs, callback) {
  111. AMapManager.addAnnotations(findNodeHandle(this), annotationConfigs, safeCallback(callback))
  112. }
  113. removeAnnotation(key) {
  114. AMapManager.removeAnnotation(findNodeHandle(this), key)
  115. }
  116. removeAnnotations(keys) {
  117. AMapManager.removeAnnotations(findNodeHandle(this), keys)
  118. }
  119. removeAllAnnotations(callback) {
  120. AMapManager.removeAllAnnotations(findNodeHandle(this),callback)
  121. }
  122. showInfoWindow(key) {
  123. AMapManager.showInfoWindow(findNodeHandle(this), key)
  124. }
  125. hideInfoWindow(key) {
  126. AMapManager.hideInfoWindow(findNodeHandle(this), key)
  127. }
  128. showAnnotation(key) {
  129. AMapManager.showAnnotation(findNodeHandle(this), key)
  130. }
  131. hideAnnotation(key) {
  132. AMapManager.hideAnnotation(findNodeHandle(this), key)
  133. }
  134. showAnnotations(keys) {
  135. AMapManager.showAnnotations(findNodeHandle(this), keys)
  136. }
  137. hideAnnotations(keys) {
  138. AMapManager.hideAnnotations(findNodeHandle(this), keys)
  139. }
  140. addCircle(circleConfig, callback) {
  141. AMapManager.addCircle(findNodeHandle(this), circleConfig, safeCallback(callback))
  142. }
  143. addCircles(circleConfigs, callback) {
  144. AMapManager.addCircles(findNodeHandle(this), circleConfigs, safeCallback(callback))
  145. }
  146. removeCircle(key) {
  147. AMapManager.removeCircle(findNodeHandle(this), key)
  148. }
  149. removeCircles(keys) {
  150. AMapManager.removeCircles(findNodeHandle(this), keys)
  151. }
  152. removeAllCircles(callback) {
  153. AMapManager.removeAllCircles(findNodeHandle(this),callback)
  154. }
  155. addPolyline(polylineConfig, callback) {
  156. AMapManager.addPolyline(findNodeHandle(this), polylineConfig, safeCallback(callback))
  157. }
  158. addPolylines(polylineConfigs, callback) {
  159. AMapManager.addPolylines(findNodeHandle(this), polylineConfigs, safeCallback(callback))
  160. }
  161. removePolyline(key) {
  162. AMapManager.removePolyline(findNodeHandle(this), key)
  163. }
  164. removePolylines(keys) {
  165. AMapManager.removePolylines(findNodeHandle(this), keys)
  166. }
  167. removeAllPolylines(callback) {
  168. AMapManager.removeAllPolylines(findNodeHandle(this),callback)
  169. }
  170. addPolygon(polygonConfig, callback) {
  171. AMapManager.addPolygon(findNodeHandle(this), polygonConfig, safeCallback(callback))
  172. }
  173. addPolygons(polygonConfigs, callback) {
  174. AMapManager.addPolygons(findNodeHandle(this), polygonConfigs, safeCallback(callback))
  175. }
  176. removePolygon(key) {
  177. AMapManager.removePolygon(findNodeHandle(this), key)
  178. }
  179. removePolygons(keys) {
  180. AMapManager.removePolygons(findNodeHandle(this), keys)
  181. }
  182. removeAllPolygons(callback) {
  183. AMapManager.removeAllPolygons(findNodeHandle(this),callback)
  184. }
  185. _Onsingletapped(event) {
  186. if (!this.props.onSingleTapped) {
  187. return;
  188. }
  189. this.props.onSingleTapped(event);
  190. }
  191. _onMapZoomChange(event) {
  192. if (!this.props.onMapZoomChange) {
  193. return;
  194. }
  195. this.props.onMapZoomChange(event);
  196. }
  197. _onAnnotationDragChange(event) {
  198. if (!this.props.onAnnotationDragChange) {
  199. return;
  200. }
  201. this.props.onAnnotationDragChange(event);
  202. }
  203. setBearing(degree){
  204. AMapManager.setBearing(findNodeHandle(this),degree);
  205. }
  206. setTilt(degree){
  207. AMapManager.setTilt(findNodeHandle(this),degree);
  208. }
  209. }
  210. export let AMapUtilityAndroid= {
  211. isLinesInCircle(center, radius, lines, callback) {
  212. AMapManager.isLinesInCircle(center, radius, lines, safeCallback(callback));
  213. }
  214. }
  215. export let AMapSearchAndroid= {
  216. searchPoiByCenterCoordinate(params) {
  217. AMapManager.searchPoiByCenterCoordinate(params) //传null为默认参数配置
  218. },
  219. searchPoiByUid(uid, callback) {
  220. AMapManager.searchPoiByUid(uid, safeCallback(callback));
  221. },
  222. reGoecodeSearch(params) {
  223. AMapManager.reGoecodeSearch(params)
  224. },
  225. OnPOISearchDoneEvent: AMapManager != null ? AMapManager.OnPOISearchDoneEvent : null,
  226. OnReGeocodeSearchDoneEvent: AMapManager != null ? AMapManager.OnReGeocodeSearchDoneEvent : null
  227. }
  228. const NativeAMap = Platform.OS == 'ios' ? View : requireNativeComponent('RCTAMapView', AMap);