Skip to content

Commit

Permalink
Add support for Garmin
Browse files Browse the repository at this point in the history
  • Loading branch information
frafra committed Mar 4, 2024
1 parent e1c159c commit 36a4d01
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 3 deletions.
4 changes: 3 additions & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
2 changes: 2 additions & 0 deletions backend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions backend/cronjob.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
60 changes: 60 additions & 0 deletions backend/garmin.mk
Original file line number Diff line number Diff line change
@@ -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)"
58 changes: 58 additions & 0 deletions backend/scripts/garmin.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion backend/scripts/topojson.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
))
)
Expand Down
2 changes: 2 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pkgs.mkShellNoCC {
# mapshaper and topojson
nodePackages.npm
nodejs-slim_21
# garmin styles
git
];
shellHook = ''
export LD_LIBRARY_PATH="${lib-path}"
Expand Down
10 changes: 9 additions & 1 deletion webapp/src/components/SideMenu/DownloadItems/DownloadItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -68,6 +68,14 @@ const DownloadItems = ({ selectedFeature }) => {
istat={properties.istat}
/>
)}
{properties[".tar.gz"] && (
<ToolTipButton
tooltip="Garmin Format"
href={config.basePathFiles + "/" + properties[".tar.gz"]}
title="Garmin"
istat={properties.istat}
/>
)}
</div>
);
};
Expand Down

0 comments on commit 36a4d01

Please sign in to comment.