首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在新的ZoomIndicator读取未定义的属性'map‘

无法在新的ZoomIndicator读取未定义的属性'map‘
EN

Stack Overflow用户
提问于 2019-04-12 22:51:18
回答 1查看 475关注 0票数 0

我确实按照https://github.com/tumerorkun/react-leaflet-zoom-indicator中的说明安装了插件,但在使用此代码时出现以下错误

代码语言:javascript
复制
import { ReactLeafletZoomIndicator } from 'react-leaflet-zoom-indicator'

<Map
    map={this.refs.mapRef}
    center={[51,10]}
    length={4}
    onClick={(e)=>{this.handleClick(e)}}
    ref="mapRef"
    zoom={5.5}
>
    <ReactLeafletZoomIndicator head='zoom:' position='topleft' />
    <TileLayer
          /*Links for background map*/
    />
          {newLocation}
          {existingLocations}
</Map>

它在这一行失败

代码语言:javascript
复制
    _this.map = context.map || _this.props.leaflet.map;

在来自node_modules的react-leaflet-zoom-indicator.js中

EN

回答 1

Stack Overflow用户

发布于 2019-04-22 19:41:05

看起来ReactLeafletZoomIndicator没有设置上下文,因此属性映射是未定义的。试试这个:

代码语言:javascript
复制
import { ReactLeafletZoomIndicator } from 'react-leaflet-zoom-indicator'

const ReactLeafletZoomIndicatorWithContext =  = withLeaflet(ReactLeafletZoomIndicator);

<Map
    map={this.refs.mapRef}
    center={[51,10]}
    length={4}
    onClick={(e)=>{this.handleClick(e)}}
    ref="mapRef"
    zoom={5.5}
>
    <ReactLeafletZoomIndicatorWithContext head='zoom:' position='topleft' />
    <TileLayer
          /*Links for background map*/
    />
          {newLocation}
          {existingLocations}
</Map>

react-leaflet的v2要求这样做。参见here

通过使用withLeaflet()包装您的自定义组件,它将获得注入到其道具中的Leaflet上下文对象。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55654307

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档