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

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

在 react-google-maps 組件上自動(dòng)調(diào)整高度

在 react-google-maps 組件上自動(dòng)調(diào)整高度

開心每一天1111 2022-05-26 17:48:38
我正在嘗試使用 react 和谷歌地圖構(gòu)建地圖應(yīng)用程序,我設(shè)法創(chuàng)建谷歌地圖組件并使用地圖,但是,當(dāng)添加導(dǎo)航欄組件時(shí),我找不到將地圖高度調(diào)整到空間的方法左側(cè)沒有顯示滾動(dòng)條。Navbar 組件來自引導(dǎo)程序,我不知道它是否有所作為。地圖組件import React from 'react';import { GoogleMap, withScriptjs, withGoogleMap } from 'react-google-maps';const INIT_VALUES = {  initialZoom: 10,  center: { lat: -27.593500, lng: -48.558540 },};function Map() {  return (    <GoogleMap      defaultCenter={INIT_VALUES.center}      defaultZoom={INIT_VALUES.initialZoom}    />  );}const WrappedMap = withScriptjs(withGoogleMap(Map));export default WrappedMap;應(yīng)用程序組件import React, { useEffect } from 'react';import MapNavbar from './components/navbar/index';import WrappedMap from './components/map/index';import './App.css';const MAP_KEY = 'https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=geometry,drawing,places&key=******';const mapStyles = {  width: '100%',  height: '100vh',};async function fetchData(callback) {  const response = await fetch('http://localhost:5000/');  const data = await response.json();  callback(data);}function App() {  useEffect(() => {    fetchData((a) => console.log(a));  }, []);  return (    <div className="App">      <MapNavbar />      <div style={mapStyles}>        <WrappedMap          googleMapURL={MAP_KEY}          loadingElement={<div style={{ height: '100%' }} />}          containerElement={<div style={{ height: '100%' }} />}          mapElement={<div style={{ height: '100%' }} />}        />      </div>    </div>  );}export default App;
查看完整描述

2 回答

?
慕哥6287543

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

如果您知道導(dǎo)航欄的確切高度,您可以使用 CSS屬性(此處calc的文檔)。

使用 calc 屬性,您可以將地圖容器設(shè)置為等于這樣的內(nèi)容

height: calc(100vh - navbarHeight)

如果您不知道導(dǎo)航欄的高度,您可以使用 flex 將地圖容器拉伸到剩余的 App 空間。


查看完整回答
反對(duì) 回復(fù) 2022-05-26
?
明月笑刀無情

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

您可以嵌套 flexbox 并定義父 flexbox 的高度。

這是我的例子。


mapContainerStyle


const mapStyles = {

  width: '100%',

- height: '100vh',

+ height: "100%",

};

APP COMPONENT


return(

  <div

    style={{ height: "100vh", display: "flex", "flex-direction": "column" }}

  >

    <div>

      <MapNavbar />

    </div>


    <div style={{ "flex-grow": "1" }}>

      <WrappedMap

        // your props...

      />

    </div>

  </div>

)

使用 Material UI Box 更簡(jiǎn)單。

APP COMPONENT


return(

  <Box display="flex" flexDirection="column" style={{ height: "100vh" }}>

  <Box>

    <MapNavbar />

  </Box>


  <Box flexGrow={1}>

    <WrappedMap

      // your props...

/>

  </Box>

</Box>

)


查看完整回答
反對(duì) 回復(fù) 2022-05-26
  • 2 回答
  • 0 關(guān)注
  • 191 瀏覽
慕課專欄
更多

添加回答

舉報(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)