diff options
-rw-r--r-- | .gitmodules | 8 | ||||
m--------- | htdocs/awesomemarkers | 0 | ||||
m--------- | htdocs/fa | 0 | ||||
-rw-r--r-- | htdocs/geojson/update.php | 16 | ||||
-rwxr-xr-x | htdocs/geojson/update_all.sh | 19 | ||||
-rw-r--r-- | htdocs/index.html | 8 | ||||
-rw-r--r-- | htdocs/mapscript.js | 178 | ||||
m--------- | lifo-dijkstraserv | 0 | ||||
-rwxr-xr-x | scripts/convert_all.sh | 62 | ||||
-rwxr-xr-x | scripts/convert_maps.sh | 4 | ||||
-rwxr-xr-x | scripts/geojson/get_rendered_meta.sh | 2 | ||||
-rwxr-xr-x | scripts/geojson/maps/fetch_bodiesofwater.sh | 62 | ||||
-rwxr-xr-x | scripts/geojson/maps/fetch_trainlines.sh | 66 | ||||
-rwxr-xr-x | scripts/geojson/maps/update_all.sh | 15 |
14 files changed, 392 insertions, 48 deletions
diff --git a/.gitmodules b/.gitmodules index 36e7ca9..b7d6b58 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,9 @@ [submodule "lifo-dijkstraserv"] path = lifo-dijkstraserv - url = https://notsyncing.net:8080/markus/lifo-dijkstraserv.git + url = https://git.notsyncing.net/markus/lifo-dijkstraserv.git +[submodule "htdocs/fa"] + path = htdocs/fa + url = https://github.com/FortAwesome/Font-Awesome +[submodule "htdocs/awesomemarkers"] + path = htdocs/awesomemarkers + url = https://github.com/lvoogdt/Leaflet.awesome-markers diff --git a/htdocs/awesomemarkers b/htdocs/awesomemarkers new file mode 160000 +Subproject 4fcacdfc82ed58f0173062851a4cda713845df8 diff --git a/htdocs/fa b/htdocs/fa new file mode 160000 +Subproject fcec2d1b01ff069ac10500ac42e4478d20d21f4 diff --git a/htdocs/geojson/update.php b/htdocs/geojson/update.php new file mode 100644 index 0000000..06e2a13 --- /dev/null +++ b/htdocs/geojson/update.php @@ -0,0 +1,16 @@ +<?php + $fn = "/tmp/lifo_update_ts"; + $ctime = time(); + $ltime = (int)(file_get_contents($fn)); + $ntime = $ltime + 60*1 * 30; + if (isset($_GET['force'])) + $ntime = 0; + if ($ctime > $ntime) { + file_put_contents($fn, $ctime); + echo "Downloading... "; + flush(); + system("cd /srv/http/maps.linux-forks.de/geojson/; ./update_all.sh"); + } else { + echo "Next update in " . intval(($ntime - $ctime) / 60) . " minutes."; + } +?> diff --git a/htdocs/geojson/update_all.sh b/htdocs/geojson/update_all.sh new file mode 100755 index 0000000..e25d843 --- /dev/null +++ b/htdocs/geojson/update_all.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +function fetch() { + if [[ "$3" != "" ]]; then + fn="$3" + else + fn="$1" + fi + "./fetch_$1.sh" "$2" | json_reformat -m > "$fn.json.tmp" + rm -f "$fn.json" + mv "$fn.json.tmp" "$fn.json" +} + +fetch streets +fetch city_outlines +fetch trainlines "Train Lines" +fetch trainlines "Access Paths" trainlines_access +fetch bodiesofwater "Rivers" rivers +fetch bodiesofwater "Oceans, Seas, and Lakes" oceans diff --git a/htdocs/index.html b/htdocs/index.html index 9b5e2c4..9dfb71e 100644 --- a/htdocs/index.html +++ b/htdocs/index.html @@ -1,14 +1,14 @@ <!DOCTYPE html> <html> <head> - <title>LinuxWorks Minetest Map</title> + <title>LinuxWorks Minetest Map [beta]</title> <meta charset="utf-8"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="fa/css/all.css"> - <link rel="stylesheet" href="awesomemarkers/leaflet.awesome-markers.css"> + <link rel="stylesheet" href="awesomemarkers/dist/leaflet.awesome-markers.css"> <link rel="stylesheet" href="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css" integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ==" crossorigin=""/> <script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js" integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew==" crossorigin=""></script> - <script src="awesomemarkers/leaflet.awesome-markers.js"></script> + <script src="awesomemarkers/dist/leaflet.awesome-markers.js"></script> <!-- Streets --> <script src='leafletjs/ctxtextpath.js'></script> <script src='leafletjs/L.LabelTextCollision.js'></script> @@ -48,7 +48,7 @@ -ms-interpolation-mode: nearest-neighbor; /* IE8+ */ } </style> - <script src="mapscript.js"></script> + <script src="mapscript.js?v3"></script> <script src="streeteditor.js"></script> </body> </html> diff --git a/htdocs/mapscript.js b/htdocs/mapscript.js index 3eccb65..6eb6e9f 100644 --- a/htdocs/mapscript.js +++ b/htdocs/mapscript.js @@ -5,6 +5,8 @@ var polyconf_show_street_names = 5; // Zoom level for when to start showing stre var polyconf_show_cities = 5; /* City outlines will be filled on this level and further away */ var polyconf_show_districts = 4; /* Shown from polyconf_show_cities until this*/ +var polyconf_show_oceans = 5; // Show ocean labels from zoom level + var dijkstraserv_base = "https://notsyncing.net/dijkstra/"; var wikiurl_base = "https://wiki.linux-forks.de/mediawiki/index.php/" var tiles_base = "https://notsyncing.net/maps.linux-forks.de/tiles/" @@ -13,12 +15,14 @@ var streetLabelsRenderer = new L.StreetLabels({ collisionFlg: true, propertyName: 'name', showLabelIf: function (layer) { - switch (layer.geometry.type) { + switch (layer.feature.geometry.type) { case "LineString": if (mymap.getZoom() <= polyconf_show_street_names) return false; break; case "Polygon": + if (layer.myName == "Oceans") + return (mymap.getZoom() > polyconf_show_oceans); if (mymap.getZoom() > polyconf_show_street_names) return false; break; @@ -34,7 +38,7 @@ var streetLabelsRenderer = new L.StreetLabels({ fontSizeUnit: "px", lineWidth: 3.0, fillStyle: "black", - strokeStyle: "white", + strokeStyle: "white" }, }); @@ -48,38 +52,44 @@ streetLabelsRenderer._getCollisionFlag = function (layer) { streetLabelsRenderer._getDynamicFontSize = function (layer) { zoom = mymap.getZoom(); - switch (layer.geometry.type) { - case "LineString": - if (zoom <= 8) - return 11; - else - return 2**(zoom - 9) * 11; + switch (layer.myName) { + case "Oceans": + return size *= 2.0/3;; break; - case "Polygon": - var size; - if (zoom >= 4) - size = 30; - else - size = 20; - switch (layer.properties.type) { - case "city": - break; - case "town": - size *= 2.0/3.0; - break; - case "village": - size *= 1.5/3; - break; - case "district": - size *= 2.0/3; + default: + switch (layer.feature.geometry.type) { + case "LineString": + if (zoom <= 8) + return 11; + else + return 2**(zoom - 9) * 11; break; + case "Polygon": + var size; + if (zoom >= 4) + size = 30; + else + size = 20; + switch (layer.feature.properties.type) { + case "city": + break; + case "town": + size *= 2.0/3.0; + break; + case "village": + size *= 1.5/3; + break; + case "district": + size *= 2.0/3; + break; + default: + size *= 0.5/3; + break; + } + return size; default: - size *= 0.5/3; break; } - return size; - default: - break; } return 10; } @@ -95,6 +105,24 @@ var style_outlines = { var style_streets = { }; +var style_trains = { + color: "yellow" + }; + +var style_tech = { + color: "red" + }; + +var style_rivers = { + color: "blue", + fillColor: "#00999955", + }; + +var style_oceans = { + color: "#00556655", + fillColor: "#00999955", + }; + var style_route = { radius: 8, fillColor: "#00ff00", @@ -176,7 +204,7 @@ function load_tiles(name, id) { if (name != "") { url = tiles_base + '{id}/{z}/{y}/{x}.png'; } - var satellite = L.tileLayer(url, { + var satellite = new L.TileLayer(url, { maxZoom: 14 /*8*/, maxNativeZoom: 6, minNativeZoom: 0, @@ -195,6 +223,7 @@ function load_tiles(name, id) { var current_location = ""; var current_feature = null; +var current_layer = null; function load_geojson(name, url, geotype, iconcolor, active=1, style={}) { var xhttp_ps = new XMLHttpRequest(); xhttp_ps.onreadystatechange = function() { @@ -206,10 +235,14 @@ function load_geojson(name, url, geotype, iconcolor, active=1, style={}) { switch (geotype) { case "street": + case "train": onEachFeature = function(feature, layer) { layer.myTag = geotype; layer.myName = name; + if (geotype == "train") + layer.no_search = true layer.on("click", function (e) { + current_layer = layer; current_feature = feature; }); }; @@ -225,6 +258,7 @@ function load_geojson(name, url, geotype, iconcolor, active=1, style={}) { break; default: /* else it is a marker with the specified icon */ onEachFeature = function(feature, layer) { + layer.myName = name; label = String(feature.properties.name) layer.bindPopup('<h1><a target="_blank" href="' + wikiurl_base + feature.properties.name + '">' + feature.properties.name + '</a> (' + feature.geometry.coordinates + ')</h1>' + '<p><img style="width:100%" src="' + feature.properties.image + '"></p>' + '<p>' + feature.properties.description + '</p>'); layer.bindTooltip(label, { @@ -323,13 +357,29 @@ function load_geojson(name, url, geotype, iconcolor, active=1, style={}) { xhttp_ps.send(); } -load_tiles("Satellite (2020-04-09)", 'world-2020-04-09').addTo(mymap); -load_tiles("Satellite (2019-05-04, wrong coords)", 'world-2019-05-04'); +load_tiles("Satellite (2020-12-13)", 'world-2020-12-13').addTo(mymap); +load_tiles("Satellite (2020-11-20)", 'world-2020-11-20'); +load_tiles("Satellite (2020-08-30)", 'world-2020-08-30'); +load_tiles("Satellite (2020-06-04)", 'world-2020-06-04'); +load_tiles("Satellite (2020-04-26)", 'world-2020-04-26'); +load_tiles("Satellite (2020-04-09)", 'world-2020-04-09'); load_tiles("None", ''); load_geojson("All", "./geojson/all.json", "auto", "auto", 0); load_geojson("Streets", "./geojson/streets.json", "street", "auto", 1, style_streets); +load_geojson("Trainlines (beta)", "./geojson/trainlines.json", "train", "auto", 1, style_trains); +load_geojson("TL Access (tech layer)", "./geojson/trainlines_access.json", "train", "auto", 0, style_tech); +load_geojson("Railroad Tracks", "./geojson/trains.json", "train", "auto", 0, style_trains); load_geojson("Cities", "./geojson/city_outlines.json", "outline", "auto", 1, style_outlines); +load_geojson("Rivers", "./geojson/rivers.json", "street", "auto", 1, style_rivers); +load_geojson("Oceans", "./geojson/oceans.json", "outline", "auto", 1, style_oceans); + +function update_geojson() { + var xhttp_ps = new XMLHttpRequest(); + xhttp_ps.open("GET", "https://notsyncing.net/maps.linux-forks.de/geojson/update.php", true); + xhttp_ps.send(); +} +update_geojson(); L.control.scale().addTo(mymap); @@ -387,7 +437,11 @@ function build_sidebar() { route_element.style.overflow = "scroll"; route_element.style.padding = "6px"; route_element.style.height = "100%"; - route_element.innerHTML = '<a href="#" onclick="toggle_search(\'search\',1);return false;"><-- Return to search<br></a><input style="width:100%;" id="route_start" name="lifo_route_loc" type="search" placeholder="Start at x,y"><br><input style="width:100%;" id="route_destination" name="lifo_route_loc" type="search" placeholder="Go to x,y"><br><input id="route_submit" type="button" style="width:100%;" value="Go!" onclick="route(event)"><div id="route_results"></div>'; + route_element.innerHTML = '<a href="#" onclick="toggle_search(\'search\',1);return false;"><-- Return to search<br><br></a>\ + <input style="width:100%;" id="route_start" name="lifo_route_loc" type="search" placeholder="Start at x,y"><br>\ + <input style="width:100%;" id="route_destination" name="lifo_route_loc" type="search" placeholder="Go to x,y"><br>\ + <input type="checkbox" name="use_trains" id="use_trains" value="trains" checked disabled=true><label for="use_trains"> Use trains (only S12)</label><br>\ + <input id="route_submit" type="button" style="width:100%;" value="Go!" onclick="route(event)"><div id="route_results"></div>'; } } @@ -451,6 +505,8 @@ function search(e) { for (key in layers._layers[i].layer._layers) { item = layers._layers[i].layer._layers[key]; + if (item.hasOwnProperty("no_search")) + break; switch (item.feature.geometry.type) { case "Point": regex = new RegExp(query, 'i'); @@ -504,7 +560,7 @@ function search(e) { var route_layer; function route(e) // BOOKMARK -{ +{ if (route_layer) { mymap.removeLayer(route_layer); } @@ -533,7 +589,7 @@ function route(e) // BOOKMARK last_through = ""; geojson.eachLayer( function(layer) { if (last_through != layer.feature.properties.through) { - str += '<li><a href="#" onclick="latLng2 = L.latLng(' + layer.feature.geometry.coordinates[0][1] + ',' + layer.feature.geometry.coordinates[0][0] + '); jump_to(latLng2); return false;">' + htmlEntities(layer.feature.properties.description) + "</a></li>"; + str += '<li><a href="#" onclick="latLng2 = L.latLng(' + layer.feature.geometry.coordinates[0][1] + ',' + layer.feature.geometry.coordinates[0][0] + '); jump_to(latLng2); return false;">' + htmlEntities(layer.feature.properties.description).replace('[T]', '🚆️') + "</a></li>"; last_through = layer.feature.properties.through; } }); @@ -606,6 +662,31 @@ L.GotoControl = L.MyControl.extend({ mymap.addControl(new L.SearchControl()); mymap.addControl(new L.GotoControl()); +L.CurrentPosControl = L.Control.extend({ + options: { + position : 'bottomleft', + callback: null, + kind: "", + html: '' + }, + onAdd: function (map) { + container = L.DomUtil.create('div', 'leaflet-control-scale leaflet-bar'); + container.style.visibility = "hidden"; + div = L.DomUtil.create('div', '', container); + div.style.backgroundColor = "white"; + div.style.paddingLeft = "4px"; + div.style.paddingRight = "4px"; + div.style.borderRadius = "2px"; + div.style.margin = "2px"; + div.style.opacity = "0.6"; + div.style.fontWeight = "bold"; + div.innerHTML = ""; + div.id = "current_position_label"; + return container; + } +}); +mymap.addControl(new L.CurrentPosControl()); + var popup = L.popup(); L.AwesomeMarkers.Icon.prototype.options.prefix = 'fa'; @@ -614,19 +695,29 @@ var baseballIcon = L.AwesomeMarkers.icon({ markerColor: 'red' }); +function escapeHtml(text) { + return text + .replace(/&/g, "&") + .replace(/</g, "<") + .replace(/>/g, ">") + .replace(/"/g, """) + .replace(/'/g, "'"); +} + function onMapClick(e) { var addinfo = ""; pos = resolve_latlng(e.latlng); route_links = '<br><a href="#" onclick="latLng2 = L.latLng(' + pos.lng + ',' + pos.lat + '); set_route_start(latLng2); return false;">[route from here]</a>'; route_links += ' <a href="#" onclick="latLng2 = L.latLng(' + pos.lng + ',' + pos.lat + '); set_route_destination(latLng2); return false;">[route to here]</a>'; if (current_location != "") - addinfo = " (part of <a target=\"_blank\" href='" + wikiurl_base + current_location + "'>" + current_location + "</a>)"; + addinfo = " (part of <a target=\"_blank\" href=\"" + wikiurl_base + encodeURIComponent(current_location) + "\">" + escapeHtml(current_location) + "</a>)"; if (current_feature) { - popup.setLatLng(e.latlng).setContent("This is " + current_feature.properties.name + addinfo + route_links).openOn(mymap); + popup.setLatLng(e.latlng).setContent("This is <a target=\"_blank\" href=\"" + wikiurl_base + current_layer.myName + ":" + encodeURIComponent(current_feature.properties.name) + "\">" + escapeHtml(current_feature.properties.name) + "</a>" + addinfo + route_links).openOn(mymap); } else { popup.setLatLng(e.latlng).setContent("You clicked the map at " + pos.lng + "," + pos.lat + addinfo + route_links).openOn(mymap); } current_feature = null; + current_layer = null; current_location = ""; } @@ -687,6 +778,17 @@ function update_outline_visibility() { }); } +function update_current_mouse_position(e) { + var lbl = document.getElementById('current_position_label'); + if (e.type == "mouseout") { + lbl.parentElement.style.visibility = "hidden"; + return; + } + lbl.parentElement.style.visibility = "visible"; + pos = resolve_latlng(e.latlng); + lbl.innerHTML = pos.lng + "," + pos.lat; +} + mymap.on('zoomend', function () {is_user_drag = 1; update_hash_from_position();}); mymap.on('zoomend', update_aa_status); mymap.on('zoomend', update_street_width); @@ -695,6 +797,8 @@ mymap.on('moveend', update_hash_from_position); mymap.on('dragstart', function () { is_user_drag = 1;}); mymap.on('keydown', function (e) { if (e.originalEvent.code.match(/Arrow.*/)) is_user_drag = 1;}); mymap.on('overlayadd', function (e) { update_street_width(); update_outline_visibility(); }); +mymap.on('mousemove', update_current_mouse_position); +mymap.on('mouseout', update_current_mouse_position); function onHashChange(e, hash=null) { if (!hash) diff --git a/lifo-dijkstraserv b/lifo-dijkstraserv -Subproject d7d59322c57c9154faa537d8d00e4ec2071f09f +Subproject faa5d7ca4b9b16442de4bd3c3cc49567cfd5659 diff --git a/scripts/convert_all.sh b/scripts/convert_all.sh new file mode 100755 index 0000000..cf566ad --- /dev/null +++ b/scripts/convert_all.sh @@ -0,0 +1,62 @@ +#!/bin/bash + + +OUTDIR=`pwd`/tiles +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" + +mode="$1" + +if [ "$mode" == "legacy" ]; then + MAPSERVER='http://old-maps.li-fo.de/' + FILES=`curl "$MAPSERVER" | sed -n 's/.*<a href="\([^\.]\+\.png\).*/\1/p'` +else + MAPSERVER='https://lifomaps.de' + FILES=`curl "$MAPSERVER" | sed -n 's/.*>\(world-[0-9\-]\+\.png\).*/\1/p'` +fi + +if [[ "$FILES" == "" ]]; then + echo "ERROR: Could not detect latest map file." + exit +fi + +for FILE in $FILES; do + REMOTE_URL="$MAPSERVER/$FILE" + LOCAL_FILE="`echo $FILE | sed 's#.*/##'`" + LOCAL_URL="$OUTDIR/$LOCAL_FILE" + MAPNAME=`echo $LOCAL_URL | sed 's/.*\/\([^\.]\+\).*/\1/g'` + + echo "# Downloading and converting $MAPNAME." + + mkdir -p $OUTDIR + cd $OUTDIR + + if [ ! -d "$OUTDIR/$MAPNAME" ]; then + echo "Downloading latest map file..." + curl -C - "$REMOTE_URL" -o "$LOCAL_URL" + + if [ "$mode" == "legacy" ]; then + echo "Patching map (for map exports prior to 2019-07-09)..." + OSIZE=`file $LOCAL_URL | sed -n 's/.*PNG image data, \([0-9]\+\).*/\1/p'` + NSIZE=$(($OSIZE+1008)) + RESIZED_URL="$LOCAL_URL-temp.png" + convert $LOCAL_URL -gravity SouthEast -extent ${NSIZE}x${NSIZE} $RESIZED_URL + rm $LOCAL_URL + mv $RESIZED_URL $LOCAL_URL + fi + + echo "Resizing map..." + OSIZE=`file $LOCAL_URL | sed -n 's/.*PNG image data, \([0-9]\+\).*/\1/p'` + NSIZE=$((2**6 * 256)) + RESIZED_URL="$LOCAL_URL-resized.png" + convert $LOCAL_URL -extent ${NSIZE}x${NSIZE} -gravity NorthWest $RESIZED_URL + + echo "Converting map..." + $SCRIPT_DIR/convert_maps.sh $MAPNAME $RESIZED_URL + + echo "Cleaning up..." + rm $RESIZED_URL + rm $LOCAL_URL + else + echo "Skipping $MAPNAME." + fi +done diff --git a/scripts/convert_maps.sh b/scripts/convert_maps.sh index faeea22..16bfe9f 100755 --- a/scripts/convert_maps.sh +++ b/scripts/convert_maps.sh @@ -11,8 +11,8 @@ # `convert $MAPFILE -extent ${crop}x${crop} -gravity NorthWest $MAPFILE.scaled.png` TILESIZE=256 -MAPNAME="world-2020-04-09" -MAPFILE="../$MAPNAME.png" +MAPNAME="$1" +MAPFILE="$2" width=`file "$MAPFILE" | sed -n "s/.* \([0-9]\+\) x \([0-9]\+\).*/\1/p"` crop=$TILESIZE diff --git a/scripts/geojson/get_rendered_meta.sh b/scripts/geojson/get_rendered_meta.sh index 120645c..9debc53 100755 --- a/scripts/geojson/get_rendered_meta.sh +++ b/scripts/geojson/get_rendered_meta.sh @@ -9,7 +9,7 @@ categories="" data=`curl -s "$1"` -temp=`echo "$data" | sed -n 's/<p>\(.\+\).*/\1/p' | head -n1` +temp=`echo "$data" | sed -n 's/<p>\(.\+\).*/\1/p' | grep -v -e '^<br />$' | sed 's#^</p>##' | head -n1` if [ "$temp" != "" ]; then temp=`echo "$temp" | sed "s#href=\"#href=\"$BASE#g" | sed 's/"/\\\\"/g' | sed 's/\t//g'` description="$temp" diff --git a/scripts/geojson/maps/fetch_bodiesofwater.sh b/scripts/geojson/maps/fetch_bodiesofwater.sh new file mode 100755 index 0000000..8cd4a29 --- /dev/null +++ b/scripts/geojson/maps/fetch_bodiesofwater.sh @@ -0,0 +1,62 @@ + #!/bin/bash + +json=`curl 'https://wiki.linux-forks.de/mediawiki/api.php?action=query&prop=revisions&rvprop=content&format=json&titles=Maps:BodiesOfWater'` +data=`echo "$json" | json_reformat | sed -e 's/\\\\n//g' -n -e 's/begin:mapdata\([^}]\+\)/\1/gp' | sed -e "s/|-|/}/g"` + +section="" +echo "[" +export IFS="}" +for entry in $data; do + this_section=`echo $entry | sed -n 's/.*== \([^=]\+\) ==.*/\1/p'` + if [[ "$this_section" != "" ]]; then + section=$this_section + fi + + if [[ "$section" != "$1" ]]; then + continue + fi + + case "$section" in + "Rivers") + name=`echo "$entry" | sed -n 's/\s*\([^|]\+\).*/\1/p' | sed 's/ $//'` + type=`echo "$entry" | sed -n 's/\s*\([^|]\+\)||\s*\([^|]\+\).*/\2/p' | sed 's/ $//'` + coord=`echo "$entry" | sed -n 's/.*||\s*\([^|]\+\).*/\1/p'` + if [[ "$name" != "" && "$coord" != "" ]]; then + echo "{ \"type\": \"Feature\", + \"geometry\": { + \"type\": \"LineString\", + \"coordinates\": [ + $coord + ] + }, + \"properties\": { + \"name\": \"$name\", + \"type\": \"$type\" + } + }," + fi + ;; + "Oceans, Seas, and Lakes") + name=`echo "$entry" | sed -n 's/\s*\([^|]\+\).*/\1/p' | sed 's/ $//'` + type=`echo "$entry" | sed -n 's/\s*\([^|]\+\)||\s*\([^|]\+\).*/\2/p' | sed 's/ $//'` + coord=`echo "$entry" | sed -n 's/.*||\s*\([^|]\+\).*/\1/p'` + if [[ "$name" != "" && "$coord" != "" ]]; then + echo "{ \"type\": \"Feature\", + \"geometry\": { + \"type\": \"Polygon\", + \"coordinates\": [[ + $coord + ]] + }, + \"properties\": { + \"name\": \"$name\", + \"type\": \"$type\" + } + }," + fi + ;; + esac +done +export IFS=" " +echo "{}" +echo "]" diff --git a/scripts/geojson/maps/fetch_trainlines.sh b/scripts/geojson/maps/fetch_trainlines.sh new file mode 100755 index 0000000..f0c4d25 --- /dev/null +++ b/scripts/geojson/maps/fetch_trainlines.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +json=`curl 'https://wiki.linux-forks.de/mediawiki/api.php?action=query&prop=revisions&rvprop=content&format=json&titles=Maps:Trainlines'` +data=`echo "$json" | json_reformat | sed -e 's/\\\\n//g' -n -e 's/begin:mapdata\([^}]\+\)/\1/gp' | sed -e "s/|-|/}/g"` + +section="" +echo "[" +export IFS="}" +for entry in $data; do + this_section=`echo $entry | sed -n 's/.*== \([^=]\+\) ==.*/\1/p'` + if [[ "$this_section" != "" ]]; then + section=$this_section + fi + + if [[ "$section" != "$1" ]]; then + continue + fi + + case "$section" in + "Train Lines") + name=`echo "$entry" | sed -n 's/\s*\([^|]\+\).*/\1/p' | sed 's/ $//'` + start=`echo "$entry" | sed -n 's/\s*\([^|]\+\)||\s*\([^|]\+\).*/\2/p' | sed 's/ $//'` + end=`echo "$entry" | sed -n 's/\s*\([^|]\+\)||\([^|]\+\)||\s*\([^|]\+\).*/\3/p' | sed 's/ $//'` + coord=`echo "$entry" | sed -n 's/.*||\s*\([^|]\+\).*/\1/p'` + if [[ "$name" != "" && "$coord" != "" ]]; then + echo "{ \"type\": \"Feature\", + \"geometry\": { + \"type\": \"LineString\", + \"coordinates\": [ + $coord + ] + }, + \"properties\": { + \"name\": \"$name\", + \"start\": \"$start\", + \"end\": \"$end\" + } +}," + fi + ;; + "Access Paths") + name=`echo "$entry" | sed -n 's/\s*\([^|]\+\).*/\1/p' | sed 's/ $//'` + lines=`echo "$entry" | sed -n 's/\s*\([^|]\+\)||\s*\([^|]\+\).*/\2/p' | sed 's/ $//'` + coord=`echo "$entry" | sed -n 's/.*||\s*\([^|]\+\).*/\1/p'` + if [[ "$type" == "district" ]]; then + continue; + fi + if [[ "$name" != "" && "$coord" != "" ]]; then + echo "{ \"type\": \"Feature\", + \"geometry\": { + \"type\": \"LineString\", + \"coordinates\": [ + $coord + ] + }, + \"properties\": { + \"name\": \"$lines:$name\" + } +}," + fi + ;; + esac +done +export IFS=" " +echo "{}" +echo "]" diff --git a/scripts/geojson/maps/update_all.sh b/scripts/geojson/maps/update_all.sh index 22b9eee..e25d843 100755 --- a/scripts/geojson/maps/update_all.sh +++ b/scripts/geojson/maps/update_all.sh @@ -1,10 +1,19 @@ #!/bin/bash function fetch() { - "./fetch_$1.sh" | json_reformat -m > "$1.json.tmp" - rm -f "$1.json" - mv "$1.json.tmp" "$1.json" + if [[ "$3" != "" ]]; then + fn="$3" + else + fn="$1" + fi + "./fetch_$1.sh" "$2" | json_reformat -m > "$fn.json.tmp" + rm -f "$fn.json" + mv "$fn.json.tmp" "$fn.json" } fetch streets fetch city_outlines +fetch trainlines "Train Lines" +fetch trainlines "Access Paths" trainlines_access +fetch bodiesofwater "Rivers" rivers +fetch bodiesofwater "Oceans, Seas, and Lakes" oceans |