| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- /*
- * 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
- } 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 (
- <NativeAMap
- {...this.props}
- />
- )
- }
- 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);
|