Add categories for markers
This commit obsoletes the many fetch scripts and combines them into a single script, creating a single json, but with category information.
This commit is contained in:
parent
c7c4975a57
commit
05238dc5ae
@ -173,8 +173,7 @@ function load_tiles(name, id) {
|
|||||||
|
|
||||||
var current_location = "";
|
var current_location = "";
|
||||||
var current_feature = null;
|
var current_feature = null;
|
||||||
|
function load_geojson(name, url, geotype, iconcolor, active=1, style={}) {
|
||||||
function load_geojson(name, url, iconname, iconcolor, active=1, style={}) {
|
|
||||||
var xhttp_ps = new XMLHttpRequest();
|
var xhttp_ps = new XMLHttpRequest();
|
||||||
xhttp_ps.onreadystatechange = function() {
|
xhttp_ps.onreadystatechange = function() {
|
||||||
if (this.readyState == 4) {
|
if (this.readyState == 4) {
|
||||||
@ -183,10 +182,10 @@ function load_geojson(name, url, iconname, iconcolor, active=1, style={}) {
|
|||||||
pointToLayer = null;
|
pointToLayer = null;
|
||||||
filter = null;
|
filter = null;
|
||||||
|
|
||||||
switch (iconname) {
|
switch (geotype) {
|
||||||
case "street":
|
case "street":
|
||||||
onEachFeature = function(feature, layer) {
|
onEachFeature = function(feature, layer) {
|
||||||
layer.myTag = iconname;
|
layer.myTag = geotype;
|
||||||
layer.myName = name;
|
layer.myName = name;
|
||||||
layer.on("click", function (e) {
|
layer.on("click", function (e) {
|
||||||
current_feature = feature;
|
current_feature = feature;
|
||||||
@ -195,7 +194,7 @@ function load_geojson(name, url, iconname, iconcolor, active=1, style={}) {
|
|||||||
break;
|
break;
|
||||||
case "outline":
|
case "outline":
|
||||||
onEachFeature = function(feature, layer) {
|
onEachFeature = function(feature, layer) {
|
||||||
layer.myTag = iconname;
|
layer.myTag = geotype;
|
||||||
layer.myName = name;
|
layer.myName = name;
|
||||||
layer.on("click", function (e) {
|
layer.on("click", function (e) {
|
||||||
current_location = feature.properties.name;
|
current_location = feature.properties.name;
|
||||||
@ -214,7 +213,55 @@ function load_geojson(name, url, iconname, iconcolor, active=1, style={}) {
|
|||||||
};
|
};
|
||||||
pointToLayer = function(feature, latlng) {
|
pointToLayer = function(feature, latlng) {
|
||||||
label = String(feature.properties.name)
|
label = String(feature.properties.name)
|
||||||
return new L.marker(latlng,{
|
if (geotype == "auto") {
|
||||||
|
iconname = "star"; // default icon
|
||||||
|
iconcolor = "orange";
|
||||||
|
for (var i = 0; i < feature.properties.categories.length; i++) {
|
||||||
|
category = feature.properties.categories[i].toLowerCase();
|
||||||
|
switch (category) {
|
||||||
|
case "stations":
|
||||||
|
iconname = "train";
|
||||||
|
iconcolor = "blue";
|
||||||
|
break;
|
||||||
|
case "shops":
|
||||||
|
iconname = "shopping-cart";
|
||||||
|
iconcolor = "green";
|
||||||
|
break;
|
||||||
|
case "city":
|
||||||
|
case "village":
|
||||||
|
case "town":
|
||||||
|
case "settlements":
|
||||||
|
iconname = "city";
|
||||||
|
iconcolor = "red";
|
||||||
|
break;
|
||||||
|
case "parks":
|
||||||
|
iconname = "tree";
|
||||||
|
iconcolor = "green";
|
||||||
|
break;
|
||||||
|
case "courts":
|
||||||
|
iconname = "balance-scale";
|
||||||
|
iconcolor = "black";
|
||||||
|
break;
|
||||||
|
case "train depots":
|
||||||
|
iconname = "wrench";
|
||||||
|
iconcolor = "violet";
|
||||||
|
break;
|
||||||
|
case "hotels":
|
||||||
|
iconname = "hotel";
|
||||||
|
iconcolor = "gray";
|
||||||
|
break;
|
||||||
|
case "beaches":
|
||||||
|
iconname = "umbrella-beach";
|
||||||
|
iconcolor = "orange";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (iconname != "star")
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
iconname = geotype;
|
||||||
|
}
|
||||||
|
marker = new L.marker(latlng,{
|
||||||
icon: L.AwesomeMarkers.icon({
|
icon: L.AwesomeMarkers.icon({
|
||||||
icon: iconname,
|
icon: iconname,
|
||||||
markerColor: iconcolor
|
markerColor: iconcolor
|
||||||
@ -224,6 +271,7 @@ function load_geojson(name, url, iconname, iconcolor, active=1, style={}) {
|
|||||||
direction: "center",
|
direction: "center",
|
||||||
opacity: 0.7
|
opacity: 0.7
|
||||||
}).openTooltip();
|
}).openTooltip();
|
||||||
|
return marker;
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -252,17 +300,9 @@ function load_geojson(name, url, iconname, iconcolor, active=1, style={}) {
|
|||||||
load_tiles("Satellite (2020-04-09)", 'world-2020-04-09').addTo(mymap);
|
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 (2019-05-04, wrong coords)", 'world-2019-05-04');
|
||||||
|
|
||||||
//load_svg("Test", "./overlay.svg", 0);
|
load_geojson("All", "./geojson/all.json", "auto", "auto", 0);
|
||||||
load_geojson("Cities", "./geojson/cities.json", "city", "red");
|
load_geojson("Streets", "./geojson/streets.json", "street", "auto", 1, style_streets);
|
||||||
load_geojson("Stations", "./geojson/stations.json", "train", "blue");
|
load_geojson("Cities", "./geojson/city_outlines.json", "outline", "auto", 1, style_outlines);
|
||||||
load_geojson("Shops", "./geojson/shops.json", "shopping-cart", "green");
|
|
||||||
load_geojson("Parks", "./geojson/parks.json", "tree", "darkgreen");
|
|
||||||
load_geojson("Libraries", "./geojson/libraries.json", "book-open", "darkblue");
|
|
||||||
load_geojson("CW Complexes", "./geojson/cw_complexes.json", "border-all", "black");
|
|
||||||
load_geojson("Courts", "./geojson/courts.json", "balance-scale", "black");
|
|
||||||
load_geojson("Waterway", "./geojson/waterway.json", "water", "darkblue");
|
|
||||||
load_geojson("Train Depots", "./geojson/depots.json", "wrench", "violet");
|
|
||||||
load_geojson("Streets", "./geojson/streets.json", "street", "blue", 0);
|
|
||||||
|
|
||||||
L.control.scale().addTo(mymap);
|
L.control.scale().addTo(mymap);
|
||||||
|
|
||||||
@ -342,12 +382,16 @@ function polyline_get_middle_coords(coords) {
|
|||||||
|
|
||||||
var highlighted_line;
|
var highlighted_line;
|
||||||
var default_street_color = "#3388ff";
|
var default_street_color = "#3388ff";
|
||||||
|
|
||||||
function search(e) {
|
function search(e) {
|
||||||
var query = document.getElementById("search_query").value;
|
var query = document.getElementById("search_query").value;
|
||||||
|
var real_query = true;
|
||||||
document.getElementById('search_results').innerHTML = "";
|
document.getElementById('search_results').innerHTML = "";
|
||||||
if (true) {
|
if (true) {
|
||||||
if (query.length == 0)
|
if (query.length == 0) {
|
||||||
|
real_query = false;
|
||||||
query = "!@#$%^&"; // Cheap workaround to (hopefully) match nothing
|
query = "!@#$%^&"; // Cheap workaround to (hopefully) match nothing
|
||||||
|
}
|
||||||
results = document.createElement("ul");
|
results = document.createElement("ul");
|
||||||
for (var i = 0; i < layers._layers.length; i++) {
|
for (var i = 0; i < layers._layers.length; i++) {
|
||||||
if (!layers._layers[i].layer._layers)
|
if (!layers._layers[i].layer._layers)
|
||||||
@ -362,6 +406,12 @@ function search(e) {
|
|||||||
el = document.createElement("li");
|
el = document.createElement("li");
|
||||||
el.innerHTML = "[" + layers._layers[i].name + "] " + '<a href="#" onclick="layers._layers[' + i + '].layer._layers[' + item._leaflet_id + '].fire(\'click\'); return false;">' + htmlEntities(item.feature.properties.name) + "</a>";
|
el.innerHTML = "[" + layers._layers[i].name + "] " + '<a href="#" onclick="layers._layers[' + i + '].layer._layers[' + item._leaflet_id + '].fire(\'click\'); return false;">' + htmlEntities(item.feature.properties.name) + "</a>";
|
||||||
results.appendChild(el);
|
results.appendChild(el);
|
||||||
|
item.setOpacity(1.0); // TODO: setOpacity does not disable hover and click events
|
||||||
|
} else {
|
||||||
|
if (real_query)
|
||||||
|
item.setOpacity(0.0); // TODO
|
||||||
|
else
|
||||||
|
item.setOpacity(1.0); // TODO
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "LineString":
|
case "LineString":
|
||||||
@ -532,6 +582,8 @@ mymap.on('overlayadd', function (e) { update_street_width(); update_outline_visi
|
|||||||
function onHashChange(e, hash=null) {
|
function onHashChange(e, hash=null) {
|
||||||
if (!hash)
|
if (!hash)
|
||||||
hash = document.location.hash;
|
hash = document.location.hash;
|
||||||
|
if (hash == "")
|
||||||
|
return;
|
||||||
if (hash == "#" + get_current_location_str())
|
if (hash == "#" + get_current_location_str())
|
||||||
return; // We're already there
|
return; // We're already there
|
||||||
coordstr = decodeURIComponent(hash.slice(1)).split(",");
|
coordstr = decodeURIComponent(hash.slice(1)).split(",");
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
fetch_category () {
|
|
||||||
echo "Fetching $1" > /dev/stderr
|
|
||||||
json=`curl "https://wiki.linux-forks.de/mediawiki/api.php?action=query&format=json&list=categorymembers&cmtitle=Category:$1&cmlimit=max" 2>/dev/null`
|
|
||||||
cities=`echo "$json" | json_reformat | sed -n 's/.*"title":\s*"\([^"]*\).*/\1/p' | tr ' ' '_' | tr '\n' ' '`
|
|
||||||
num=`echo $cities | tr ' ' '\n' | wc -l`
|
|
||||||
i=0
|
|
||||||
echo "["
|
|
||||||
for city in $cities; do
|
|
||||||
let i++
|
|
||||||
echo -n -e "\rFetched $i/$num" > /dev/stderr
|
|
||||||
./fetch_single.sh "$city"
|
|
||||||
done
|
|
||||||
echo > /dev/stderr
|
|
||||||
echo "{}]"
|
|
||||||
}
|
|
||||||
|
|
||||||
JSONDIR=../../htdocs/geojson
|
|
||||||
|
|
||||||
mkdir -p $JSONDIR
|
|
||||||
|
|
||||||
|
|
||||||
fetch_category Shops > $JSONDIR/shops.json
|
|
||||||
fetch_category City > $JSONDIR/cities.json
|
|
||||||
fetch_category Stations > $JSONDIR/stations.json
|
|
||||||
fetch_category Parks > $JSONDIR/parks.json
|
|
||||||
fetch_category Libraries > $JSONDIR/libraries.json
|
|
||||||
fetch_category "CW_Complexes" > $JSONDIR/cw_complexes.json
|
|
||||||
fetch_category Courts > $JSONDIR/courts.json
|
|
||||||
fetch_category Waterway > $JSONDIR/waterway.json
|
|
||||||
fetch_category Train_Depots > $JSONDIR/depots.json
|
|
48
scripts/geojson/fetch_all_points.sh
Executable file
48
scripts/geojson/fetch_all_points.sh
Executable file
@ -0,0 +1,48 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
json=`curl -s 'https://wiki.linux-forks.de/mediawiki/api.php?action=query&format=json&list=search&redirects=1&converttitles=1&srsearch=%7B%7BCo%7C&srlimit=max&srwhat=text&srprop=snippet'`
|
||||||
|
data=`echo "$json" | json_reformat`;
|
||||||
|
|
||||||
|
echo "[";
|
||||||
|
|
||||||
|
IFS=$'\n';
|
||||||
|
for line in $data; do
|
||||||
|
temp=`echo "$line" | sed -n 's/^\s*{\s*$/END/p'`
|
||||||
|
if [[ "$temp" == "END" ]]; then
|
||||||
|
title="";
|
||||||
|
coords="";
|
||||||
|
fi
|
||||||
|
temp=`echo "$line" | sed -n 's/\s*"title": "*\([^"]\+\).*/\1/p'`
|
||||||
|
if [[ "$temp" != "" ]]; then
|
||||||
|
title="$temp";
|
||||||
|
fi
|
||||||
|
temp=`echo "$line" | sed -n 's#.*<span class=.searchmatch.>Co<\/span>|\([0-9\-]\+\)|\([0-9\-]\+\)|\([0-9\-]\+\).*#\1,\3#p'`
|
||||||
|
if [[ "$temp" != "" ]]; then
|
||||||
|
coords="$temp";
|
||||||
|
fi
|
||||||
|
if [[ "$title" != "" && "$coords" != "" ]]; then
|
||||||
|
echo "{\"type\": \"Feature\", \"properties\": {\"name\": \"$title\","
|
||||||
|
echo -n "\"categories\": ["
|
||||||
|
urltitle=`echo "$title" | sed 's/ /%20/g'`
|
||||||
|
cjson=`curl -s "https://wiki.linux-forks.de/mediawiki/api.php?action=query&format=json&titles=$urltitle&prop=categories" | json_reformat -m`
|
||||||
|
categories=`echo "$cjson" | sed -n 's/.*\("categories":[^]]\+\).*/\1/p'`;
|
||||||
|
IFS='}'
|
||||||
|
fc="true";
|
||||||
|
for entry in $categories; do
|
||||||
|
if [[ "$fc" != "true" ]]; then
|
||||||
|
echo -n ",";
|
||||||
|
fi
|
||||||
|
category=`echo "$entry" | sed -n 's/.*Category:\([^"]\+\).*/\1/p'`
|
||||||
|
echo -n "\"$category\"";
|
||||||
|
fc="false";
|
||||||
|
done;
|
||||||
|
IFS=$'\n'
|
||||||
|
echo "]},";
|
||||||
|
echo "\"geometry\": {\"type\": \"Point\", \"coordinates\": [$coords]}},";
|
||||||
|
title="";
|
||||||
|
coords="";
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
IFS=" ";
|
||||||
|
|
||||||
|
echo "{}]";
|
@ -1,10 +0,0 @@
|
|||||||
#!/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 "{}]"
|
|
@ -1,10 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
json=`curl 'https://wiki.linux-forks.de/mediawiki/api.php?action=query&format=json&list=categorymembers&cmtitle=Category:Shops&cmlimit=1000' 2>/dev/null`
|
|
||||||
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 "{}]"
|
|
@ -1,31 +0,0 @@
|
|||||||
#!/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" 2>/dev/null | sed -s "s/\\\\\\\\n//g"`
|
|
||||||
|
|
||||||
title=`echo $json | sed -n 's/.*"title":\s*"\([^"]\+\).*/\1/p'`
|
|
||||||
|
|
||||||
img=$(curl "https://wiki.linux-forks.de/mediawiki/index.php/$1" 2>/dev/null | sed s/\"/\\n/g | grep /thumb/ | head -n 1)
|
|
||||||
|
|
||||||
image="https://wiki.linux-forks.de$img"
|
|
||||||
|
|
||||||
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=`curl "https://wiki.linux-forks.de/mediawiki/api.php?action=parse&page=$1§ion=0&prop=text&format=json" 2>/dev/null | sed -z -n "s/<\/p><p>//g;s/.*<p>\(.*\)<\/p>.*/\1/p" | sed s,\"/mediawiki/index.php,\"https://wiki.linux-forks.de/mediawiki/index.php,g`
|
|
||||||
|
|
||||||
|
|
||||||
if [[ "$coord_x" != "" && "$coord_y" != "" ]]; then
|
|
||||||
echo "{\
|
|
||||||
\"type\": \"Feature\",\
|
|
||||||
\"properties\": {\
|
|
||||||
\"name\": \"$title\",\
|
|
||||||
\"amenity\": \"City\",\
|
|
||||||
\"description\": \"$description\",\
|
|
||||||
\"image\": \"$image\"\
|
|
||||||
},\
|
|
||||||
\"geometry\": {\
|
|
||||||
\"type\": \"Point\",\
|
|
||||||
\"coordinates\": [$coord_x, $coord_y]\
|
|
||||||
}\
|
|
||||||
},"
|
|
||||||
fi
|
|
@ -1,10 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
json=`curl 'https://wiki.linux-forks.de/mediawiki/api.php?action=query&format=json&list=categorymembers&cmtitle=Category:Stations&cmlimit=1000' 2>/dev/null`
|
|
||||||
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 "{}]"
|
|
Loading…
Reference in New Issue
Block a user