Skip to content

Commit 0acf4ec

Browse files
committed
fix: tag match
1 parent 3f6e7fc commit 0acf4ec

4 files changed

Lines changed: 45 additions & 25 deletions

File tree

src/build.rs

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
use std::{fs, path::Path, time};
22

3-
use geojson::{Feature, FeatureCollection};
43
use serde_json::json;
54
use wax::{Glob, Pattern};
65

76
use crate::{
8-
types::{CountryData, ToCollection, ToFeature, ToFeatures},
7+
types::{CountryData, ToCollection},
98
utils::{diff_countries, get_country, read_config},
109
};
1110

@@ -15,35 +14,50 @@ pub fn build() {
1514
let total_time = time::Instant::now();
1615

1716
for processing_item in config.processing {
17+
println!("--- {} ---", processing_item.output_folder);
18+
1819
let processed_time = time::Instant::now();
1920

2021
let out_folder = Path::new(&processing_item.output_folder);
2122

22-
let tags = processing_item.tags.unwrap_or(vec!["*".to_string()]);
23+
let tags = processing_item.tags.unwrap_or(vec![]);
2324
let globs: Vec<Glob> = tags.iter().map(|tag| Glob::new(tag).unwrap()).collect();
2425

2526
let mut countries: Vec<CountryData> = vec![];
2627

2728
{
2829
let dissolved_time = time::Instant::now();
2930

30-
for country_id in &config.main.layers {
31-
let country = get_country(country_id.to_owned());
32-
33-
let mut matches = false;
34-
for glob in &globs {
35-
for tag in &country.config.tags.clone().unwrap_or(vec!["*".to_owned()]) {
36-
if glob.is_match(tag.as_str()) {
37-
matches = true;
31+
if tags.len() == 0 {
32+
for country_id in &config.main.layers {
33+
countries.push(get_country(country_id.to_owned()));
34+
}
35+
} else {
36+
for country_id in &config.main.layers {
37+
let country = get_country(country_id.to_owned());
38+
39+
match &country.config.tags {
40+
Some(tags) => {
41+
let mut matches = false;
42+
for glob in &globs {
43+
for tag in tags {
44+
if glob.is_match(tag.as_str()) {
45+
matches = true;
46+
}
47+
}
48+
}
49+
50+
if !matches {
51+
continue;
52+
}
53+
54+
countries.push(country);
55+
}
56+
None => {
57+
continue;
3858
}
3959
}
4060
}
41-
42-
if !matches {
43-
continue;
44-
}
45-
46-
countries.push(country);
4761
}
4862

4963
println!("Dissolved in {:?}", dissolved_time.elapsed());
@@ -62,6 +76,7 @@ pub fn build() {
6276
};
6377

6478
// TODO: Add nature support
79+
6580
{
6681
let generated_time = time::Instant::now();
6782
let countries_json = serde_json::to_string_pretty(&serde_json::Map::from_iter(
@@ -88,7 +103,13 @@ pub fn build() {
88103
println!("Generated files in {:?}", generated_time.elapsed());
89104
}
90105

91-
println!("Processed in {:?}\n---\n", processed_time.elapsed());
106+
let processed = format!("{:?}", processed_time.elapsed());
107+
108+
println!(
109+
"--- {} {}---\n",
110+
processed,
111+
"-".repeat(processing_item.output_folder.len() - processed.len())
112+
);
92113
}
93114

94115
println!("Total time: {:?}", total_time.elapsed());

src/templates/config.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ output_folder = "./out/map"
88
# show_markers = false
99

1010
# Information for public repository in cimengine. See: https://github.com/CIMEngine/MapList
11+
# If you want to add your map to MapList, add link to public.json file in repository at index.json
12+
# {..., "id": { "external": "https://example.com/index.json" } }
1113
# [processing.public]
1214
# name = "Sample Map"
1315
# description = "This is a sample map"

src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clap::{Parser, Subcommand};
22
use geo::{Geometry, MultiPolygon};
33
use geo::{Point, Polygon};
4-
use geojson::{Feature, FeatureCollection, Value};
4+
use geojson::{FeatureCollection, Value};
55
use serde::{Deserialize, Serialize};
66
use serde_json::json;
77

src/utils.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
use std::{fs, marker, path::Path};
1+
use std::{fs, path::Path};
22

33
use geo::{BooleanOps, MultiPolygon};
4-
use geojson::{Feature, FeatureCollection, GeoJson};
4+
use geojson::GeoJson;
55

6-
use crate::types::{
7-
Config, CountryConfig, CountryData, Marker, Territory, ToCollection, ToCountryFeature,
8-
ToFeature, ToFeatures, ToMultiPolygon, ToSplitGeo, UnsplitGeo,
9-
};
6+
use crate::types::{Config, CountryConfig, CountryData, Territory, ToMultiPolygon, ToSplitGeo};
107

118
pub fn read_config() -> Config {
129
let c = toml::from_str::<Config>(&fs::read_to_string("config.toml").unwrap());

0 commit comments

Comments
 (0)