微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

React Leaflet:调整点击/动态按钮的地图大小

如何解决React Leaflet:调整点击/动态按钮的地图大小

let style;
if(this.state.getMoreInfo){
  style = {
    height: "78vh",width: "75%",};
} else {
  style = {
    height: "78vh",width: "100%",};
}


<div className="mapContent">
  <Map 
    className="Map" 
    style={style} 
    center={{ lat: 40.7,lng: -74 }} 
    zoom={15} 
    onClick={this.addMarker}>
    <TileLayer
      attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
      url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
    />
    {this.state.data.map((house,idx) => 
      <Marker 
        key={`marker-${idx}`} 
        position={{ lat: house.latitude,lng: house.longitude }} 
        icon={ Icon } >
        <Popup>
          <Card className="housePopup">
            <CardHeader tag="h5">{house.address}</CardHeader>
            <CardBody className="houseDescription">
              <CardText>{house.description}</CardText>
            </CardBody>
            <Button 
              value={house} 
              onClick={() => this.setState({
                getMoreInfo: true,currHouse: house 
              })}>
              Get More Info
            </Button>
          </Card>
        </Popup>
      </Marker>
    )}
  </Map>                
  { this.state.getMoreInfo 
    ? (<HouseInfo house={this.state.currHouse}/>) 
    : (<div></div>)}
</div>

以上是我的 React 类组件的片段。我目前正在使用 React Leaflet 库为我的项目生成地图。我的目标是在点击更多信息按钮时生成一个特定的侧边栏。本质上,我想制作一个特定于数组中元素的动态按钮。但是,每次我单击按钮时,页面都会变为空白。我尝试在没有附加信息的情况下将地图设置为较小的宽度,并且它起作用了。我猜这可能是我创建按钮的逻辑有问题。有什么想法吗?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。