mirror of
https://github.com/CIMEngine/cimengine-build-tools.git
synced 2024-11-21 19:56:22 +03:00
feat: auto generate colors
This commit is contained in:
parent
a0ec2ef415
commit
5ba8c2b8b6
3 changed files with 52 additions and 12 deletions
36
package-lock.json
generated
36
package-lock.json
generated
|
@ -1,16 +1,17 @@
|
||||||
{
|
{
|
||||||
"name": "cimengine-build-tools",
|
"name": "cimengine-build-tools",
|
||||||
"version": "1.3.2",
|
"version": "1.4.2",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "cimengine-build-tools",
|
"name": "cimengine-build-tools",
|
||||||
"version": "1.3.2",
|
"version": "1.4.2",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@turf/turf": "^6.5.0",
|
"@turf/turf": "^6.5.0",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
|
"md5": "^2.3.0",
|
||||||
"yaml": "^2.3.1",
|
"yaml": "^2.3.1",
|
||||||
"yargs": "^17.7.2"
|
"yargs": "^17.7.2"
|
||||||
},
|
},
|
||||||
|
@ -1623,6 +1624,14 @@
|
||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/charenc": {
|
||||||
|
"version": "0.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/charenc/-/charenc-0.0.2.tgz",
|
||||||
|
"integrity": "sha512-yrLQ/yVUFXkzg7EDQsPieE/53+0RlaWTs+wBrvW36cyilJ2SaDWfl4Yj7MtLTXleV9uEKefbAGUPv2/iWSooRA==",
|
||||||
|
"engines": {
|
||||||
|
"node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/cliui": {
|
"node_modules/cliui": {
|
||||||
"version": "8.0.1",
|
"version": "8.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz",
|
||||||
|
@ -1681,6 +1690,14 @@
|
||||||
"quickselect": "^2.0.0"
|
"quickselect": "^2.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/crypt": {
|
||||||
|
"version": "0.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/crypt/-/crypt-0.0.2.tgz",
|
||||||
|
"integrity": "sha512-mCxBlsHFYh9C+HVpiEacem8FEBnMXgU9gy4zmNC+SXAZNB/1idgp/aulFJ4FgCi7GPEVbfyng092GqL2k2rmow==",
|
||||||
|
"engines": {
|
||||||
|
"node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/d3-array": {
|
"node_modules/d3-array": {
|
||||||
"version": "1.2.4",
|
"version": "1.2.4",
|
||||||
"resolved": "https://registry.npmjs.org/d3-array/-/d3-array-1.2.4.tgz",
|
"resolved": "https://registry.npmjs.org/d3-array/-/d3-array-1.2.4.tgz",
|
||||||
|
@ -1894,6 +1911,11 @@
|
||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/is-buffer": {
|
||||||
|
"version": "1.1.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz",
|
||||||
|
"integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w=="
|
||||||
|
},
|
||||||
"node_modules/is-date-object": {
|
"node_modules/is-date-object": {
|
||||||
"version": "1.0.5",
|
"version": "1.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.5.tgz",
|
"resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.5.tgz",
|
||||||
|
@ -1936,6 +1958,16 @@
|
||||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
||||||
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
|
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
|
||||||
},
|
},
|
||||||
|
"node_modules/md5": {
|
||||||
|
"version": "2.3.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/md5/-/md5-2.3.0.tgz",
|
||||||
|
"integrity": "sha512-T1GITYmFaKuO91vxyoQMFETst+O71VUPEU3ze5GNzDm0OWdP8v1ziTaAEPUr/3kLsY3Sftgz242A1SetQiDL7g==",
|
||||||
|
"dependencies": {
|
||||||
|
"charenc": "0.0.2",
|
||||||
|
"crypt": "0.0.2",
|
||||||
|
"is-buffer": "~1.1.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/object-assign": {
|
"node_modules/object-assign": {
|
||||||
"version": "4.1.1",
|
"version": "4.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "cimengine-build-tools",
|
"name": "cimengine-build-tools",
|
||||||
"version": "1.3.2",
|
"version": "1.4.2",
|
||||||
"description": "Geojson data processing tools for CIMEngine",
|
"description": "Geojson data processing tools for CIMEngine",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -32,6 +32,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@turf/turf": "^6.5.0",
|
"@turf/turf": "^6.5.0",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
|
"md5": "^2.3.0",
|
||||||
"yaml": "^2.3.1",
|
"yaml": "^2.3.1",
|
||||||
"yargs": "^17.7.2"
|
"yargs": "^17.7.2"
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ const fs = require("fs");
|
||||||
const YAML = require("yaml");
|
const YAML = require("yaml");
|
||||||
const _ = require("lodash");
|
const _ = require("lodash");
|
||||||
const path = require("node:path");
|
const path = require("node:path");
|
||||||
|
const md5 = require("md5");
|
||||||
|
|
||||||
const yargs = require("yargs/yargs");
|
const yargs = require("yargs/yargs");
|
||||||
const { hideBin } = require("yargs/helpers");
|
const { hideBin } = require("yargs/helpers");
|
||||||
|
@ -25,15 +26,14 @@ const geofixConf = {
|
||||||
};
|
};
|
||||||
|
|
||||||
let layers = YAML.parse(fs.readFileSync(geofixConf.layers, "utf-8"));
|
let layers = YAML.parse(fs.readFileSync(geofixConf.layers, "utf-8"));
|
||||||
let countries_properties = YAML.parse(
|
let countries_properties =
|
||||||
fs.readFileSync(geofixConf.properties, "utf-8")
|
YAML.parse(fs.readFileSync(geofixConf.properties, "utf-8")) || {};
|
||||||
);
|
|
||||||
let config = YAML.parse(fs.readFileSync(geofixConf.config, "utf-8"));
|
let config = YAML.parse(fs.readFileSync(geofixConf.config, "utf-8"));
|
||||||
|
|
||||||
let features = [];
|
let features = [];
|
||||||
|
|
||||||
for (country of layers) {
|
for (country of layers) {
|
||||||
let properties = countries_properties[country];
|
let properties = countries_properties[country] || {};
|
||||||
|
|
||||||
let co_features = JSON.parse(
|
let co_features = JSON.parse(
|
||||||
fs.readFileSync(
|
fs.readFileSync(
|
||||||
|
@ -58,10 +58,17 @@ for (country of layers) {
|
||||||
JSON.stringify(co_features, null, " ")
|
JSON.stringify(co_features, null, " ")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!properties.fill) {
|
||||||
|
properties.fill = `#${md5(country).substring(0, 6)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!properties.stroke) {
|
||||||
|
properties.stroke = `#${md5(country).substring(6, 12)}`;
|
||||||
|
}
|
||||||
|
|
||||||
co_features = co_features.features;
|
co_features = co_features.features;
|
||||||
|
|
||||||
features = [
|
features.unshift(
|
||||||
...features,
|
|
||||||
...co_features.map((val) => {
|
...co_features.map((val) => {
|
||||||
if (val.geometry.type == "Polygon") {
|
if (val.geometry.type == "Polygon") {
|
||||||
val.properties = properties;
|
val.properties = properties;
|
||||||
|
@ -69,13 +76,13 @@ for (country of layers) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}),
|
})
|
||||||
];
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let geo = {
|
let geo = {
|
||||||
type: "FeatureCollection",
|
type: "FeatureCollection",
|
||||||
features: features.reverse(),
|
features,
|
||||||
};
|
};
|
||||||
|
|
||||||
geo.features = geo.features.filter((v) => v.properties.name);
|
geo.features = geo.features.filter((v) => v.properties.name);
|
||||||
|
|
Loading…
Add table
Reference in a new issue