React Leaflet LayersControll-baseLayer对象示例

时间:2018-06-26 15:34:24

标签: javascript reactjs leaflet react-leaflet

我尝试将LayersControll添加到react-lealfet映射中。

我添加了图层控制图标

enter image description here

但悬停时为空。

enter image description here

还有代码示例

 <Map center={this.props.configuration.center}
                 zoom={this.props.configuration.zoom}
                 minZoom={this.props.configuration.minZoom}
                 maxZoom={this.props.configuration.maxZoom}
                 attributionControl={false}
                 doubleClickZoom={false}
                 zoomControl={false}
                 editable={true}
                 onZoomEnd={this.props.configuration.onZoomEnd}
                 onZoomStart={this.props.configuration.onZoomStart}
                 bounceAtZoomLimits={false}
                 dragging={true}>

                <FeatureGroup>
                    <LayersControl
                        baseLayers={{
                            url: TILES_URL,
                            id: 'MapID'}}
                    >
                        <TileLayer url={TILES_URL}/>
                        <ZoomControl position="topright" />
                        <Marker position={[0, 0]}>
                            <Popup>
                                <span>Great marker!</span>
                            </Popup>
                        </Marker>

                    </LayersControl>

                    {this.props.children}
                </FeatureGroup>

            </Map>

1 个答案:

答案 0 :(得分:0)

通过react-leaflet文档

https://react-leaflet.js.org/docs/en/examples.html

有层的例子
https://github.com/PaulLeCam/react-leaflet/blob/master/example/components/layers-control.js

所以工作示例将是

首先,我们需要导入组件

import { Map, LayersControl, ... } from 'react-leaflet';
const { BaseLayer, Overlay } = LayersControl;

  <LayersControl>
       <BaseLayer checked name="OpenStreetMap.Mapnik">
             <TileLayer url={TILES_URL}/>
       </BaseLayer>
  </LayersControl>