diff --git a/src/build.rs b/src/build.rs index 8ff50bb..65c5982 100644 --- a/src/build.rs +++ b/src/build.rs @@ -1,11 +1,10 @@ use std::{fs, path::Path, time}; -use geojson::{Feature, FeatureCollection}; use serde_json::json; use wax::{Glob, Pattern}; use crate::{ - types::{CountryData, ToCollection, ToFeature, ToFeatures}, + types::{CountryData, ToCollection}, utils::{diff_countries, get_country, read_config}, }; @@ -15,11 +14,13 @@ pub fn build() { let total_time = time::Instant::now(); for processing_item in config.processing { + println!("--- {} ---", processing_item.output_folder); + let processed_time = time::Instant::now(); let out_folder = Path::new(&processing_item.output_folder); - let tags = processing_item.tags.unwrap_or(vec!["*".to_string()]); + let tags = processing_item.tags.unwrap_or(vec![]); let globs: Vec = tags.iter().map(|tag| Glob::new(tag).unwrap()).collect(); let mut countries: Vec = vec![]; @@ -27,23 +28,36 @@ pub fn build() { { let dissolved_time = time::Instant::now(); - for country_id in &config.main.layers { - let country = get_country(country_id.to_owned()); + if tags.len() == 0 { + for country_id in &config.main.layers { + countries.push(get_country(country_id.to_owned())); + } + } else { + for country_id in &config.main.layers { + let country = get_country(country_id.to_owned()); - let mut matches = false; - for glob in &globs { - for tag in &country.config.tags.clone().unwrap_or(vec!["*".to_owned()]) { - if glob.is_match(tag.as_str()) { - matches = true; + match &country.config.tags { + Some(tags) => { + let mut matches = false; + for glob in &globs { + for tag in tags { + if glob.is_match(tag.as_str()) { + matches = true; + } + } + } + + if !matches { + continue; + } + + countries.push(country); + } + None => { + continue; } } } - - if !matches { - continue; - } - - countries.push(country); } println!("Dissolved in {:?}", dissolved_time.elapsed()); @@ -62,6 +76,7 @@ pub fn build() { }; // TODO: Add nature support + { let generated_time = time::Instant::now(); let countries_json = serde_json::to_string_pretty(&serde_json::Map::from_iter( @@ -88,7 +103,13 @@ pub fn build() { println!("Generated files in {:?}", generated_time.elapsed()); } - println!("Processed in {:?}\n---\n", processed_time.elapsed()); + let processed = format!("{:?}", processed_time.elapsed()); + + println!( + "--- {} {}---\n", + processed, + "-".repeat(processing_item.output_folder.len() - processed.len()) + ); } println!("Total time: {:?}", total_time.elapsed()); diff --git a/src/templates/config.toml b/src/templates/config.toml index ce3a1e3..2916eb0 100644 --- a/src/templates/config.toml +++ b/src/templates/config.toml @@ -8,6 +8,8 @@ output_folder = "./out/map" # show_markers = false # Information for public repository in cimengine. See: https://github.com/CIMEngine/MapList +# If you want to add your map to MapList, add link to public.json file in repository at index.json +# {..., "id": { "external": "https://example.com/index.json" } } # [processing.public] # name = "Sample Map" # description = "This is a sample map" diff --git a/src/types.rs b/src/types.rs index 6a3bc5c..c938797 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,7 +1,7 @@ use clap::{Parser, Subcommand}; use geo::{Geometry, MultiPolygon}; use geo::{Point, Polygon}; -use geojson::{Feature, FeatureCollection, Value}; +use geojson::{FeatureCollection, Value}; use serde::{Deserialize, Serialize}; use serde_json::json; diff --git a/src/utils.rs b/src/utils.rs index 798baff..661637f 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,12 +1,9 @@ -use std::{fs, marker, path::Path}; +use std::{fs, path::Path}; use geo::{BooleanOps, MultiPolygon}; -use geojson::{Feature, FeatureCollection, GeoJson}; +use geojson::GeoJson; -use crate::types::{ - Config, CountryConfig, CountryData, Marker, Territory, ToCollection, ToCountryFeature, - ToFeature, ToFeatures, ToMultiPolygon, ToSplitGeo, UnsplitGeo, -}; +use crate::types::{Config, CountryConfig, CountryData, Territory, ToMultiPolygon, ToSplitGeo}; pub fn read_config() -> Config { let c = toml::from_str::(&fs::read_to_string("config.toml").unwrap());