From be1dc049d63dccd22b60e64a2cf1f27a464b5ee4 Mon Sep 17 00:00:00 2001 From: Markus Koch Date: Tue, 14 Apr 2020 18:10:19 +0200 Subject: [PATCH] Initial commit --- .gitignore | 1 + index.html | 164 ++++++++++++++++++++++++++++++++ scripts/convert_maps.sh | 53 +++++++++++ scripts/geojson/cities.json | 14 +++ scripts/geojson/fetch_cities.sh | 10 ++ scripts/geojson/fetch_single.sh | 29 ++++++ tiles/index.php | 3 + 7 files changed, 274 insertions(+) create mode 100644 .gitignore create mode 100644 index.html create mode 100755 scripts/convert_maps.sh create mode 100644 scripts/geojson/cities.json create mode 100755 scripts/geojson/fetch_cities.sh create mode 100755 scripts/geojson/fetch_single.sh create mode 100644 tiles/index.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e22bc1f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +tiles/**/ diff --git a/index.html b/index.html new file mode 100644 index 0000000..1c4ecdd --- /dev/null +++ b/index.html @@ -0,0 +1,164 @@ + + + + + LinuxWorks Minetest Map (unofficial) + + + + + + + + +
+ + + + diff --git a/scripts/convert_maps.sh b/scripts/convert_maps.sh new file mode 100755 index 0000000..32ef029 --- /dev/null +++ b/scripts/convert_maps.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# Convert a huge .png file into smaller chunks for LeafletJS. +# +# Copyright (C) 2020 Markus Koch +# +# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. +# You can obtain a copy of the license at https://mozilla.org/MPL/2.0/. + +# TODO: The width of the input png has to be a multiple of TILESIZE, otherwise bad things will happen. +# Workaround for now is to add white borders on the bottom and right: +# `convert $MAPFILE -extent ${crop}x${crop} -gravity NorthWest $MAPFILE.scaled.png` + +TILESIZE=256 +MAPNAME="world-2020-04-09" +MAPFILE="../$MAPNAME.png" + +width=`file "$MAPFILE" | sed -n "s/.* \([0-9]\+\) x \([0-9]\+\).*/\1/p"` +crop=$TILESIZE +zoom=0 + +while true; do + out="$MAPNAME/$zoom" + tempfile=$out/temp.png + + echo "" + echo "Generating maps for zoomlevel $zoom to $out..." + + mkdir -p $out; + + if [ ! -f "$tempfile" ]; then + if [ $crop -ge $width ]; then + echo " Reached max zoom at zoomlevel $zoom [using original zoom]" + cp $MAPFILE $tempfile + #convert $MAPFILE -extent ${crop}x${crop} -gravity NorthWest $tempfile + else + echo " Scaling map for zoomlevel $zoom" + convert $MAPFILE -resize ${crop}x${crop} $tempfile + fi + else + echo " Reusing existing scaled image" + fi + + echo " Generating tiles..." + convert $tempfile -crop ${TILESIZE}x${TILESIZE} +adjoin $out/%05d.png + + rm $tempfile + + if [ $crop -ge $width ]; then + break; + fi + crop=$(($crop * 2)) + zoom=$(($zoom + 1)) +done; diff --git a/scripts/geojson/cities.json b/scripts/geojson/cities.json new file mode 100644 index 0000000..d66fd89 --- /dev/null +++ b/scripts/geojson/cities.json @@ -0,0 +1,14 @@ +[ +{ "type": "Feature", "properties": { "name": "Anju Crossing", "amenity": "City", "description": "Anju Crossing is {{Player|Anju64}}'s settlement, located north of [[Spawn]].", "image": "https://wiki.linux-forks.de/mediawiki/images/thumb/0/0e//250px-" }, "geometry": { "type": "Point", "coordinates": [-337, 403] } }, +{ "type": "Feature", "properties": { "name": "Crossroads", "amenity": "City", "description": "Crossroads is a city built by {{Player|Ywang}} and some contributors.", "image": "https://wiki.linux-forks.de/mediawiki/images/thumb/0/0e//250px-" }, "geometry": { "type": "Point", "coordinates": [1771, 991] } }, +{ "type": "Feature", "properties": { "name": "Fatamorgan City", "amenity": "City", "description": "Fatamorgan City is a hamlet situated south of [[Newton]].", "image": "https://wiki.linux-forks.de/mediawiki/images/thumb/0/0e/Fatamorgan_aerial.jpeg/250px-Fatamorgan_aerial.jpeg" }, "geometry": { "type": "Point", "coordinates": [-742, -1421] } }, +{ "type": "Feature", "properties": { "name": "Neverbuild", "amenity": "City", "description": "Neverbuild is an city founded in the Lava/Savannah biome.", "image": "https://wiki.linux-forks.de/mediawiki/images/thumb/0/0e/Neverbuild_panorama.png/250px-Neverbuild_panorama.png" }, "geometry": { "type": "Point", "coordinates": [1350, 1940] } }, +{ "type": "Feature", "properties": { "name": "Origin", "amenity": "City", "description": "Origin is a coastal city built around the world origin of coordinates, managed by {{Player|Felfa}}.", "image": "https://wiki.linux-forks.de/mediawiki/images/thumb/0/0e//250px-" }, "geometry": { "type": "Point", "coordinates": [0, 0] } }, +{ "type": "Feature", "properties": { "name": "Personhood", "amenity": "City", "description": "Personhood is a major city in the northeast of the map and the previous beginner area.", "image": "https://wiki.linux-forks.de/mediawiki/images/thumb/0/0e/Personhood.png/250px-Personhood.png" }, "geometry": { "type": "Point", "coordinates": [1532, 2971] } }, +{ "type": "Feature", "properties": { "name": "Riverside", "amenity": "City", "description": "Riverside is a city located south of [[Spawn]].", "image": "https://wiki.linux-forks.de/mediawiki/images/thumb/0/0e//250px-" }, "geometry": { "type": "Point", "coordinates": [-600, -787] } }, +{ "type": "Feature", "properties": { "name": "South Forest", "amenity": "City", "description": "South Forest is a former noob town managed by {{Player|dhausmig}}; it was the first noob town.", "image": "https://wiki.linux-forks.de/mediawiki/images/thumb/0/0e//250px-" }, "geometry": { "type": "Point", "coordinates": [285, -2045] } }, +{ "type": "Feature", "properties": { "name": "Spawn", "amenity": "City", "description": "Spawn is the capital of the Linux Works minetest server world.", "image": "https://wiki.linux-forks.de/mediawiki/images/thumb/0/0e//250px-" }, "geometry": { "type": "Point", "coordinates": [-675, -496] } }, +{ "type": "Feature", "properties": { "name": "Stallmangrad", "amenity": "City", "description": "", "image": "https://wiki.linux-forks.de/mediawiki/images/thumb/0/0e/Stallmangrad_dec_2018.png/250px-Stallmangrad_dec_2018.png" }, "geometry": { "type": "Point", "coordinates": [1896, -2205] } }, +{ "type": "Feature", "properties": { "name": "Trisiston", "amenity": "City", "description": "", "image": "https://wiki.linux-forks.de/mediawiki/images/thumb/0/0e/Trisiston_rathaus.png/250px-Trisiston_rathaus.png" }, "geometry": { "type": "Point", "coordinates": [-4250, -3130] } }, +{ "type": "Feature", "properties": { "name": "X Nihilo City", "amenity": "City", "description": "X Nihilo City is a ghost town in the far north of the map, at the end of the [[X Nihilo Mainline]].", "image": "https://wiki.linux-forks.de/mediawiki/images/thumb/0/0e/File:XNihilo.png/250px-File:XNihilo.png" }, "geometry": { "type": "Point", "coordinates": [2246, 5942] } }, +{}] diff --git a/scripts/geojson/fetch_cities.sh b/scripts/geojson/fetch_cities.sh new file mode 100755 index 0000000..16e81c1 --- /dev/null +++ b/scripts/geojson/fetch_cities.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +json=`curl 'https://wiki.linux-forks.de/mediawiki/api.php?action=query&format=json&list=categorymembers&cmtitle=Category:City&cmlimit=100'` +cities=`echo "$json" | json_reformat | sed -n 's/.*"title":\s*"\([^"]*\).*/\1/p' | tr ' ' '_' | tr '\n' ' '` + +echo "[" +for city in $cities; do + ./fetch_single.sh "$city" +done +echo "{}]" diff --git a/scripts/geojson/fetch_single.sh b/scripts/geojson/fetch_single.sh new file mode 100755 index 0000000..61ab79d --- /dev/null +++ b/scripts/geojson/fetch_single.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +json=`curl "https://wiki.linux-forks.de/mediawiki/api.php?action=query&prop=revisions&rvprop=content&format=json&titles=$1&rvsection=0&rvslots=main" | sed -s "s/\\\\\\\\n//g"` + +title=`echo $json | sed -n 's/.*"title":\s*"\([^"]\+\).*/\1/p'` +image=`echo "$json" | sed -n "s/.*image = \([^|]*\).*/\1/p"` + +coords=`echo "$json" | sed -n "s/.*coordinates = {{Co|\([^}]*\).*/\1/p"` +coord_x=`echo "$coords" | sed -n "s/\([^|]\+\).*/\1/p"` +coord_y=`echo "$coords" | sed -n "s/.*|\([^|]\+\).*/\1/p"` + +description=`echo $json | sed -n "s/.*coordinates.*[^']*'''\([^']*\)'''\([^\.]*\).*/\1\2./p" +` + +if [[ "$coord_x" != "" && "$coord_y" != "" ]]; then + echo "{\ + \"type\": \"Feature\",\ + \"properties\": {\ + \"name\": \"$title\",\ + \"amenity\": \"City\",\ + \"description\": \"$description\",\ + \"image\": \"https://wiki.linux-forks.de/mediawiki/images/thumb/0/0e/$image/250px-$image\"\ + },\ + \"geometry\": {\ + \"type\": \"Point\",\ + \"coordinates\": [$coord_x, $coord_y]\ + }\ + }," +fi diff --git a/tiles/index.php b/tiles/index.php new file mode 100644 index 0000000..62a2de0 --- /dev/null +++ b/tiles/index.php @@ -0,0 +1,3 @@ +