summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorMarkus Koch <markus@notsyncing.net>2020-04-14 18:10:19 +0200
committerMarkus Koch <markus@notsyncing.net>2020-04-14 18:10:19 +0200
commitbe1dc049d63dccd22b60e64a2cf1f27a464b5ee4 (patch)
tree751a45b6f35850cab51d98be209222a8e5921ba0 /scripts
downloadlifomapserver-be1dc049d63dccd22b60e64a2cf1f27a464b5ee4.tar.gz
lifomapserver-be1dc049d63dccd22b60e64a2cf1f27a464b5ee4.tar.bz2
lifomapserver-be1dc049d63dccd22b60e64a2cf1f27a464b5ee4.zip
Initial commit
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/convert_maps.sh53
-rw-r--r--scripts/geojson/cities.json14
-rwxr-xr-xscripts/geojson/fetch_cities.sh10
-rwxr-xr-xscripts/geojson/fetch_single.sh29
4 files changed, 106 insertions, 0 deletions
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 <markus@notsyncing.net>
+#
+# 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