Невозможно прочитать свойство 'map' из undefined в новом ZoomIndicator - PullRequest
0 голосов
/ 12 апреля 2019

Я установил плагин, как описано в https://github.com/tumerorkun/react-leaflet-zoom-indicator, но я получаю эту ошибку при использовании этого кода

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>

Сбой на этой линии

    _this.map = context.map || _this.props.leaflet.map;

в response-leaflet-zoom-Indicator.js из node_modules

1 Ответ

0 голосов
/ 22 апреля 2019

Похоже, что ReactLeafletZoomIndicator не имеет установленного контекста, поэтому карта свойств не определена. Попробуйте это:

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>

v2 реакционной листовки требует этого. Смотри здесь .

Обернув ваш пользовательский компонент с помощью withLeaflet (), он получит объект контекста Leaflet, вставленный в его подпорки.

...