آموزش جاوااسکریپت › انجمن ها › react native › گرفتن نقطه مرکزی نقشه سیدارمپ
- این موضوع 1 پاسخ، 1 کاربر را دارد و آخرین بار در 4 سال، 5 ماه پیش بدست سجاد بهروزرسانی شده است.
-
نویسندهنوشتهها
-
سجادمیهمان
میخام نقطه مرکزی نقشه سیدارمپو بدست بیارم اما متدgetCenter به صورت مسقیم داخل کامپوننت cedarmap عمل نمیکنه و باید از طریق getMapbox به فانکشنای مپباکس دسترسی داشت. فانکشن getCenter هم داخل mapView مپباکس تعریف شده، چجوری بین cedarmap و mapView ارتباط برقرار کنم
نحوه استفاده از getCenter داخل مپباکس به این شکله:JavaScript12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364import React from 'react';import {Text} from 'react-native';import MapboxGL from '@mapbox/react-native-mapbox-gl';import BaseExamplePropTypes from './common/BaseExamplePropTypes';import Page from './common/Page';import Bubble from './common/Bubble';class GetCenter extends React.Component {static propTypes = {...BaseExamplePropTypes,};constructor(props) {super(props);this.state = {center: [],};this.onRegionDidChange = this.onRegionDidChange.bind(this);this.getLat = this.getLat.bind(this);this.getLng = this.getLng.bind(this);}async onRegionDidChange() {const center = await this._map.getCenter();this.setState({center});}getLng() {const {center} = this.state;return center.length === 2 ? <code>Lng: ${center[0]}</code> : 'Not available';}getLat() {const {center} = this.state;return center.length === 2 ? <code>Lat: ${center[1]}</code> : 'Not available';}render() {return (<Page {...this.props}><MapboxGL.MapViewonRegionDidChange={this.onRegionDidChange}zoomLevel={9}ref={c => (this._map = c)}onPress={this.onPress}centerCoordinate={[-73.970895, 40.723279]}style={{flex: 1}}/><Bubble><Text>Center</Text><Text>{this.getLng()}</Text><Text>{this.getLat()}</Text></Bubble></Page>);}}export default GetCenter;همین متدو چجوری داخل سیدارمپ استفاده کنم
سجادمیهمانداخل مستندات و تریف سیدارمپ گفته که باید از طریق دو تا فانکشن عمل کنیم اما نمیدونم بین CedarMap و Mapbox.MapView چجوری ارتباط برقرار کنم
CedarMaps SDK is based on Mapbox Maps SDK for React Native v6.1.3 and provides extra API methods over Mapbox. For more information about how to use MapView and other components such as Adding Markers, Showing Current Location, etc., please see Mapbox for React Native First Steps.
FunctionsgetMap():
get the map ref object
getMapbox():
You can get main mapbox object (react-native-mapbox-gl) via getMapbox() functions attached to CedarMaps -
نویسندهنوشتهها