定位工具封装和使用LocationCtrlimportReact, {useState, useEffect}from'react';import{View,Text,ScrollView,StyleSheet,DeviceEventEmitter}from'react-native';import{Button,List,Switch}from'@ant-design/react-native';import{LocationCtrl,LayerManager,MapManager,MapView,LocationEventType,AutoPanMode,LocationCtrl2,LocationEventType2,}from'@haibalai/react-native-arcgis';import{connect}from'react-redux';importWidthDrawerfrom'../../../../components/WithDrawer/index';import{Colors}from'react-native/Libraries/NewAppScreen';import{PermissionsUtil}from'../../../../../nativeModules/util/PermissionsUtil';constMapId='baseMap';constGraphicLayerId='graphic点';constMapImageLayerId='水闸-MapImageLayer';constFeatureLayerId='水闸-featurelayer';constMapImageLayerIds= ['水闸-MapImageLayer','原水管线-MapImageLayer','海堤-MapImageLayer','海洋环境区划-MapImageLayer',];constFeatureLayerIds= ['水闸-featurelayer','原水管线-featurelayer','原水管线-featurelayer','海洋环境区划-featurelayer',];constGraphicLayerIds= ['graphic点','graphic线','graphic面'];constGeoX=1.2664272368526626e7;constGeoY=2595847.2157473154;constGeo4490X=113.78868474700005;constGeo4490Y=22.693641836999973;constlocationEventType =LocationEventType.onLocationChanged;letlistenerId ='';letdisplayMode =AutoPanMode.COMPASS_NAVIGATION;constsymbolStr ='';constimageBse64 ='iVBORw0KGgoAAAANSUhEUgAAAFQAAABUCAYAAAAcaxDBAAAABHNCSVQICAgIfAhkiAAADgtJREFUeJy9nF9MXFUex7/MwDBU2g5CA10FTGNbXaRU7YqEAE/2QZA+GLNJG9jGyr60jTHpJhLbXS3dBzchmoj7YE21Je3DbrKbrjjJusmmTIOBFjVQsl1atsnQGgbDX4sw1Q7sQznDmXN/v3POvTP4TU7uuf/OOfczv9/5d8+dLPx8ysrwPSse0vNyjyt5echM57EeZTCBWzew6wlUlzZ3Lp3ycJB08DIOdj2A2sKirjMdcwPN9pjuuGtlEqgNoCyXcRutuIxT+6bj1soEUJNFmsBxWxtR0NStbZxL15XSAWoL0gRxPYBycNcdrFegJvfWgVLPebVUHTSbOJcOl4+VMtU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2zViaAmtIygXILUpaNddlCSwuk0Hp8k6IDYgPLzYO5cdeMujan9fzIxwQvU96hA+L1nGdl0uXTzSMTZbGBtC4ghf4PMbnq5XFFjogAAAAASUVORK5CYII=';constdelay =100;constperiod =10000;constenable =true;constenableShow =false;constopacity =0.5;constisShow =false;lettmpLocateListener: any =null;constinitScale =1000;//测试初始比例尺constpermissions = ['android.permission.ACCESS_FINE_LOCATION','android.permission.ACCESS_COARSE_LOCATION'];/** sideBar组件*@param{*} renderCb renderCb是一个函数, 每次触发并且向里面传值(对象),content组件就以sideBarData的属性去接受*/constSideBar= ({renderCb, Home}: any) => {const[content, changeContent] =useState('');const[errorContent, changeErrorContent] =useState('');const[singleMapImageLayerStatus, setSingleMapImageLayerStatus] =useState(false);const[multiMapImageLayerStatus, setMultiMapImageLayerStatus] =useState(false);const[singleFeatureLayerStatus, setSingleFeatureStatus] =useState(false);const[multiFeatureLayerStatus, setMultiFeatureLayerStatus] =useState(false);const[singleGraphicLayerStatus, setSingleGraphicLayerStatus] =useState(false);const[multiGraphicLayerStatus, setMultiGraphicLayerStatus] =useState(false);useEffect(() =>{renderCb({content, errorContent});}, [content, errorContent, renderCb]);constgetGeoX= () => {letcoordinate =Home.coordinate;if(coordinate ==='4490') {returnGeo4490X;}else{returnGeoX;}};constgetGeoY= () => {letcoordinate =Home.coordinate;if(coordinate ==='4490') {returnGeo4490Y;}else{returnGeoY;}};constonSwitchSingleMapImageLayer= (e: boolean) => {if(e) {LayerManager.showLayer(MapId,MapImageLayerId);}else{LayerManager.hideLayer(MapId,MapImageLayerId);}setSingleMapImageLayerStatus(e);};constonSwitchMultiMapImageLayer= (e: boolean) => {if(e) {LayerManager.showLayers(MapId,MapImageLayerIds);}else{LayerManager.hideLayers(MapId,MapImageLayerIds);}setMultiMapImageLayerStatus(e);};constonSwitchSingleFeatureLayer= (e: boolean) => {if(e) {LayerManager.showLayer(MapId,FeatureLayerId);}else{LayerManager.hideLayer(MapId,FeatureLayerId);}setSingleFeatureStatus(e);};constonSwitchMultiFeatureLayer= (e: boolean) => {if(e) {LayerManager.showLayers(MapId,FeatureLayerIds);}else{LayerManager.hideLayers(MapId,FeatureLayerIds);}setMultiFeatureLayerStatus(e);};constonSwitchSingleGraphicLayer= (e: boolean) => {setSingleGraphicLayerStatus(e);//加载单个图层的graphics};constonSwitchMultiGraphicLayer= (e: boolean) => {setMultiGraphicLayerStatus(e);//加载多个图层的graphics};constonStartAsyncNotShow= () => {LocationCtrl.startAsync(MapId,false).then((r: any) =>{changeErrorContent('');changeContent(r);}).catch((e: any) =>{changeErrorContent(e);});};constonCheckPermissions= () => {PermissionsUtil.checkPermissions(permissions).then((r: any) =>{console.log(r,'当前请求定位权限结果状态!');changeErrorContent('');changeContent(r);}).catch((e: any) =>{console.log(e,'提出请求申请失败!');changeErrorContent(e);});};constonStartAsyncShow= () => {LocationCtrl.startAsync(MapId,true).then((r: any) =>{changeErrorContent('');LocationCtrl.startGetLocation(MapId,50,5000).then((r: any) =>{console.log('开启等间隔获取定位成功', r);changeErrorContent('');tmpLocateListener =DeviceEventEmitter.addListener(LocationEventType.onPassiveLocationChanged,res=>{changeContent(res);});}).catch((e: any) =>{changeErrorContent(e);});}).catch((e: any) =>{changeErrorContent(e);});// LocationCtrl.startAsync(MapId, true)// .then((r: any) => {// changeErrorContent('');// changeContent(r);// })// .catch((e: any) => {// changeErrorContent(e);// });};constonSetTimerParam= () => {LocationCtrl.setTimerParam(MapId, delay, period).then((r: any) =>{changeErrorContent('');changeContent(r);}).catch((e: any) =>{changeErrorContent(e);});};constonStartListenCourseChange= () => {LocationCtrl.startListenCourseChange(MapId).then((r: any) =>{changeErrorContent('');changeContent(r);}).catch((e: any) =>{changeErrorContent(e);});};constonStopListenCourseChange= () => {LocationCtrl.stopListenCourseChange(MapId).then((r: any) =>{changeErrorContent('');changeContent(r);}).catch((e: any) =>{changeErrorContent(e);});};constonAddListener= () => {LocationCtrl.addListener(MapId, locationEventType).then((r: any) =>{listenerId = r;changeErrorContent('');tmpLocateListener =DeviceEventEmitter.addListener(locationEventType,r=>{changeContent(r);});}).catch((e: any) =>{changeErrorContent(e);});};constonStartGetLocation= () => {LocationCtrl.startGetLocation(MapId,50,5000).then((r: any) =>{console.log('开启等间隔获取定位成功', r);changeErrorContent('');tmpLocateListener =DeviceEventEmitter.addListener(LocationEventType.onPassiveLocationChanged,res=>{changeContent(res);});}).catch((e: any) =>{changeErrorContent(e);});};constonStopGetLocation= () => {LocationCtrl.stopGetLocation(MapId).then((r: any) =>{console.log('关闭等间隔获取定位成功', r);changeErrorContent('');}).catch((e: any) =>{changeErrorContent(e);});};constonRemoveListener= () => {LocationCtrl.removeListener(MapId, listenerId).then((r: any) =>{changeErrorContent('');changeContent(r);}).catch((e: any) =>{changeErrorContent(e);});};constonClearListener= () => {LocationCtrl.clearListener(MapId).then((r: any) =>{changeErrorContent('');changeContent(r);}).catch((e: any) =>{changeErrorContent(e);});};constonIsStarted= () => {LocationCtrl.isStarted(MapId).then((r: any) =>{changeErrorContent('');changeContent(r.toString());}).catch((e: any) =>{changeErrorContent(e);});};constonStopLocation= () => {LocationCtrl2.stopLocation(MapId).then((r: any) =>{changeErrorContent('');changeContent(r);}).catch((e: any) =>{changeErrorContent(e);});};constonGetHeading= () => {LocationCtrl.getHeading(MapId).then((r: any) =>{changeErrorContent('');changeContent(r);}).catch((e: any) =>{changeErrorContent(e);});};constonGetInitialZoomScale= () => {LocationCtrl.getInitialZoomScale(MapId).then((r: any) =>{changeErrorContent('');changeContent(r);}).catch((e: any) =>{changeErrorContent(e);});};constonSetInitialZoomScale= () => {LocationCtrl.setInitialZoomScale(MapId, initScale).then((r: any) =>{changeErrorContent('');changeContent(r);}).catch((e: any) =>{changeErrorContent(e);});};constonGetMapLocation= () => {LocationCtrl2.getCurrentLocation().then((r: any) =>{changeErrorContent('');changeContent(r);}).catch((e: any) =>{changeErrorContent(e);});};constonSetAutoPanMode= () => {LocationCtrl.setAutoPanMode(MapId, displayMode).then((r: any) =>{changeErrorContent('');changeContent(r);}).catch((e: any) =>{changeErrorContent(e);});};constonGetAccuracySymbol= () => {LocationCtrl.getAccuracySymbol(MapId).then((r: any) =>{changeErrorContent('');changeContent(r);}).catch((e: any) =>{changeErrorContent(e);});};constonSetAccuracySymbol= () => {LocationCtrl.setAccuracySymbol(MapId, symbolStr).then((r: any) =>{changeErrorContent('');changeContent(r);}).catch((e: any) =>{changeErrorContent(e);});};constonGetAcquiringSymbol= () => {LocationCtrl.getAcquiringSymbol(MapId).then((r: any) =>{changeErrorContent('');changeContent(r);}).catch((e: any) =>{changeErrorContent(e);});};constonSetAcquiringSymbol= () => {LocationCtrl.setAcquiringSymbol(MapId, symbolStr).then((r: any) =>{changeErrorContent('');changeContent(r);}).catch((e: any) =>{changeErrorContent(e);});};constonGetCourseSymbol= () => {LocationCtrl.getCourseSymbol(MapId).then((r: any) =>{changeErrorContent('');changeContent(r);}).catch((e: any) =>{changeErrorContent(e);});};constonSetCourseSymbol= () => {LocationCtrl.setCourseSymbol(MapId, symbolStr).then((r: any) =>{changeErrorContent('');changeContent(r);}).catch((e: any) =>{changeErrorContent(e);});};constonGetDefaultSymbol= () => {LocationCtrl.getDefaultSymbol(MapId).then((r: any) =>{changeErrorContent('');changeContent(r);}).catch((e: any) =>{changeErrorContent(e);});};constonSetDefaultSymbol= () => {LocationCtrl.setDefaultSymbol(MapId, imageBse64).then((r: any) =>{changeErrorContent('');changeContent(r);}).catch((e: any) =>{changeErrorContent(e);});};
网友评论