с учетом следующей реализации:
getCurrentMap() {
const {currentlyActiveMap: {task, type, layout}} = this.mapStore
if (this.currentMap) this.currentMap.eachLayer(layer => {
this.currentMap.removeLayer(layer)
})
let centerX = 0
let centerY = 0
if (layout.image_width > layout.image_height) {
centerX = layout.tile_size / 2
centerY = (layout.tile_size * layout.image_height / layout.image_width) / 2
} else {
centerX = (layout.tile_size * layout.image_width / layout.image_height) / 2
centerY = layout.tile_size / 2
}
this.currentMap = this.currentMap || Leaflet.map(this.map, {
center: [-centerY, centerX],
crs: Leaflet.CRS.Simple,
minZoom: 0,
maxZoom: layout.max_zoom_level + 1,
maxBounds: [[layout.tile_size, -layout.tile_size], [-2 * layout.tile_size, 2 * layout.tile_size]],
doubleClickZoom: false,
attributionControl: false,
zoom: 2
})
let currentLayer = Leaflet.tileLayer(`${layout.tiling_url}`)
this.currentMap.addLayer(currentLayer)
return (
<Fragment>
<button type='button' className={styles.mapPanelCreateButton} onClick={this.handleCreateTask}>
<FaPlus/>
</button>
</Fragment>
)
}
render() {
const mapLayout = !!this.taskStore.loading || !this.mapStore.currentlyActiveMap
? <LoadingContainer transparent={true}/>
: this.getCurrentMap()
return (
<Fragment>
<div id='map' className={styles.mapPanelContainer} ref={map => this.map = map}></div>
{mapLayout}
</Fragment>
)
}
Мне не удается отобразить карту, а также я не могу обновить / поменять или иным образом изменить данные на карте (необходимо переключиться между пользовательским мозаичным изображением и глобальной картой). Идентификаторы что-то не так с этой реализацией или есть лучший вариант для достижения этой цели?
Как всегда ценится любое направление, поэтому спасибо заранее!
также другая реализация с тем же результатом:
Leaflet.tileLayer(`${layout.tiling_url}`).addTo(this.currentMap)
РЕДАКТИРОВАТЬ: Я также получаю печально известную:
Uncaught Error: контейнер карты уже инициализирован.