/* * 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 } from 'react-native'; import PropTypes from 'prop-types'; const AMapManager = Platform.OS == 'ios' ? null : NativeModules.AMapModule; function isFunction(fn) { return typeof fn === 'function'; } function safeCallback(callback) { return isFunction(callback) ? callback : function() {}; } export default class AMap extends Component { static propTypes = { ...View.propTypes, frame: PropTypes.shape({ width: PropTypes.number.isRequired, height: PropTypes.number.isRequired, }), mapViewType: PropTypes.number, customMapStyleFileName: PropTypes.string, showsUserLocation: PropTypes.bool, mapType: PropTypes.number, zoomLevel: PropTypes.number, centerCoordinate: PropTypes.shape({ latitude: PropTypes.number.isRequired, longitude: PropTypes.number.isRequired, }), scaleControls: PropTypes.bool, tiltGestures: PropTypes.bool, rotateGestures: PropTypes.bool, infoWindowClass: PropTypes.string, onDidMoveByUser: PropTypes.func, onSingleTapped: PropTypes.func, onLongTapped: PropTypes.func, onMapZoomChange: PropTypes.func, onAnnotationDragChange: PropTypes.func, onAttachedToWindow: PropTypes.func, onAnnotationClick: PropTypes.func, onInfoWindowClick: PropTypes.func, circles: PropTypes.array, markers: PropTypes.array, polygons: PropTypes.array, polylines: PropTypes.array, region: PropTypes.object, bearing: PropTypes.number, tilt: PropTypes.number } constructor(props) { super(props) this.state = {} } render() { return ( ) } printCurrentMapShot(){ AMapManager.printCurrentMapShot(findNodeHandle(this)); } setCenterCoordinate(coordinate) { //console.log('findNodeHandle => ') //console.log(findNodeHandle) AMapManager.setCenterCoordinate(findNodeHandle(this), coordinate) } setRegion(region) { AMapManager.setRegion(findNodeHandle(this), region) } setRegionByLatLngs(region) { AMapManager.setRegionByLatLngs(findNodeHandle(this), region) } setLatLngZoom(config) { AMapManager.setLatLngZoom(findNodeHandle(this), config) } setMapType(mapType) { AMapManager.setMapType(findNodeHandle(this), mapType) } movieToUserLocation() { AMapManager.movieToUserLocation(findNodeHandle(this)) } setZoomLevel(zoomLevel) { AMapManager.setZoomLevel(findNodeHandle(this), zoomLevel) } 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),callback) } showInfoWindow(key) { AMapManager.showInfoWindow(findNodeHandle(this), key) } hideInfoWindow(key) { AMapManager.hideInfoWindow(findNodeHandle(this), key) } showAnnotation(key) { AMapManager.showAnnotation(findNodeHandle(this), key) } hideAnnotation(key) { AMapManager.hideAnnotation(findNodeHandle(this), key) } showAnnotations(keys) { AMapManager.showAnnotations(findNodeHandle(this), keys) } hideAnnotations(keys) { AMapManager.hideAnnotations(findNodeHandle(this), keys) } 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),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),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),callback) } _Onsingletapped(event) { if (!this.props.onSingleTapped) { return; } this.props.onSingleTapped(event); } _onMapZoomChange(event) { if (!this.props.onMapZoomChange) { return; } this.props.onMapZoomChange(event); } _onAnnotationDragChange(event) { if (!this.props.onAnnotationDragChange) { return; } this.props.onAnnotationDragChange(event); } setBearing(degree){ AMapManager.setBearing(findNodeHandle(this),degree); } setTilt(degree){ AMapManager.setTilt(findNodeHandle(this),degree); } } export let AMapUtilityAndroid= { isLinesInCircle(center, radius, lines, callback) { AMapManager.isLinesInCircle(center, radius, lines, safeCallback(callback)); } } export let AMapSearchAndroid= { searchPoiByCenterCoordinate(params) { AMapManager.searchPoiByCenterCoordinate(params) //传null为默认参数配置 }, searchPoiByUid(uid, callback) { AMapManager.searchPoiByUid(uid, safeCallback(callback)); }, reGoecodeSearch(params) { AMapManager.reGoecodeSearch(params) }, OnPOISearchDoneEvent: AMapManager != null ? AMapManager.OnPOISearchDoneEvent : null, OnReGeocodeSearchDoneEvent: AMapManager != null ? AMapManager.OnReGeocodeSearchDoneEvent : null } const NativeAMap = Platform.OS == 'ios' ? View : requireNativeComponent('RCTAMapView', AMap);