GraphicCtrl的使用importReact, {useState, useEffect}from'react';import{View,Text,ScrollView,StyleSheet}from'react-native';import{Button,List,Switch}from'@ant-design/react-native';import{GraphicCtrl,GraphicLayerCtrl,LayerManager,MapManager,MapView}from'@haibalai/react-native-arcgis';import{connect}from'react-redux';importWidthDrawerfrom'../../../../components/WithDrawer/index';import{Colors}from'react-native/Libraries/NewAppScreen';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;constlayerName ='test';constgraphicStrs = [{geometry: {type:'point',x:113.868676,y:22.487838,z:0,spatialReference: {wkid:4326}}},{geometry: {type:'point',x:113.768676,y:22.587838,z:0,spatialReference: {wkid:4326}}},{geometry: {type:'point',x:113.868676,y:22.587838,z:0,spatialReference: {wkid:4326}}},];letgraphicId ='';letgraphicIds = [''];constsymbolStr = {angle:0,color: [40,135,255,255],outline: {color: [14,98,230,255],style:'solid',type:'esriSLS',width:1.5},size:9,style:'circle',type:'esriSMS',xoffset:0,yoffset:0,};constselected =true;constvisible =true;constgeometryStr ='';constattributesStr ='';constzIndex =1;/** 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};constonAddGraphics= () => {GraphicLayerCtrl.addGraphics(MapId, layerName, graphicStrs).then((r: any) =>{graphicIds = r;graphicId = graphicIds[0];changeErrorContent('');changeContent(r);}).catch((e: any) =>{changeErrorContent(e);});};constonRemoveGraphic= () => {GraphicCtrl.removeGraphic(graphicId).then((r: any) =>{changeErrorContent('');changeContent(r);}).catch((e: any) =>{changeErrorContent(e);});};constonRemoveGraphics= () => {GraphicCtrl.removeGraphics(graphicIds).then((r: any) =>{changeErrorContent('');changeContent(r);}).catch((e: any) =>{changeErrorContent(e);});};constonGetSymbol= () => {GraphicCtrl.getSymbol(graphicId).then((r: any) =>{changeErrorContent('');changeContent(r);}).catch((e: any) =>{changeErrorContent(e);});};constonSetSymbol= () => {GraphicCtrl.setSymbol(graphicId, symbolStr).then((r: any) =>{changeErrorContent('');changeContent(r);}).catch((e: any) =>{changeErrorContent(e);});};constonIsSelected= () => {GraphicCtrl.isSelected(graphicId).then((r: any) =>{changeErrorContent('');changeContent(r.toString());}).catch((e: any) =>{changeErrorContent(e);});};constonSetSelected= () => {GraphicCtrl.setSelected(graphicId, selected).then((r: any) =>{changeErrorContent('');changeContent(r);}).catch((e: any) =>{changeErrorContent(e);});};constonIsVisible= () => {GraphicCtrl.isVisible(graphicId).then((r: any) =>{changeErrorContent('');changeContent(r.toString());}).catch((e: any) =>{changeErrorContent(e);});};constonSetVisible= () => {GraphicCtrl.setVisible(graphicId, visible).then((r: any) =>{changeErrorContent('');changeContent(r);}).catch((e: any) =>{changeErrorContent(e);});};constonGetAttributes= () => {
https://xiaozhuanlan.com/topic/