import React from "react"; import {HelpPopup, humanFileSize, PageContainer, TabLinks, WROLModeMessage} from "./Common"; import {Route, Routes} from "react-router-dom"; import {getMapImportStatus, importMapFiles} from "../api"; import { Checkbox, PlaceholderLine, TableBody, TableCell, TableFooter, TableHeader, TableHeaderCell, TableRow } from "semantic-ui-react"; import Message from "semantic-ui-react/dist/commonjs/collections/Message"; import {Button, Icon, Loader, Placeholder, Table} from "./Theme"; class ManageMap extends React.Component { constructor(props) { super(props); this.state = { files: null, importing: null, import_running: false, selectedPaths: [], dockerized: null, } } async componentDidMount() { await this.fetchImportStatus(); this.intervalId = setInterval(this.fetchImportStatus, 1000 * 30); } componentWillUnmount() { clearInterval(this.intervalId); } fetchImportStatus = async () => { try { const importStatus = await getMapImportStatus(); this.setState({ files: importStatus['files'], importing: importStatus['importing'], import_running: importStatus['import_running'], dockerized: importStatus['dockerized'], }); } catch (e) { console.error(e); } } import = async (e) => { e.preventDefault(); this.setState({'ready': false}); const {files, selectedPaths} = this.state; if (!selectedPaths || selectedPaths.length === 0) { // No files are selected, import all. let paths = []; for (let i = 0; i < files.length; i++) { paths = paths.concat([files[i].path]); } await importMapFiles(paths); } else { await importMapFiles(selectedPaths); } await this.fetchImportStatus(); } handleCheckbox = (checked, pbf) => { let {selectedPaths} = this.state; if (checked === true) { selectedPaths = selectedPaths.concat([pbf.path]); } else { const index = selectedPaths.indexOf(pbf.path); if (index > -1) { selectedPaths.splice(index, 1); } } this.setState({selectedPaths}); } tableRow = (pbf, disabled) => { let ref = React.createRef(); const {size, path, imported, time_to_import} = pbf; let sizeCells = (<> {humanFileSize(size)} {humanFileSize(size * 25)} {time_to_import} ); return this.handleCheckbox(data.checked, pbf)} /> {path} {path === this.state.importing ? : imported ? 'yes' : 'no'} {size !== null ? sizeCells : } } render() { const {files, selectedPaths, import_running, importing, dockerized} = this.state; let dockerWarning; if (dockerized === true) { dockerWarning = Maps are not fully supported in a Docker container!

Only one PBF can be imported and displayed in the docker container.

To import a map file, run the following docker-compose commands:

  docker-compose stop map
  docker-compose rm map
  docker-compose run --rm -v /absolute/path/to/map.osm.pbf:/data.osm.pbf
                        -v openstreetmap-data:/var/lib/postgresql/12/main map import
                    

Be sure to change /absolute/path/to/map.osm.pbf!

After you have imported a new PBF file, you need to clear the rendered tile cache:

  docker volume rm openstreetmap-rendered-tiles
  docker volume create openstreetmap-rendered-tiles

Start your map container:

  docker-compose up -d map
} let downloadMessage = Where do I get map files?

You can download map files from  https://download.geofabrik.de/

Download only the areas you need. Large regions like all of Asia, or the entire planet are most likely too large and won't render quickly. I recommend only importing files less than 1GB on a Raspberry Pi.

Only *.osm.pbf files are supported!

Place downloaded map files into map/pbf so they can be imported here.

let importingLoader = ( Importing: {importing} ); let disabled = dockerized || !files || files.length === 0 || import_running; let importButton = ; let rows; if (!files) { // Fetch request is not complete. rows = ; } else if (files.length === 0) { rows = No PBF map files were found in map/pbf ; } else { rows = files.map(i => this.tableRow(i, disabled)); } let spaceHelpPopup = ; let timeHelpPopup = ; return {dockerWarning} {downloadMessage} {importingLoader} PBF File Imported Size Space Required {spaceHelpPopup} Time to Import {timeHelpPopup} {rows} {importButton}
} } function MapApp() { return (