React Map GL: map not taking the entire width
我将语义React ui用作ui库,并在我的react应用程序中使用react map gl来渲染地图。 但是从react-map-gl渲染的地图不会占用列的整个宽度。 请找到下面的图片:
虚线表示该列。 仍然有足够的宽度可以拉伸地图。 但是根据文档,我们必须以像素为单位提供地图的宽度和高度。
容器代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | render() { return ( <Grid style={{ padding: '20px' }}> <Grid.Row> <Grid.Column mobile={16} computer={12} style={{ border: 'dotted', paddingLeft: 0 }}> <PincodesMap viewPort={this.props.viewPort} handleViewportChange={this.handleViewportChange.bind(this)} /> </Grid.Column> <Grid.Column mobile={16} computer={4} style={{ border: 1 }}> This is test </Grid.Column> </Grid.Row> </Grid> ); } |
拥有地图的组件如下所示:
1 2 3 4 5 6 7 8 9 10 11 12 13 | import React from 'react'; import ReactMapGL from 'react-map-gl'; const PincodesMap = ({ viewPort, handleViewportChange }) => ( <ReactMapGL {...viewPort} mapStyle="mapbox://styles/mapbox/dark-v9" mapboxApiAccessToken="key" onViewportChange={handleViewportChange} /> ); export default PincodesMap; |
地图的视口代码如下:
1 2 3 4 5 6 7 | viewPort: { width: 800, height: 800, latitude: 21.1458, longitude: 79.0882, zoom: 4 } |
我们无法以百分比形式提供宽度。 我们如何使其显示为全角? 另外,如何在手机上自动调整地图大小?
谢谢
使用
代替百分比单位,我可以使用" vw" /" vh"单位来使它正常工作:
repo示例直接使用width / height道具,但是在
1 2 3 4 5 6 7 | viewPort: { width: '100vw', height: '100vh', latitude: 21.1458, longitude: 79.0882, zoom: 4 } |
希望能对某人有所帮助。
这为我工作:
1 2 3 4 | viewport: { width:"fit", ... }, |
1 2 3 4 5 6 | <ReactMapGL onViewportChange={nextViewport => this.setState({ viewport: { ...nextViewport, width:"fit" } }) } ... > |
对我来说,对于
我通过指定
1 2 3 4 5 6 7 | viewport: { latitude: 0, longitude: 0, zoom: 1, height: window.innerHeight, width: window.innerWidth, } |
您应该能够以百分比形式提供宽度。 只要确保它是一个字符串即可。
1 2 3 4 5 6 7 | viewPort: { width:"100%", height:"100%", latitude: 21.1458, longitude: 79.0882, zoom: 4 } |