From 3c7c161090aa00d3c686a149ac64bccfc5f8f7df Mon Sep 17 00:00:00 2001 From: Matthew Bloch Date: Mon, 19 Feb 2024 21:47:17 -0500 Subject: [PATCH] Add a second scalebar style, add cmd help for -scalebar command --- src/cli/mapshaper-options.mjs | 34 ++++++++++++++++++++++++------- src/cli/mapshaper-run-command.mjs | 4 ++++ src/crs/mapshaper-projections.mjs | 4 ++-- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/cli/mapshaper-options.mjs b/src/cli/mapshaper-options.mjs index 7fb59efb..ed130315 100644 --- a/src/cli/mapshaper-options.mjs +++ b/src/cli/mapshaper-options.mjs @@ -1987,13 +1987,33 @@ export function getOptionParser() { DEFAULT: true, describe: 'distance label, e.g. "35 miles"' }) - .option('top', {}) - .option('right', {}) - .option('bottom', {}) - .option('left', {}) - .option('font-size', {}) - // .option('font-family', {}) - .option('label-position', {}); // top or bottom + .option('style', { + describe: 'two options: a or b' + }) + .option('font-size', { + type: 'number' + }) + .option('tic-length', { + describe: 'length of tic marks (style b)', + type: 'number' + }) + .option('bar-width', { + describe: 'line width of bar', + type: 'number' + }) + .option('label-offset', { + type: 'number' + }) + .option('position', { + describe: 'e.g. bottom-right (default is top-left)' + }) + .option('label-position', { + describe: 'top or bottom' + }) + .option('margin', { + describe: 'offset in pixels from edge of map', + type: 'number' + }); parser.command('shape') .describe('create a polyline or polygon from coordinates') diff --git a/src/cli/mapshaper-run-command.mjs b/src/cli/mapshaper-run-command.mjs index 40b94672..2dc87b05 100644 --- a/src/cli/mapshaper-run-command.mjs +++ b/src/cli/mapshaper-run-command.mjs @@ -121,6 +121,10 @@ export async function runCommand(command, job) { return done(null); } + if (name == 'comment') { + return done(null); + } + if (!job) job = new Job(); job.startCommand(command); diff --git a/src/crs/mapshaper-projections.mjs b/src/crs/mapshaper-projections.mjs index f6bf9655..658dffd0 100644 --- a/src/crs/mapshaper-projections.mjs +++ b/src/crs/mapshaper-projections.mjs @@ -244,10 +244,10 @@ export function requireDatasetsHaveCompatibleCRS(arr) { // x, y: a point location in projected coordinates // Returns k, the ratio of coordinate distance to distance on the ground export function getScaleFactorAtXY(x, y, crs) { - var dist = 1; + var dist = 1 / crs.to_meter; var lp = mproj.pj_inv_deg({x: x, y: y}, crs); var lp2 = mproj.pj_inv_deg({x: x + dist, y: y}, crs); - var k = dist / geom.greatCircleDistance(lp.lam, lp.phi, lp2.lam, lp2.phi); + var k = 1 / geom.greatCircleDistance(lp.lam, lp.phi, lp2.lam, lp2.phi); return k; }