/* * A smart AMap Library for react-native apps * https://github.com/react-native-component/react-native-smart-amap/ * Released under the MIT license * Copyright (c) 2016 react-native-component */ import React, { Component, } from 'react' import { View, requireNativeComponent, NativeModules, findNodeHandle, Platform, Event } from 'react-native'; import PropTypes from 'prop-types'; const AMapManager = Platform.OS == 'ios' ? NativeModules.AMap : null function isFunction(fn) { return typeof fn === 'function'; } function safeCallback(callback) { return isFunction(callback) ? callback : function() {}; } export default class AMap extends Component { static propTypes = { mapType: PropTypes.number, showsUserLocation: PropTypes.bool, bearing: PropTypes.number, tilt: PropTypes.number, centerCoordinate: PropTypes.shape({ latitude: PropTypes.number, longitude: PropTypes.number }), mapViewType: PropTypes.number, customMapStyleFileName: PropTypes.string, frame: PropTypes.shape({ width: PropTypes.number, height: PropTypes.number }).isRequired, zoomLevel: PropTypes.number, onDidMoveByUser: PropTypes.func, onSingleTapped: PropTypes.func, onLongTapped: PropTypes.func, onMapZoomChange: PropTypes.func, onAnnotationDragChange: PropTypes.func, onAnnotationClick: PropTypes.func, circles: PropTypes.array, markers: PropTypes.array, polygons: PropTypes.array, polylines: PropTypes.array, region: PropTypes.object } constructor(props) { super(props) this.state = {} } render() { return ( ) } setCenterCoordinate(coordinate) { AMapManager.setCenterCoordinate(findNodeHandle(this), coordinate) } setRegion(region) { AMapManager.setRegion(findNodeHandle(this), region) } setRegionByLatLngs(region) { AMapManager.setRegionByLatLngs(findNodeHandle(this), region) } movieToUserLocation() { AMapManager.movieToUserLocation(findNodeHandle(this)) } setBearing(degree) { AMapManager.setBearing(findNodeHandle(this), degree); } setTilt(degree) { AMapManager.setTilt(findNodeHandle(this), degree); } zoomLevel(callback) { AMapManager.zoomLevel(findNodeHandle(this), safeCallback(callback)) } minZoomLevel(callback) { AMapManager.minZoomLevel(findNodeHandle(this), safeCallback(callback)) } maxZoomLevel(callback) { AMapManager.maxZoomLevel(findNodeHandle(this), safeCallback(callback)) } addAnnotation(annotationConfig, callback) { AMapManager.addAnnotation(findNodeHandle(this), annotationConfig, safeCallback(callback)) } addAnnotations(annotationConfigs, callback) { AMapManager.addAnnotations(findNodeHandle(this), annotationConfigs, safeCallback(callback)) } removeAnnotation(key) { AMapManager.removeAnnotation(findNodeHandle(this), key) } removeAnnotations(keys) { AMapManager.removeAnnotations(findNodeHandle(this), keys) } removeAllAnnotations(callback) { AMapManager.removeAllAnnotations(findNodeHandle(this), safeCallback(callback)) } addCircle(circleConfig, callback) { AMapManager.addCircle(findNodeHandle(this), circleConfig, safeCallback(callback)) } addCircles(circleConfigs, callback) { AMapManager.addCircles(findNodeHandle(this), circleConfigs, safeCallback(callback)) } removeCircle(key) { AMapManager.removeCircle(findNodeHandle(this), key) } removeCircles(keys) { AMapManager.removeCircles(findNodeHandle(this), keys) } removeAllCircles(callback) { AMapManager.removeAllCircles(findNodeHandle(this), safeCallback(callback)) } addPolyline(polylineConfig, callback) { AMapManager.addPolyline(findNodeHandle(this), polylineConfig, safeCallback(callback)) } addPolylines(polylineConfigs, callback) { AMapManager.addPolylines(findNodeHandle(this), polylineConfigs, safeCallback(callback)) } removePolyline(key) { AMapManager.removePolyline(findNodeHandle(this), key) } removePolylines(keys) { AMapManager.removePolylines(findNodeHandle(this), keys) } removeAllPolylines(callback) { AMapManager.removeAllPolylines(findNodeHandle(this), safeCallback(callback)) } addPolygon(polygonConfig, callback) { AMapManager.addPolygon(findNodeHandle(this), polygonConfig, safeCallback(callback)) } addPolygons(polygonConfigs, callback) { AMapManager.addPolygons(findNodeHandle(this), polygonConfigs, safeCallback(callback)) } removePolygon(key) { AMapManager.removePolygon(findNodeHandle(this), key) } removePolygons(keys) { AMapManager.removePolygons(findNodeHandle(this), keys) } removeAllPolygons(callback) { AMapManager.removeAllPolygons(findNodeHandle(this), safeCallback(callback)) } } export let AMapUtilityIOS = { isLinesInCircle(center, radius, lines, callback) { AMapManager.isLinesInCircle(center, radius, lines, safeCallback(callback)); } } export let AMapSearchIOS = { searchPoiByCenterCoordinate(params) { AMapManager.searchPoiByCenterCoordinate(params) //传null为默认参数配置 }, searchPoiByUid(uid) { AMapManager.searchPoiByUid(uid) }, reGoecodeSearch(params) { AMapManager.reGoecodeSearch(params) }, OnPOISearchDoneEvent: AMapManager != null ? AMapManager.OnPOISearchDoneEvent : null, OnReGeocodeSearchDoneEvent: AMapManager != null ? AMapManager.OnReGeocodeSearchDoneEvent : null } const NativeAMap = Platform.OS == 'ios' ? requireNativeComponent('RCTAMap', AMap) : View