mirror of
https://github.com/Turfjs/turf.git
synced 2026-01-25 16:07:00 +00:00
* Configure ESlint and Prettier - Disable all eslint rules that trigger - Build's lint step now runs monorepoint, prettier, and eslint - Remove all tslint references * [auto] run prettier on everything Co-authored-by: Matt Fedderly <mfedderly@palantir.com>
58 lines
1.5 KiB
JavaScript
58 lines
1.5 KiB
JavaScript
const fs = require("fs");
|
|
const test = require("tape");
|
|
const path = require("path");
|
|
const load = require("load-json-file");
|
|
const write = require("write-json-file");
|
|
const bboxPoly = require("@turf/bbox-polygon").default;
|
|
const truncate = require("@turf/truncate").default;
|
|
const rectangleGrid = require("./index").default;
|
|
|
|
const directories = {
|
|
in: path.join(__dirname, "test", "in") + path.sep,
|
|
out: path.join(__dirname, "test", "out") + path.sep,
|
|
};
|
|
|
|
let fixtures = fs.readdirSync(directories.in).map((filename) => {
|
|
return {
|
|
filename,
|
|
name: path.parse(filename).name,
|
|
json: load.sync(directories.in + filename),
|
|
};
|
|
});
|
|
|
|
test("rectangle-grid", (t) => {
|
|
for (const { name, json } of fixtures) {
|
|
const { bbox, cellWidth, cellHeight, units, properties, mask } = json;
|
|
const options = {
|
|
mask,
|
|
units,
|
|
properties,
|
|
};
|
|
const result = truncate(
|
|
rectangleGrid(bbox, cellWidth, cellHeight, options)
|
|
);
|
|
|
|
// Add styled GeoJSON to the result
|
|
const poly = bboxPoly(bbox);
|
|
poly.properties = {
|
|
stroke: "#F00",
|
|
"stroke-width": 6,
|
|
"fill-opacity": 0,
|
|
};
|
|
result.features.push(poly);
|
|
if (options.mask) {
|
|
options.mask.properties = {
|
|
stroke: "#00F",
|
|
"stroke-width": 6,
|
|
"fill-opacity": 0,
|
|
};
|
|
result.features.push(options.mask);
|
|
}
|
|
|
|
if (process.env.REGEN)
|
|
write.sync(directories.out + name + ".geojson", result);
|
|
t.deepEqual(result, load.sync(directories.out + name + ".geojson"), name);
|
|
}
|
|
t.end();
|
|
});
|