SVG Continents
This commit is contained in:
parent
a8cf82565d
commit
9f5018c2ee
@ -15,7 +15,7 @@ android {
|
||||
minSdk 28
|
||||
targetSdk 34
|
||||
versionCode 1
|
||||
versionName "0.1a"
|
||||
versionName "1.0"
|
||||
}
|
||||
signingConfigs {
|
||||
create("release") {
|
||||
|
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 6.4 MiB After Width: | Height: | Size: 6.1 MiB |
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 6.4 MiB After Width: | Height: | Size: 6.0 MiB |
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 6.5 MiB After Width: | Height: | Size: 6.1 MiB |
@ -39,17 +39,20 @@ class CSSWrapper(private val ctx: Context) {
|
||||
private fun refresh() {
|
||||
val id = if (Settings.isRegional(ctx)) "1" else "2"
|
||||
customCSS = visits.getVisitedByValue().map { (k, v) ->
|
||||
if (groups.getGroupFromKey(k).key != NO_GROUP || (!Settings.isRegional(ctx) && k == AUTO_GROUP)) {
|
||||
v.joinToString(",") { "#${it}$id,#${it}" } + "{fill:${
|
||||
colorToHex6(
|
||||
if (k == AUTO_GROUP)
|
||||
colorWrapper(ctx, android.R.attr.colorPrimary)
|
||||
else groups.getGroupFromKey(k).color
|
||||
)
|
||||
};}"
|
||||
(if (groups.getGroupFromKey(k).key != NO_GROUP) {
|
||||
v
|
||||
} else if (!Settings.isRegional(ctx) && k == AUTO_GROUP) {
|
||||
v.filter { it !in World.WWW.children.map { it1 -> it1.code } }
|
||||
} else {
|
||||
""
|
||||
}
|
||||
emptyList()
|
||||
}).takeIf { it.isNotEmpty() }
|
||||
?.joinToString(",") { "#${it}$id,#${it}" } + "{fill:${
|
||||
colorToHex6(
|
||||
if (k == AUTO_GROUP)
|
||||
colorWrapper(ctx, android.R.attr.colorPrimary)
|
||||
else groups.getGroupFromKey(k).color
|
||||
)
|
||||
};}"
|
||||
}.joinToString("")
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
<string name="key_regional">Regional</string>
|
||||
<string name="about">About</string>
|
||||
<string name="beans_is_foss">Beans is free and open source software, licensed under the GNU General Public License (version 3 or later)</string>
|
||||
<string name="beans_repo">Project repository: https://git.helcel.net/helcel/beans\n Feel free to report issues or contribute to the project.</string>
|
||||
<string name="beans_repo">Project repository: https://github.com/helcel-net/beans\n Feel free to report issues or contribute to the project.</string>
|
||||
<string name="foss_licenses">Free and open source dependencies and licenses</string>
|
||||
<string name="about_beans">About the Beans application</string>
|
||||
<string name="edit_group">Select the group to assign. Long press on a group to edit its name and color.</string>
|
||||
|
35
gensvg.sh
35
gensvg.sh
@ -15,13 +15,13 @@ countries=(
|
||||
"DNK" "DJI" "DMA" "DOM" "ECU" "EGY" "SLV" "GNQ" "ERI" "EST" "ETH" "FLK" "FRO" "FJI" "FIN" "FRA" "GUF" "PYF" "ATF"
|
||||
"GAB" "GMB" "GEO" "DEU" "GHA" "GIB" "GRC" "GRL" "GRD" "GLP" "GUM" "GTM" "GGY" "GIN" "GNB" "GUY" "HTI" "HMD" "HND" "HUN"
|
||||
"ISL" "IND" "IDN" "IRN" "IRQ" "IRL" "IMN" "ISR" "ITA" "JAM" "JPN" "JEY" "JOR" "KAZ" "KEN" "KIR" "XKO" "KWT" "KGZ"
|
||||
"LAO" "LVA" "LBN" "LSO" "LBR" "LBY" "LIE" "LTU" "LUX" "SXM"
|
||||
"MKD" "MDG" "MWI" "MYS" "MDV" "MLI" "MLT" "MHL" "MTQ" "MRT" "MUS" "MYT" "MEX" "FSM" "MDA" "MCO" "MNG" "MNE" "MSR" "MAR" "MOZ" "MMR"
|
||||
"NAM" "NRU" "NPL" "NLD" "NCL" "NZL" "NIC" "NER" "NGA" "NIU" "NFK" "PRK" "ZNC" "MNP" "NOR" "OMN"
|
||||
"PAK" "PLW" "PSE" "PAN" "PNG" "PRY" "PER" "PHL" "PCN" "POL" "PRT" "PRI" "QAT" "COG" "REU" "ROU" "RUS" "RWA" "BLM" "MAF"
|
||||
"SHN" "KNA" "LCA" "SPM" "VCT" "WSM" "SMR" "STP" "SAU" "SEN" "SRB" "SYC" "SLE" "SGP" "SVK" "SVN" "SLB" "SOM" "ZAF" "SGS" "KOR" "SSD" "ESP"
|
||||
"LKA" "SDN" "SUR" "SJM" "SWZ" "SWE" "CHE" "SYR" "TWN" "TJK" "TZA" "THA" "TLS" "TGO" "TKL" "TON" "TTO" "TUN" "TUR" "TKM" "TCA" "TUV" "UGA"
|
||||
"UKR" "ARE" "GBR" "USA" "UMI" "URY" "UZB" "VUT" "VAT" "VEN" "VNM" "VIR" "WLF" "ESH" "YEM" "ZMB" "ZWE"
|
||||
"LAO" "LVA" "LBN" "LSO" "LBR" "LBY" "LIE" "LTU" "LUX" "SXM"
|
||||
"MKD" "MDG" "MWI" "MYS" "MDV" "MLI" "MLT" "MHL" "MTQ" "MRT" "MUS" "MYT" "MEX" "FSM" "MDA" "MCO" "MNG" "MNE" "MSR" "MAR" "MOZ" "MMR"
|
||||
"NAM" "NRU" "NPL" "NLD" "NCL" "NZL" "NIC" "NER" "NGA" "NIU" "NFK" "PRK" "ZNC" "MNP" "NOR" "OMN"
|
||||
"PAK" "PLW" "PSE" "PAN" "PNG" "PRY" "PER" "PHL" "PCN" "POL" "PRT" "PRI" "QAT" "COG" "REU" "ROU" "RUS" "RWA" "BLM" "MAF"
|
||||
"SHN" "KNA" "LCA" "SPM" "VCT" "WSM" "SMR" "STP" "SAU" "SEN" "SRB" "SYC" "SLE" "SGP" "SVK" "SVN" "SLB" "SOM" "ZAF" "SGS" "KOR" "SSD" "ESP"
|
||||
"LKA" "SDN" "SUR" "SJM" "SWZ" "SWE" "CHE" "SYR" "TWN" "TJK" "TZA" "THA" "TLS" "TGO" "TKL" "TON" "TTO" "TUN" "TUR" "TKM" "TCA" "TUV" "UGA"
|
||||
"UKR" "ARE" "GBR" "USA" "UMI" "URY" "UZB" "VUT" "VAT" "VEN" "VNM" "VIR" "WLF" "ESH" "YEM" "ZMB" "ZWE"
|
||||
)
|
||||
|
||||
|
||||
@ -117,25 +117,28 @@ toSVG_1() {
|
||||
|
||||
|
||||
toSVG_01() {
|
||||
input_files=("./temp/1/ATA.json" "./temp/0/ATA.json")
|
||||
input_files=()
|
||||
|
||||
input_files+=("./temp/1/ATA.json")
|
||||
for country in "${countries[@]}"
|
||||
do
|
||||
input_file1="./temp/1/${country}.json"
|
||||
input_file0="./temp/0/${country}.json"
|
||||
if [ -f "$input_file1" ]; then
|
||||
input_files+=("$input_file1")
|
||||
fi
|
||||
done
|
||||
input_files+=("./temp/0/ATA.json")
|
||||
for country in "${countries[@]}"
|
||||
do
|
||||
input_file0="./temp/0/${country}.json"
|
||||
if [ -f "$input_file0" ]; then
|
||||
input_files+=("$input_file0")
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
"$mapshaper" -i combine-files ${input_files[@]} snap -proj eqdc +lat_1=55 +lat_2=60 -simplify 0.005 weighted keep-shapes resolution=1200x1200 -o ./app/src/main/assets/eqdc01.svg svg-data=GID_0,COUNTRY,GID,NAME id-field=GID
|
||||
"$mapshaper" -i combine-files ${input_files[@]} snap -proj loxim densify -simplify 0.005 weighted keep-shapes resolution=1200x1200 -o ./app/src/main/assets/loxim01.svg svg-data=GID_0,COUNTRY,GID,NAME id-field=GID
|
||||
"$mapshaper" -i combine-files ${input_files[@]} snap -proj webmercator densify -simplify 0.005 weighted keep-shapes resolution=1200x1200 -o ./app/src/main/assets/webmercator01.svg svg-data=GID_0,COUNTRY,GID,NAME id-field=GID
|
||||
"$mapshaper" -i combine-files ${input_files[@]} snap -proj aeqd +lat_0=90 densify -simplify 0.005 weighted keep-shapes resolution=1200x1200 -o ./app/src/main/assets/aeqd01.svg svg-data=GID_0,COUNTRY,GID,NAME id-field=GID
|
||||
"$mapshaper" -i combine-files ${input_files[@]} snap -proj loxim densify -simplify 0.001 weighted keep-shapes -o ./app/src/main/assets/loxim01.svg svg-data=GID_0,COUNTRY,GID,NAME id-field=GID
|
||||
"$mapshaper" -i combine-files ${input_files[@]} snap -proj webmercator densify -simplify 0.001 weighted keep-shapes -o ./app/src/main/assets/webmercator01.svg svg-data=GID_0,COUNTRY,GID,NAME id-field=GID
|
||||
"$mapshaper" -i combine-files ${input_files[@]} snap -proj aeqd +lat_0=90 densify -simplify 0.001 weighted keep-shapes -o ./app/src/main/assets/aeqd01.svg svg-data=GID_0,COUNTRY,GID,NAME id-field=GID
|
||||
}
|
||||
|
||||
do_1() {
|
||||
@ -152,8 +155,8 @@ do_0() {
|
||||
done
|
||||
wget -q -O "./temp/1/ATA.json" "$ATA_URL"
|
||||
}
|
||||
do_0
|
||||
do_1
|
||||
# do_0
|
||||
# do_1
|
||||
# toSVG_0
|
||||
# toSVG_1
|
||||
toSVG_01
|
325
mapping.js
Normal file
325
mapping.js
Normal file
@ -0,0 +1,325 @@
|
||||
var continents = {
|
||||
XAD:"EEE",
|
||||
ALA:"EEE",
|
||||
ALB:"EEE",
|
||||
AND:"EEE",
|
||||
AUT:"EEE",
|
||||
BLR:"EEE",
|
||||
BEL:"EEE",
|
||||
BIH:"EEE",
|
||||
BGR:"EEE",
|
||||
HRV:"EEE",
|
||||
CYP:"EEE",
|
||||
CZE:"EEE",
|
||||
DNK:"EEE",
|
||||
EST:"EEE",
|
||||
FRO:"EEE",
|
||||
FIN:"EEE",
|
||||
FRA:"EEE",
|
||||
DEU:"EEE",
|
||||
GIB:"EEE",
|
||||
GRC:"EEE",
|
||||
GGY:"EEE",
|
||||
HUN:"EEE",
|
||||
ISL:"EEE",
|
||||
IRL:"EEE",
|
||||
IMN:"EEE",
|
||||
ITA:"EEE",
|
||||
JEY:"EEE",
|
||||
KAZ:"EEE",
|
||||
XKO:"EEE",
|
||||
LVA:"EEE",
|
||||
LIE:"EEE",
|
||||
LTU:"EEE",
|
||||
LUX:"EEE",
|
||||
MLT:"EEE",
|
||||
MDA:"EEE",
|
||||
MCO:"EEE",
|
||||
MNE:"EEE",
|
||||
NLD:"EEE",
|
||||
MKD:"EEE",
|
||||
NOR:"EEE",
|
||||
POL:"EEE",
|
||||
PRT:"EEE",
|
||||
ROU:"EEE",
|
||||
RUS:"EEE",
|
||||
SMR:"EEE",
|
||||
SRB:"EEE",
|
||||
SVK:"EEE",
|
||||
SVN:"EEE",
|
||||
ESP:"EEE",
|
||||
SJM:"EEE",
|
||||
SWE:"EEE",
|
||||
CHE:"EEE",
|
||||
UKR:"EEE",
|
||||
GBR:"EEE",
|
||||
VAT:"EEE",
|
||||
|
||||
AFG:"ABB",
|
||||
ARM:"ABB",
|
||||
AZE:"ABB",
|
||||
BHR:"ABB",
|
||||
BGD:"ABB",
|
||||
BTN:"ABB",
|
||||
IOT:"ABB",
|
||||
BRN:"ABB",
|
||||
KHM:"ABB",
|
||||
CCK:"ABB",
|
||||
CHN:"ABB",
|
||||
CXR:"ABB",
|
||||
GEO:"ABB",
|
||||
HKG:"ABB",
|
||||
IND:"ABB",
|
||||
IDN:"ABB",
|
||||
IRN:"ABB",
|
||||
IRQ:"ABB",
|
||||
ISR:"ABB",
|
||||
JPN:"ABB",
|
||||
JOR:"ABB",
|
||||
KWT:"ABB",
|
||||
KGZ:"ABB",
|
||||
LAO:"ABB",
|
||||
LBN:"ABB",
|
||||
MAC:"ABB",
|
||||
MYS:"ABB",
|
||||
MDV:"ABB",
|
||||
MNG:"ABB",
|
||||
MMR:"ABB",
|
||||
NPL:"ABB",
|
||||
PRK:"ABB",
|
||||
OMN:"ABB",
|
||||
PAK:"ABB",
|
||||
PSE:"ABB",
|
||||
PHL:"ABB",
|
||||
QAT:"ABB",
|
||||
SAU:"ABB",
|
||||
SGP:"ABB",
|
||||
KOR:"ABB",
|
||||
LKA:"ABB",
|
||||
SYR:"ABB",
|
||||
TWN:"ABB",
|
||||
TJK:"ABB",
|
||||
THA:"ABB",
|
||||
TLS:"ABB",
|
||||
TUR:"ABB",
|
||||
TKM:"ABB",
|
||||
ARE:"ABB",
|
||||
UZB:"ABB",
|
||||
VNM:"ABB",
|
||||
YEM:"ABB",
|
||||
ZNC:"ABB",
|
||||
|
||||
DZA:"FFF",
|
||||
AGO:"FFF",
|
||||
BDI:"FFF",
|
||||
BEN:"FFF",
|
||||
BWA:"FFF",
|
||||
BFA:"FFF",
|
||||
BDI:"FFF",
|
||||
CPV:"FFF",
|
||||
CMR:"FFF",
|
||||
CAF:"FFF",
|
||||
TCD:"FFF",
|
||||
COM:"FFF",
|
||||
COG:"FFF",
|
||||
COD:"FFF",
|
||||
CIV:"FFF",
|
||||
DJI:"FFF",
|
||||
EGY:"FFF",
|
||||
GNQ:"FFF",
|
||||
ERI:"FFF",
|
||||
ETH:"FFF",
|
||||
ATF:"FFF",
|
||||
GAB:"FFF",
|
||||
GMB:"FFF",
|
||||
GHA:"FFF",
|
||||
GIN:"FFF",
|
||||
GNB:"FFF",
|
||||
KEN:"FFF",
|
||||
LSO:"FFF",
|
||||
LBR:"FFF",
|
||||
LBY:"FFF",
|
||||
MDG:"FFF",
|
||||
MWI:"FFF",
|
||||
MLI:"FFF",
|
||||
MRT:"FFF",
|
||||
MUS:"FFF",
|
||||
MYT:"FFF",
|
||||
MAR:"FFF",
|
||||
MOZ:"FFF",
|
||||
NAM:"FFF",
|
||||
NER:"FFF",
|
||||
NGA:"FFF",
|
||||
COD:"FFF",
|
||||
REU:"FFF",
|
||||
RWA:"FFF",
|
||||
STP:"FFF",
|
||||
SEN:"FFF",
|
||||
SYC:"FFF",
|
||||
SLE:"FFF",
|
||||
SOM:"FFF",
|
||||
ZAF:"FFF",
|
||||
SSD:"FFF",
|
||||
SHN:"FFF",
|
||||
SDN:"FFF",
|
||||
SWZ:"FFF",
|
||||
TZA:"FFF",
|
||||
TGO:"FFF",
|
||||
TUN:"FFF",
|
||||
UGA:"FFF",
|
||||
COD:"FFF",
|
||||
ZMB:"FFF",
|
||||
ZWE:"FFF",
|
||||
ESH:"FFF",
|
||||
|
||||
ABW:"NNN",
|
||||
AIA:"NNN",
|
||||
ATG:"NNN",
|
||||
BHS:"NNN",
|
||||
BRB:"NNN",
|
||||
BLZ:"NNN",
|
||||
BMU:"NNN",
|
||||
BES:"NNN",
|
||||
VGB:"NNN",
|
||||
CAN:"NNN",
|
||||
CYM:"NNN",
|
||||
XCL:"NNN",
|
||||
CRI:"NNN",
|
||||
CUB:"NNN",
|
||||
CUW:"NNN",
|
||||
DMA:"NNN",
|
||||
DOM:"NNN",
|
||||
SLV:"NNN",
|
||||
GRL:"NNN",
|
||||
GRD:"NNN",
|
||||
GLP:"NNN",
|
||||
GTM:"NNN",
|
||||
HTI:"NNN",
|
||||
HND:"NNN",
|
||||
JAM:"NNN",
|
||||
MTQ:"NNN",
|
||||
MEX:"NNN",
|
||||
MSR:"NNN",
|
||||
ANT:"NNN",
|
||||
CUW:"NNN",
|
||||
NIC:"NNN",
|
||||
PAN:"NNN",
|
||||
PRI:"NNN",
|
||||
BLM:"NNN",
|
||||
KNA:"NNN",
|
||||
LCA:"NNN",
|
||||
MAF:"NNN",
|
||||
SPM:"NNN",
|
||||
VCT:"NNN",
|
||||
SXM:"NNN",
|
||||
TTO:"NNN",
|
||||
TCA:"NNN",
|
||||
USA:"NNN",
|
||||
UMI:"NNN",
|
||||
VIR:"NNN",
|
||||
|
||||
ARG:"SRR",
|
||||
BOL:"SRR",
|
||||
BRA:"SRR",
|
||||
CHL:"SRR",
|
||||
COL:"SRR",
|
||||
ECU:"SRR",
|
||||
FLK:"SRR",
|
||||
GUF:"SRR",
|
||||
GUY:"SRR",
|
||||
PRY:"SRR",
|
||||
PER:"SRR",
|
||||
SUR:"SRR",
|
||||
URY:"SRR",
|
||||
VEN:"SRR",
|
||||
|
||||
ASM:"UUU",
|
||||
AUS:"UUU",
|
||||
COK:"UUU",
|
||||
FJI:"UUU",
|
||||
PYF:"UUU",
|
||||
GUM:"UUU",
|
||||
KIR:"UUU",
|
||||
MHL:"UUU",
|
||||
FSM:"UUU",
|
||||
NRU:"UUU",
|
||||
NCL:"UUU",
|
||||
NZL:"UUU",
|
||||
NIU:"UUU",
|
||||
NFK:"UUU",
|
||||
MNP:"UUU",
|
||||
PLW:"UUU",
|
||||
PNG:"UUU",
|
||||
PCN:"UUU",
|
||||
WSM:"UUU",
|
||||
SLB:"UUU",
|
||||
TKL:"UUU",
|
||||
TON:"UUU",
|
||||
TUV:"UUU",
|
||||
VUT:"UUU",
|
||||
WLF:"UUU",
|
||||
|
||||
ATA:"XXX",
|
||||
BVT:"XXX",
|
||||
HMD:"XXX",
|
||||
SGS:"XXX",
|
||||
}
|
||||
|
||||
import fs from "fs"
|
||||
import {JSDOM} from "jsdom"
|
||||
|
||||
function groupByContinent(svgFilePath) {
|
||||
// Read the SVG file
|
||||
fs.readFile(svgFilePath, 'utf-8', (err, data) => {
|
||||
if (err) {
|
||||
console.error('Error reading SVG file:', err);
|
||||
return;
|
||||
}
|
||||
|
||||
// Create a virtual DOM with JSDOM
|
||||
const dom = new JSDOM(data);
|
||||
const document = dom.window.document;
|
||||
|
||||
// Select the root <svg> element
|
||||
const svgElement = document.querySelector('svg');
|
||||
|
||||
// Group <g> elements representing countries by continent
|
||||
const world = {}; // Renamed continents object to 'world'
|
||||
svgElement.querySelectorAll('g').forEach(countryGroup => {
|
||||
const countryId = countryGroup.getAttribute('id');
|
||||
if (countryId!= null){
|
||||
const continentId = continents[countryId.replace(/\d/g, "")] || "XXX"; // Remove numbers from country ID to get continent ID
|
||||
if (!world[continentId]) {
|
||||
world[continentId] = document.createElementNS('http://www.w3.org/2000/svg', 'g');
|
||||
world[continentId].setAttribute('id', continentId);
|
||||
}
|
||||
world[continentId].innerHTML += countryGroup.outerHTML;
|
||||
}else{
|
||||
|
||||
console.log(countryId,countryGroup.outerHTML)
|
||||
}
|
||||
});
|
||||
|
||||
// Create new <g> elements for each continent
|
||||
svgElement.innerHTML = '';
|
||||
for (const continentId in world) {
|
||||
svgElement.appendChild(world[continentId]);
|
||||
}
|
||||
|
||||
// Output the modified SVG
|
||||
fs.writeFile(svgFilePath, svgElement.outerHTML, 'utf-8', err => {
|
||||
if (err) {
|
||||
console.error('Error writing to SVG file:', err);
|
||||
return;
|
||||
}
|
||||
console.log('SVG file updated successfully.');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Example usage:
|
||||
const svgFileBasePath = "./app/src/main/assets/" ;
|
||||
groupByContinent(svgFileBasePath+ "webmercator01.svg");
|
||||
groupByContinent(svgFileBasePath+ "aeqd01.svg");
|
||||
groupByContinent(svgFileBasePath+ "loxim01.svg");
|
@ -1,13 +1,8 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"@turf/area": "^6.5.0",
|
||||
"@turf/concave": "^6.5.0",
|
||||
"@turf/convex": "^6.5.0",
|
||||
"@turf/projection": "^6.5.0",
|
||||
"@turf/simplify": "^6.5.0",
|
||||
"@turf/truncate": "^6.5.0",
|
||||
"@turf/turf": "^6.5.0",
|
||||
"geojson2svg": "^2.0.1",
|
||||
"jsdom": "^24.0.0",
|
||||
"mapshaper": "^0.6.79"
|
||||
},
|
||||
"type": "module"
|
||||
|
Loading…
x
Reference in New Issue
Block a user