React Map GL:地图不占用整个宽度
React Map GL: map not taking the entire width
我正在使用语义反应 ui 作为 ui 库和反应地图 gl 在我的反应应用程序中渲染地图。但是从 react-map-gl 呈现的地图并没有占据列的整个宽度。请找到下图:
虚线表示列。地图仍有足够的宽度可以拉伸。但是根据文档,我们必须以像素为单位提供地图的宽度和高度。
容器代码如下:
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>
);
}
而保存地图的组件如下所示:
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;
地图视口代码如下:
viewPort: {
width: 800,
height: 800,
latitude: 21.1458,
longitude: 79.0882,
zoom: 4
}
我们无法提供百分比宽度。我们如何使它显示为全宽?另外,如何在移动设备上自动调整地图大小?
谢谢
您应该能够以百分比形式提供宽度。只要确保它是一个字符串。
viewPort: {
width: "100%",
height: "100%",
latitude: 21.1458,
longitude: 79.0882,
zoom: 4
}
使用 react-map-gl
版本 5.2.3,当我使用 width: '100%', height: '100%'
时地图无法渲染。
我可以使用 "vw"/"vh" 单位来代替百分比单位,如下所示:width: '100vw', height: '100vh'
。这是 docs examples from the react-map-gl repo.
当前显示的语法风格
回购示例直接使用 width/height 道具,但在 viewPort
对象中它看起来像:
viewPort: {
width: '100vw',
height: '100vh',
latitude: 21.1458,
longitude: 79.0882,
zoom: 4
}
希望对某人有所帮助。
对我来说,使用 react-map-gl@5.2.3
,我无法将宽度和高度指定为 100%
。虽然指定 100vh
有效,但它在移动设备上有问题。
我通过如下指定 viewport
解决了这个问题
viewport: {
latitude: 0,
longitude: 0,
zoom: 1,
height: window.innerHeight,
width: window.innerWidth,
}
这对我有用:
viewport: {
width: "fit",
...
},
<ReactMapGL
onViewportChange={nextViewport =>
this.setState({ viewport: { ...nextViewport, width: "fit" } })
}
...
>
尝试在道具中添加width="100vw"
height="100vh"
<ReactMapGL
{...viewPort}
width="100vw"
height="100vh"
mapStyle="mapbox://styles/mapbox/dark-v9"
mapboxApiAccessToken="key"
onViewportChange={handleViewportChange}
/>
我正在使用语义反应 ui 作为 ui 库和反应地图 gl 在我的反应应用程序中渲染地图。但是从 react-map-gl 呈现的地图并没有占据列的整个宽度。请找到下图:
虚线表示列。地图仍有足够的宽度可以拉伸。但是根据文档,我们必须以像素为单位提供地图的宽度和高度。
容器代码如下:
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>
);
}
而保存地图的组件如下所示:
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;
地图视口代码如下:
viewPort: {
width: 800,
height: 800,
latitude: 21.1458,
longitude: 79.0882,
zoom: 4
}
我们无法提供百分比宽度。我们如何使它显示为全宽?另外,如何在移动设备上自动调整地图大小?
谢谢
您应该能够以百分比形式提供宽度。只要确保它是一个字符串。
viewPort: {
width: "100%",
height: "100%",
latitude: 21.1458,
longitude: 79.0882,
zoom: 4
}
使用 react-map-gl
版本 5.2.3,当我使用 width: '100%', height: '100%'
时地图无法渲染。
我可以使用 "vw"/"vh" 单位来代替百分比单位,如下所示:width: '100vw', height: '100vh'
。这是 docs examples from the react-map-gl repo.
回购示例直接使用 width/height 道具,但在 viewPort
对象中它看起来像:
viewPort: {
width: '100vw',
height: '100vh',
latitude: 21.1458,
longitude: 79.0882,
zoom: 4
}
希望对某人有所帮助。
对我来说,使用 react-map-gl@5.2.3
,我无法将宽度和高度指定为 100%
。虽然指定 100vh
有效,但它在移动设备上有问题。
我通过如下指定 viewport
解决了这个问题
viewport: {
latitude: 0,
longitude: 0,
zoom: 1,
height: window.innerHeight,
width: window.innerWidth,
}
这对我有用:
viewport: {
width: "fit",
...
},
<ReactMapGL
onViewportChange={nextViewport =>
this.setState({ viewport: { ...nextViewport, width: "fit" } })
}
...
>
尝试在道具中添加width="100vw"
height="100vh"
<ReactMapGL
{...viewPort}
width="100vw"
height="100vh"
mapStyle="mapbox://styles/mapbox/dark-v9"
mapboxApiAccessToken="key"
onViewportChange={handleViewportChange}
/>