Uncaught TypeError:无法读取未定义的属性'addLayer'-PixiOverlay

问题描述 投票:0回答:1

这是我的代码:

import React, { PureComponent } from 'react';
import { PixiOverlay } from 'react-leaflet-pixi-overlay';
import { Map, TileLayer } from 'react-leaflet';
import { renderToString } from 'react-dom/server';

class PixiOverlayClass extends PureComponent {
 render() {
  const markers = [
   {
    id: 'randomStringOrNumber',
    iconColor: 'red', // colors: https://github.com/pointhi/leaflet-color-markers
    position: [-37.814, 144.96332],
    popup: renderToString(<div>All good!</div>),
    onClick: () => alert('marker clicked'),
    tooltip: 'Hey!',
  },
  {
    id: '2',
    position: [-37.814, 144.96332],
    popup: 'Quack!',
    popupOpen: true, // if popup has to be open by default
    onClick: () => alert('marker clicked'),
    tooltip: 'Nice!',
  },
];
return (
  <React.Fragment>
    <Map
      preferCanvas
      maxZoom={20}
      minZoom={3}
      center={[-37.814, 144.96332]}
      // Other map props...
    >
      <TileLayer
        url="https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}{r}.png"
        attribution="&copy; 
        <a href=&quot;https://www.openstreetmap.org/copyright&quot;>OpenStreetMap</a> 
        contributors"
       />
      <PixiOverlay markers={markers} />
    </Map>
  </React.Fragment>
 );
}
}
export default PixiOverlayClass;

这只是简单的代码。

而且我添加了所有依赖项传单,leaflet-pixi-overlay,pixi.js,react,react-leaflet,use-leaflet

但是我仍然收到错误:

TypeError:无法读取未定义的属性'addLayer' 在NewClass.addTo(leaflet-src.js:6559) 在PixiOverlay.jsx:69

内部呼叫-

   addTo: function (map) {
    map.addLayer(this);
    return this;
 },

这是未定义的。有人可以帮我吗?

reactjs leaflet pixi.js
1个回答
0
投票

升级react-leaflet

© www.soinside.com 2019 - 2024. All rights reserved.