shramov / leaflet-plugins

Plugins for Leaflet library
http://psha.org.ru/b/leaflet-plugins.html
MIT License
722 stars 288 forks source link

The problem of using "Yandex.js" with "react-leaflet" plugin #303

Open azolotova-sc opened 3 years ago

azolotova-sc commented 3 years ago

Hi, I managed to draw a Yandex map using react-leaflet, but after switching to a different route, an error occurs in the Yandex plugin. During debugging, it turned out that the destroy () event occurs earlier than this._container.remove (), and the other component is not rendered, because container no longer exists

mapa

MapPage.tsx

<MapLeaflet center={ [55.7558, 37.6173]} zoom={13} style={{width: '800px', height: '800px'}}>

**_Yandex.js_** _destroy: function (e) { if (!this._map || this._map === e.target) { if (this._yandex) { this._yandex.destroy(); delete this._yandex; } delete this._container; } }, _setEvents: function (map) { var events = { move: this._update }; if (this._zoomAnimated) { events.zoomanim = this._animateZoom; events.zoomend = this._animateZoomEnd; } map.on(events, this); this.once('remove', function () { map.off(events, this); this._container.remove(); // we do not call this until api is initialized (ymaps API expects DOM element) }, this); }, _**Ошибка**_ ![mistake](https://user-images.githubusercontent.com/61736543/106730555-93863e80-661f-11eb-9db0-0cf8045b6474.png)
johnd0e commented 3 years ago

the destroy () event occurs before this._container.remove (),

Is that wrong?

andreynovikov commented 1 year ago

I've just removed this line. I do not understand its purpose as there is another remove() in the code: https://github.com/shramov/leaflet-plugins/blob/master/layer/tile/Yandex.js#L161