mirror of
https://github.com/CIMEngine/cimengine-build-tools.git
synced 2024-11-05 20:53:58 +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",
|
||||
"version": "1.3.2",
|
||||
"version": "1.4.2",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "cimengine-build-tools",
|
||||
"version": "1.3.2",
|
||||
"version": "1.4.2",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@turf/turf": "^6.5.0",
|
||||
"lodash": "^4.17.21",
|
||||
"md5": "^2.3.0",
|
||||
"yaml": "^2.3.1",
|
||||
"yargs": "^17.7.2"
|
||||
},
|
||||
|
@ -1623,6 +1624,14 @@
|
|||
"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": {
|
||||
"version": "8.0.1",
|
||||
"resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz",
|
||||
|
@ -1681,6 +1690,14 @@
|
|||
"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": {
|
||||
"version": "1.2.4",
|
||||
"resolved": "https://registry.npmjs.org/d3-array/-/d3-array-1.2.4.tgz",
|
||||
|
@ -1894,6 +1911,11 @@
|
|||
"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": {
|
||||
"version": "1.0.5",
|
||||
"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",
|
||||
"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": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "cimengine-build-tools",
|
||||
"version": "1.3.2",
|
||||
"version": "1.4.2",
|
||||
"description": "Geojson data processing tools for CIMEngine",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
@ -32,6 +32,7 @@
|
|||
"dependencies": {
|
||||
"@turf/turf": "^6.5.0",
|
||||
"lodash": "^4.17.21",
|
||||
"md5": "^2.3.0",
|
||||
"yaml": "^2.3.1",
|
||||
"yargs": "^17.7.2"
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ const fs = require("fs");
|
|||
const YAML = require("yaml");
|
||||
const _ = require("lodash");
|
||||
const path = require("node:path");
|
||||
const md5 = require("md5");
|
||||
|
||||
const yargs = require("yargs/yargs");
|
||||
const { hideBin } = require("yargs/helpers");
|
||||
|
@ -25,15 +26,14 @@ const geofixConf = {
|
|||
};
|
||||
|
||||
let layers = YAML.parse(fs.readFileSync(geofixConf.layers, "utf-8"));
|
||||
let countries_properties = YAML.parse(
|
||||
fs.readFileSync(geofixConf.properties, "utf-8")
|
||||
);
|
||||
let countries_properties =
|
||||
YAML.parse(fs.readFileSync(geofixConf.properties, "utf-8")) || {};
|
||||
let config = YAML.parse(fs.readFileSync(geofixConf.config, "utf-8"));
|
||||
|
||||
let features = [];
|
||||
|
||||
for (country of layers) {
|
||||
let properties = countries_properties[country];
|
||||
let properties = countries_properties[country] || {};
|
||||
|
||||
let co_features = JSON.parse(
|
||||
fs.readFileSync(
|
||||
|
@ -58,10 +58,17 @@ for (country of layers) {
|
|||
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;
|
||||
|
||||
features = [
|
||||
...features,
|
||||
features.unshift(
|
||||
...co_features.map((val) => {
|
||||
if (val.geometry.type == "Polygon") {
|
||||
val.properties = properties;
|
||||
|
@ -69,13 +76,13 @@ for (country of layers) {
|
|||
}
|
||||
|
||||
return val;
|
||||
}),
|
||||
];
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
let geo = {
|
||||
type: "FeatureCollection",
|
||||
features: features.reverse(),
|
||||
features,
|
||||
};
|
||||
|
||||
geo.features = geo.features.filter((v) => v.properties.name);
|
||||
|
|
Loading…
Reference in a new issue