import React from 'react'; import { SafeAreaView, ScrollView, StatusBar, StyleSheet, Text, Image, TouchableOpacity, View, DeviceEventEmitter } from 'react-native'; import MapboxGL from 'fengsheng-rnmaps'; import comStyles from './../../assets/styles/com-style'; import GpsLocationShowKit from './GpsLocationShowKit'; import KitAreaLocaionMsg from '../kits/KitAreaLocaionMsg'; import { BjTypeLocation, BjTypeMapConfig } from '../../utils/types'; import KitCompass from './KitCompass'; import redux from './../../redux/store'; import ResearchDataGroup from './ResearchDataGroup'; import { px2dp, size } from '../../utils'; interface Props { } interface State { location: Array zoomLevel: number currentZoomLevel: number mapConfig: BjTypeMapConfig } export default class CustomMapView extends React.Component { constructor(props: Props) { super(props); }; public cameraRef = null; public locationKitRef = null; public mapConfigChangeListener = null; public researchDataGroupRef = null; public fucusCurrentLocationListener = null; public _state = redux.getState(); public readonly state: Readonly = { location: [112.9166537, 28.294697], zoomLevel: 12, mapConfig: this._state.mapConfig, currentZoomLevel: 12, }; componentDidMount() { this.mapConfigChangeListener = DeviceEventEmitter.addListener('map-config-change', (a) => { this.setState({ mapConfig: redux.getState().mapConfig }) }) this.fucusCurrentLocationListener = DeviceEventEmitter.addListener('focus-current-location', (a) => { const location: BjTypeLocation = this.locationKitRef.getLocation(); console.log("location", location) if (location.latitude && location.longitude) { this.cameraRef.flyTo([location._longitude, location._latitude], 350) // this.setState({ zoomLevel: 16, location: [location._longitude, location._latitude] }) } }) }; componentWillUnmount(): void { this.mapConfigChangeListener && this.mapConfigChangeListener?.remove(); this.fucusCurrentLocationListener && this.fucusCurrentLocationListener?.remove(); } getMarkerData() { this.researchDataGroupRef?.handleGetMarkerData(); } adptMapStyleUrl() { // return 'mapbox://styles/mapbox/satellite-streets-v11' const { currentZoomLevel, mapConfig } = this.state; if (mapConfig) { let mapStyleUrl = ""; // return "mapbox://styles/mapbox/streets-v11"; switch (mapConfig.layerType) { case 'outdoor': mapStyleUrl = "mapbox://styles/mapbox/outdoors-v11" break; case 'satellite': mapStyleUrl = "mapbox://styles/mapbox/satellite-streets-v11"; break; default: break; } return mapStyleUrl; } return 'mapbox://styles/mapbox/satellite-streets-v11' } onRegionDidChange(e) { console.log("onRegionDidChange", e); }; render() { const { location, zoomLevel } = this.state; return ( this.cameraRef = c} zoomLevel={zoomLevel} centerCoordinate={location} animationMode={'flyTo'} animationDuration={600} /> this.researchDataGroupRef = c} /> this.locationKitRef = c} size={'headless'} customKey={'map-location'} /> ) } }