| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- /*
- * 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 <moonsunfall@aliyun.com>
- */
- 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 (
- <NativeAMap
- {...this.props}
- />
- )
- }
- 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
|