第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

反應(yīng)本機(jī)地圖在標(biāo)記按下時(shí)重新渲染

反應(yīng)本機(jī)地圖在標(biāo)記按下時(shí)重新渲染

瀟瀟雨雨 2023-08-18 17:24:59
我遇到了 React 本機(jī)地圖的問(wèn)題。我嘗試在地圖上放置標(biāo)記,并突出顯示按下的標(biāo)記。我不認(rèn)為這會(huì)那么棘手:)這是我渲染標(biāo)記的方式:function renderMarkers() {    const shopsFiltered = shops.filter((shop) => {            return shop.hasOwnProperty('latitude') && shop.hasOwnProperty('longitude') && shop.latitude && shop.longitude    });    return shopsFiltered.map((shop) => {            const isInWallet = cards.data.filter(card => {        return card.hasOwnProperty('company') && shop.hasOwnProperty('company') && card.company.objectId === shop.company.objectId;      }).length;      const isCurrentMarker = shop.company.objectId === currentMarkerCardId;      const latLng = { latitude: shop.latitude, longitude: shop.longitude };      return <Marker          key={shop.objectId}        coordinate={latLng}        onPress={() => onMarkerPress(shop.company.objectId)}      >        {isCurrentMarker && // I had to do this, since the dimensions weren't updated using style prop...          <Image            source={isInWallet ? require('../assets/images/explorer/pin-on.png'):require('../assets/images/explorer/pin-off.png')}            style={styles.mapMarkerCurrent }            resizeMode="cover"            resizeMethod="resize"          />        }        {!isCurrentMarker &&          <Image            source={isInWallet ? require('../assets/images/explorer/pin-on.png'):require('../assets/images/explorer/pin-off.png')}            style={styles.mapMarker}            resizeMode="cover"            resizeMethod="resize"          />        }      </Marker>    });  }當(dāng)我按下標(biāo)記時(shí):function onMarkerPress(id) {  setBottomBoxOpacity(1);  setCurrentMarkerCardId(id);}setCurrentMarkerCardId是一個(gè) useState 鉤子,因此重新渲染視圖。這對(duì)我來(lái)說(shuō)是一個(gè)問(wèn)題,因?yàn)檎麄€(gè)地圖重新渲染(=它使地圖重新回到用戶位置的中心)并導(dǎo)致地圖滯后。但是,我看到了這個(gè)問(wèn)題,但我不知道如何在不重新渲染整個(gè)地圖的情況下更新按下的標(biāo)記值。有任何想法嗎?
查看完整描述

1 回答

?
尚方寶劍之說(shuō)

TA貢獻(xiàn)1788條經(jīng)驗(yàn) 獲得超4個(gè)贊

好吧,我真的覺(jué)得自己很傻。

答案一直就在那里。當(dāng)我應(yīng)該在 MapView 組件上region使用時(shí)(我沒(méi)有包含在問(wèn)題中:/),我使用 prop 時(shí)犯了一個(gè)錯(cuò)誤,根據(jù)文檔,它僅在組件安裝時(shí)使用:initialRegion

Changing this prop after the component has mounted will not result in a region change.


查看完整回答
反對(duì) 回復(fù) 2023-08-18
  • 1 回答
  • 0 關(guān)注
  • 132 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)