From 36a4d01e86b831240f144793908b04913cb48890 Mon Sep 17 00:00:00 2001 From: Francesco Frassinelli Date: Sun, 3 Mar 2024 22:12:04 +0100 Subject: [PATCH] Add support for Garmin --- backend/Dockerfile | 4 +- backend/Makefile | 2 + backend/cronjob.sh | 1 + backend/garmin.mk | 60 +++++++++++++++++++ backend/scripts/garmin.sh | 58 ++++++++++++++++++ backend/scripts/topojson.sh | 3 +- shell.nix | 2 + .../SideMenu/DownloadItems/DownloadItems.js | 10 +++- 8 files changed, 137 insertions(+), 3 deletions(-) create mode 100644 backend/garmin.mk create mode 100755 backend/scripts/garmin.sh diff --git a/backend/Dockerfile b/backend/Dockerfile index fe7e789..0a55a81 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -15,12 +15,14 @@ RUN --mount=type=cache,sharing=locked,target=/var/cache/apt \ gdal-bin \ `# mapshaper, topojson` \ npm \ + `# garmin styles` \ + git \ && \ rm /etc/cron.daily/apt-compat /etc/cron.daily/dpkg WORKDIR /root # https://github.com/moby/moby/issues/17175 -COPY Makefile . +COPY Makefile garmin.mk . RUN make setup COPY scripts/ scripts/ diff --git a/backend/Makefile b/backend/Makefile index 97c0936..9f8622c 100644 --- a/backend/Makefile +++ b/backend/Makefile @@ -125,5 +125,7 @@ $(WEBAPP_DIR)/%.json: $(TOPOJSON_DIR)/%.json webapp: $(WEBAPP_DIR)/municipalities.json $(WEBAPP_DIR)/limits_IT_regions.json $(WEBAPP_DIR)/limits_IT_provinces.json +include garmin.mk + clean: rm -rf $(WORK_DIR) diff --git a/backend/cronjob.sh b/backend/cronjob.sh index 74458b3..706b793 100755 --- a/backend/cronjob.sh +++ b/backend/cronjob.sh @@ -10,5 +10,6 @@ mkdir -p "$(dirname $logfile)" exec >> "$logfile" exec 2>&1 +make -C /root setup_garmin_data make -C /root pbf make -C /root -j$(nproc) diff --git a/backend/garmin.mk b/backend/garmin.mk new file mode 100644 index 0000000..ebc69b9 --- /dev/null +++ b/backend/garmin.mk @@ -0,0 +1,60 @@ +MKGMAP_URL ?= https://www.mkgmap.org.uk/download/mkgmap-r4917.tar.gz +MKGMAP_DIR = $(WORK_DIR)/mkgmap +MKGMAP = $(MKGMAP_DIR)/mkgmap.jar +MKGMAP_XMX = 8G +MKGMAP_PRIORITY = 10 +SPLITTER_URL ?= https://www.mkgmap.org.uk/download/splitter-r653.jar +SPLITTER = $(MKGMAP_DIR)/splitter.jar +SEA_URL = https://www.thkukuk.de/osm/data/sea-latest.zip +SEA_DIR = $(MKGMAP_DIR)/sea +SEA = $(SEA_DIR)/.dirstamp +BOUNDS_URL = https://www.thkukuk.de/osm/data/bounds-latest.zip +BOUNDS_DIR = $(MKGMAP_DIR)/bounds +BOUNDS = $(BOUNDS_DIR)/.dirstamp + +REPO_URL = https://github.com/lucadelu/ital.img.git +REPO_DIR = $(MKGMAP_DIR)/ital.img +REPO = $(REPO_DIR)/.git/HEAD +STYLES = styles/.directory +STYLES_DIR = $(REPO_DIR)/$(dir $(STYLES)) + +NATION = $(notdir $(patsubst %/,%,$COUNTRY)) + +.PHONY: setup_garmin setup_garmin_data garmin_regioni + +$(MKGMAP): + $(dir_guard) + curl -s "$(MKGMAP_URL)" | bsdtar --strip-components 1 -xf- -C "$(MKGMAP_DIR)" + +$(SPLITTER): $(MKGMAP) + curl -s "$(SPLITTER_URL)" -o "$@" + +$(SEA): + $(dir_guard) + curl -s "$(SEA_URL)" | bsdtar --strip-components 1 -xf- -C "$(SEA_DIR)" + touch $@ + +$(BOUNDS): + $(dir_guard) + curl -s "$(BOUNDS_URL)" | bsdtar -xf- -C "$(BOUNDS_DIR)" + touch $@ + +$(REPO): + cd $(dir $(REPO_DIR)) && git clone -n --depth=1 --filter=tree:0 $(REPO_URL) $(notdir $(REPO_DIR)) + +$(STYLES): $(REPO) + cd $(REPO_DIR) && git sparse-checkout set --no-cone $(dir $(STYLES)) + cd $(REPO_DIR) && git checkout + +setup_garmin_data: $(SEA) $(BOUNDS) +setup_garmin: $(MKGMAP) $(SPLITTER) $(STYLES) +setup: setup_garmin + +PBF_FILES_REGIONI = $(wildcard $(PBF_DIR)/regioni/*.osm.pbf) +garmin_regioni: $(subst /pbf/,/garmin/,$(PBF_FILES_REGIONI:.osm.pbf=.tar.gz)) +all: garmin_regioni + +.NOTPARALLEL: +$(OUTPUT)/garmin/%.tar.gz: $(PBF_DIR)/%.osm.pbf + $(dir_guard) + ./scripts/garmin.sh "$<" "$@" "$(MKGMAP)" "-Xmx$(MKGMAP_XMX) --draw-priority=$(MKGMAP_PRIORITY)" "$(SPLITTER)" "-Xmx$(MKGMAP_XMX)" "$(STYLES_DIR)" "$(SEA_DIR)" "$(BOUNDS_DIR)" diff --git a/backend/scripts/garmin.sh b/backend/scripts/garmin.sh new file mode 100755 index 0000000..2c4e480 --- /dev/null +++ b/backend/scripts/garmin.sh @@ -0,0 +1,58 @@ +#!/bin/bash -eux +# +# Based on https://github.com/lucadelu/ital.img by Luca Delucchi + +INPUT="$1" +OUTPUT="$2" +MKGMAP="$3" +MKGMAP_OPTS="$4" +SPLITTER="$5" +SPLITTER_OPTS="$6" +STYLES_DIR="$7" +SEA_DIR="$8" +BOUNDS_DIR="$9" + +area_id="$(basename $OUTPUT .tar)" +area_name="${area_id#*_}" +temp_dir="$OUTPUT".temp/ + +function clean() { + rm -rf "${temp_dir}" +} +trap clean EXIT INT TERM + +java -jar "$SPLITTER" \ + --max-areas=4096 --max-nodes=3000000 --wanted-admin-level=8 \ + --output-dir="$temp_dir" "$INPUT" +java -jar "$MKGMAP" \ + --style-file="$STYLES_DIR/general" \ + --latin1 \ + --country-name=Italia \ + --country-abbr="IT" \ + --region-name="$area_name" \ + --area-name="$area_name" \ + --family-name="Mappe regionali ital.img" \ + --description="$area_name" \ + --precomp-sea="$SEA_DIR" \ + --generate-sea \ + --bounds="$BOUNDS_DIR" \ + --max-jobs \ + --route \ + --drive-on=detect,right \ + --process-destination \ + --process-exits \ + --location-autofill=is_in,nearest \ + --index \ + --split-name-index \ + --housenumbers \ + --add-pois-to-areas \ + --link-pois-to-ways \ + --preserve-element-order \ + --verbose \ + --name-tag-list=name,name:it,loc_name,reg_name,nat_name \ + --reduce-point-density=3.2 \ + --make-opposite-cycleways \ + --gmapsupp \ + --output-dir="$temp_dir"/ \ + "$temp_dir"/*.osm.pbf +tar -czf "$OUTPUT" "$temp_dir"/gmapsupp.img diff --git a/backend/scripts/topojson.sh b/backend/scripts/topojson.sh index b7cf069..3d5c8c9 100755 --- a/backend/scripts/topojson.sh +++ b/backend/scripts/topojson.sh @@ -25,7 +25,8 @@ select json_object( 'adm', admin_level, '.osm.pbf', 'pbf/regioni/' || filename || '.osm.pbf', '.gpkg', 'gpkg/regioni/' || filename || '.gpkg', - '.obf', 'obf/regioni/' || filename || '.obf' + '.obf', 'obf/regioni/' || filename || '.obf', + '.tar.gz', 'garmin/regioni/' || filename || '.tar.gz' ) )) ) diff --git a/shell.nix b/shell.nix index 3a918f8..1ac7387 100644 --- a/shell.nix +++ b/shell.nix @@ -31,6 +31,8 @@ pkgs.mkShellNoCC { # mapshaper and topojson nodePackages.npm nodejs-slim_21 + # garmin styles + git ]; shellHook = '' export LD_LIBRARY_PATH="${lib-path}" diff --git a/webapp/src/components/SideMenu/DownloadItems/DownloadItems.js b/webapp/src/components/SideMenu/DownloadItems/DownloadItems.js index 1e19f04..b4ab65e 100644 --- a/webapp/src/components/SideMenu/DownloadItems/DownloadItems.js +++ b/webapp/src/components/SideMenu/DownloadItems/DownloadItems.js @@ -37,7 +37,7 @@ const DownloadItems = ({ selectedFeature }) => { const { properties } = selectedFeature; - if (!properties[".gpkg"] && !properties[".osm.pbf"] && !properties[".obf"]) { + if (!properties[".gpkg"] && !properties[".osm.pbf"] && !properties[".obf"] && !properties[".tar.gz"]) { return null; } @@ -68,6 +68,14 @@ const DownloadItems = ({ selectedFeature }) => { istat={properties.istat} /> )} + {properties[".tar.gz"] && ( + + )} ); };