天天看點

React Native for Arcgis 地圖開發 影像RasterLayer(十)

RasterLayerCtrl的封裝調用
import React, {useState, useEffect} from ‘react’;
 import {View, Text, ScrollView, StyleSheet} from ‘react-native’;
 import {Button, List, Switch} from ‘@ant-design/react-native’;
 import {RasterLayerCtrl, LayerManager, MapManager, MapView} from ‘@haibalai/react-native-arcgis’;
 import {connect} from ‘react-redux’;
 import WidthDrawer from ‘…/…/…/…/components/WithDrawer/index’;
 const MapId = ‘baseMap’;
 const EditFeatureLayerId3857 = ‘DEM_3857’;
 const EditFeatureLayerId4490 = ‘DEM_2000’;
 /** sideBar元件
 *@param {*} renderCb renderCb是一個函數, 每次觸發并且向裡面傳值(對象),content元件就以sideBarData的屬性去接受
 */
 const SideBar = ({renderCb, Home}: any) => {
 const [content, changeContent] = useState(‘’);
 const [errorContent, changeErrorContent] = useState(‘’);
 const [singleRasterLayerStatus, setSingleRasterLayerStatus] = useState(false);
 useEffect(() => {
 renderCb({content, errorContent});
 }, [content, errorContent, renderCb]);
 const getRender = () => {
 let coordinate = Home.coordinate;
 if (coordinate === ‘4490’) {
 return ‘’;
 } else {
 return ‘’;
 }
 };
 const getLayerId = () => {
 let coordinate = Home.coordinate;
 if (coordinate === ‘4490’) {
 return EditFeatureLayerId4490;
 } else {
 return EditFeatureLayerId3857;
 }
 };
 const onSwitchRasterLayer = (e: boolean) => {
 if (e) {
 LayerManager.showLayer(MapId, getLayerId());
 } else {
 LayerManager.hideLayer(MapId, getLayerId());
 }
 setSingleRasterLayerStatus(e);
 };
 const onGetRasterRenderer = () => {
 RasterLayerCtrl.getRasterRenderer(MapId, getLayerId())
 .then((r: any) => {
 changeErrorContent(‘’);
 changeContent®;
 })
 .catch((e: any) => {
 changeErrorContent(e);
 });
 };
 const onSetRasterRenderer = () => {
 RasterLayerCtrl.setRasterRenderer(MapId, getLayerId(), getRender())
 .then((r: any) => {
 changeErrorContent(‘’);
 changeContent®;
 })
 .catch((e: any) => {
 changeErrorContent(e);
 });
 };
 return (}>
 單個RasterLayerReact Native for Arcgis 地圖開發 影像RasterLayer(十) - 小專欄