获取当前层onChange

时间:2018-10-17 06:28:48

标签: reactjs react-leaflet

通过layersControl切换时如何获取当前图层? 例如,当我从第一层更改为第二个console.info('Now layer is:',curLayer)  我已经尝试从refs获取访问权限,将onClick事件添加到layersControl。

                <LayersControl 
                    ref = 'control'
                    position='topleft'>

                    <TileLayer
                        interactive={true}
                        url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
                    />

                    <LayersControl.BaseLayer 
                        checked
                        onClick={(e,t)=>console.info(e,t,'infoooo')}
                        name='1 этаж'>
                        <LayerGroup>

                            <ImageOverlay
                                minZoom={31}
                                bounds={bounds}
                                url={firstFloor}

                            />
                        </LayerGroup>
                    </LayersControl.BaseLayer>

                    <LayersControl.BaseLayer name='2 этаж'>
                        <LayerGroup>

                            <ImageOverlay
                                minZoom={31}
                                bounds={bounds2}
                                url={secondFloor}

                            />
                        </LayerGroup>
                        </LayersControl.BaseLayer>

0 个答案:

没有答案