mapshaper 0.6.31 → 0.6.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/mapshaper.js CHANGED
@@ -1,6 +1,6 @@
1
1
  (function () {
2
2
 
3
- var VERSION = "0.6.31";
3
+ var VERSION = "0.6.32";
4
4
 
5
5
 
6
6
  var utils = /*#__PURE__*/Object.freeze({
@@ -24840,13 +24840,12 @@ ${svg}
24840
24840
 
24841
24841
  parser.command('run')
24842
24842
  .describe('create commands on-the-fly and run them')
24843
- .option('include', {
24844
- // TODO: remove this option
24845
- })
24846
- .option('commands', {
24843
+ .option('expression', {
24847
24844
  DEFAULT: true,
24848
- describe: 'command string or JS expresson to generate command(s)'
24845
+ describe: 'JS expression to generate command(s)'
24849
24846
  })
24847
+ // deprecated
24848
+ .option('commands', {alias_to: 'expression'})
24850
24849
  .option('target', targetOpt);
24851
24850
 
24852
24851
  parser.command('scalebar')
@@ -34730,7 +34729,64 @@ ${svg}
34730
34729
  };
34731
34730
  }
34732
34731
 
34733
- cmd.define = function(opts) {
34732
+ function compileIfCommandExpression(expr, catalog, opts) {
34733
+ return compileLayerExpression(expr, catalog, opts);
34734
+ }
34735
+
34736
+
34737
+ function compileLayerExpression(expr, catalog, opts) {
34738
+ var targetId = opts.layer || opts.target || null;
34739
+ var targets = catalog.findCommandTargets(targetId);
34740
+ var isSingle = targets.length == 1 && targets[0].layers.length == 1;
34741
+ if (targets.length === 0 && targetId) {
34742
+ stop('Layer not found:', targetId);
34743
+ }
34744
+ // var vars = getAssignedVars(exp);
34745
+ var defs = getStashedVar('defs') || {};
34746
+
34747
+ var ctx;
34748
+ if (isSingle) {
34749
+ ctx = getLayerProxy(targets[0].layers[0], targets[0].dataset.arcs);
34750
+ } else {
34751
+ ctx = getNullLayerProxy(targets);
34752
+ }
34753
+ ctx.global = defs; // TODO: remove duplication with mapshaper.expressions.mjs
34754
+ var exprOpts = Object.assign({returns: true}, opts);
34755
+ var func = compileExpressionToFunction(expr, exprOpts);
34756
+
34757
+ // @geoType: optional geometry type (polygon, polyline, point, null);
34758
+ ctx.layer_exists = function(name, geoType) {
34759
+ try {
34760
+ var targets = catalog.findCommandTargets(name, geoType);
34761
+ if (targets.length > 0) return true;
34762
+ } catch(e) {}
34763
+ return false;
34764
+ };
34765
+
34766
+ ctx.file_exists = function(file) {
34767
+ return cli.isFile(file);
34768
+ };
34769
+
34770
+ return function() {
34771
+ try {
34772
+ return func.call(ctx, defs, ctx);
34773
+ } catch(e) {
34774
+ // if (opts.quiet) throw e;
34775
+ stop(e.name, "in expression [" + expr + "]:", e.message);
34776
+ }
34777
+ };
34778
+ }
34779
+
34780
+ /*
34781
+ cmd.define_v2 = function(catalog, opts) {
34782
+ if (!opts.expression) {
34783
+ stop('Missing an assignment expression');
34784
+ }
34785
+ compileLayerExpression(opts.expression, catalog, opts)();
34786
+ };
34787
+ */
34788
+
34789
+ cmd.define = function(catalog, opts) {
34734
34790
  if (!opts.expression) {
34735
34791
  stop('Missing an assignment expression');
34736
34792
  }
@@ -38418,46 +38474,6 @@ ${svg}
38418
38474
  return job.control || (job.control = {});
38419
38475
  }
38420
38476
 
38421
- function compileIfCommandExpression(expr, catalog, opts) {
38422
- var targetId = opts.layer || opts.target || null;
38423
- var targets = catalog.findCommandTargets(targetId);
38424
- var isSingle = targets.length == 1 && targets[0].layers.length == 1;
38425
- if (targets.length === 0 && targetId) {
38426
- stop('Layer not found:', targetId);
38427
- }
38428
- var ctx;
38429
- if (isSingle) {
38430
- ctx = getLayerProxy(targets[0].layers[0], targets[0].dataset.arcs);
38431
- } else {
38432
- ctx = getNullLayerProxy(targets);
38433
- }
38434
- ctx.global = getStashedVar('defs') || {}; // TODO: remove duplication with mapshaper.expressions.mjs
38435
- var exprOpts = Object.assign({returns: true}, opts);
38436
- var func = compileExpressionToFunction(expr, exprOpts);
38437
-
38438
- // @geoType: optional geometry type (polygon, polyline, point, null);
38439
- ctx.layer_exists = function(name, geoType) {
38440
- try {
38441
- var targets = catalog.findCommandTargets(name, geoType);
38442
- if (targets.length > 0) return true;
38443
- } catch(e) {}
38444
- return false;
38445
- };
38446
-
38447
- ctx.file_exists = function(file) {
38448
- return cli.isFile(file);
38449
- };
38450
-
38451
- return function() {
38452
- try {
38453
- return func.call(ctx, {}, ctx);
38454
- } catch(e) {
38455
- // if (opts.quiet) throw e;
38456
- stop(e.name, "in expression [" + expr + "]:", e.message);
38457
- }
38458
- };
38459
- }
38460
-
38461
38477
  function skipCommand(cmdName, job) {
38462
38478
  // allow all control commands to run
38463
38479
  if (jobIsStopped(job)) return true;
@@ -40914,13 +40930,10 @@ ${svg}
40914
40930
 
40915
40931
  cmd.run = function(job, targets, opts, cb) {
40916
40932
  var commandStr, commands;
40917
- if (opts.include) {
40918
- cmd.include({file: opts.include});
40919
- }
40920
- if (!opts.commands) {
40921
- stop("Missing commands parameter");
40933
+ if (!opts.expression) {
40934
+ stop("Missing expression parameter");
40922
40935
  }
40923
- commandStr = runGlobalExpression(opts.commands, targets);
40936
+ commandStr = runGlobalExpression(opts.expression, targets);
40924
40937
  if (commandStr) {
40925
40938
  commands = parseCommands(commandStr);
40926
40939
  runParsedCommands(commands, job, cb);
@@ -40937,6 +40950,8 @@ ${svg}
40937
40950
  targetData = getRunCommandData(targets[0]);
40938
40951
  Object.defineProperty(ctx, 'target', {value: targetData});
40939
40952
  }
40953
+ // Add defined functions and data to the expression context
40954
+ // (Such as functions imported via the -require command)
40940
40955
  utils.extend(ctx, getStashedVar('defs'));
40941
40956
  try {
40942
40957
  output = Function('ctx', 'with(ctx) {return (' + expression + ');}').call({}, ctx);
@@ -43220,7 +43235,7 @@ ${svg}
43220
43235
  applyCommandToEachLayer(cmd.dashlines, targetLayers, targetDataset, opts);
43221
43236
 
43222
43237
  } else if (name == 'define') {
43223
- cmd.define(opts);
43238
+ cmd.define(job.catalog, opts);
43224
43239
 
43225
43240
  } else if (name == 'dissolve') {
43226
43241
  outputLayers = applyCommandToEachLayer(cmd.dissolve, targetLayers, arcs, opts);
@@ -43648,7 +43663,6 @@ ${svg}
43648
43663
 
43649
43664
  // Unified function for processing calls to runCommands() and applyCommands()
43650
43665
  function _runCommands(argv, opts, callback) {
43651
-
43652
43666
  var outputArr = opts.output || null,
43653
43667
  inputObj = opts.input,
43654
43668
  commands;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mapshaper",
3
- "version": "0.6.31",
3
+ "version": "0.6.32",
4
4
  "description": "A tool for editing vector datasets for mapping and GIS.",
5
5
  "keywords": [
6
6
  "shapefile",
package/www/index.html CHANGED
@@ -154,9 +154,14 @@
154
154
  <div class="export-formats option-menu">
155
155
  </div>
156
156
 
157
- <div class="option-menu"><input type="text" class="advanced-options" placeholder="command line options" /><div class="tip-button">?<div class="tip-anchor">
158
- <div class="tip">Enter options from the command line interface for the -o command. Examples: "bbox" "no-quantization"
159
- "precision=0.001"</div></div></div></div>
157
+ <div class="option-menu"><input type="text" class="advanced-options" placeholder="command line options" />
158
+ <a href="https://github.com/mbloch/mapshaper/wiki/Command-Reference#-o-output" target="_mapshaper_output_docs">
159
+ <div class="tip-button">?<div class="tip-anchor">
160
+ <div class="tip">Enter options from the command line interface for
161
+ the -o command. Examples: bbox no-quantization
162
+ precision=0.001. Click to see all options.</div></div></div></a>
163
+
164
+ </div>
160
165
  <!-- <div class="cancel-btn btn dialog-btn">Cancel</div> -->
161
166
  <div class="save-btn btn dialog-btn">Export</div>
162
167
  <span id="save-preference"><input type="checkbox"/>choose directory</span>
@@ -283,10 +288,13 @@ apply to TopoJSON files.</div></div></div></div> -->
283
288
 
284
289
  </div>
285
290
 
286
- <div><input type="text" class="advanced-options" placeholder="import options" /><div class="tip-button">?<div class="tip-anchor">
291
+ <div><input type="text" class="advanced-options" placeholder="import options" />
292
+ <a href="https://github.com/mbloch/mapshaper/wiki/Command-Reference#-i-input" target="_mapshaper_import_docs">
293
+ <div class="tip-button">?<div class="tip-anchor">
287
294
  <div class="tip">Enter options from the command line
288
- interface. Examples: <span id="import-option-examples">no-topology
289
- encoding=big5</span></div></div></div></div>
295
+ interface. Examples: <span id="import-option-examples">snap no-topology
296
+ encoding=big5</span>. Click to see all options.</div></div></div></div>
297
+ </a>
290
298
 
291
299
  </div>
292
300
 
@@ -1834,6 +1834,7 @@
1834
1834
  var importCount = 0;
1835
1835
  var importTotal = 0;
1836
1836
  var overQuickView = false;
1837
+ var useQuickView = false;
1837
1838
  var queuedFiles = [];
1838
1839
  var manifestFiles = opts.files || [];
1839
1840
  var catalog;
@@ -1863,21 +1864,17 @@
1863
1864
  }
1864
1865
  });
1865
1866
 
1866
- function useQuickView() {
1867
- return initialImport && (opts.quick_view || overQuickView);
1868
- }
1869
-
1870
1867
  function initDropArea(el, isQuick) {
1871
1868
  var area = El(el)
1872
1869
  .on('dragleave', onout)
1873
- .on('dragover', onover)
1870
+ .on('dragover', function() {overQuickView = !!isQuick; onover();})
1874
1871
  .on('mouseover', onover)
1875
1872
  .on('mouseout', onout);
1876
1873
 
1877
1874
  function onover() {
1878
- overQuickView = !!isQuick;
1879
1875
  area.addClass('dragover');
1880
1876
  }
1877
+
1881
1878
  function onout() {
1882
1879
  overQuickView = false;
1883
1880
  area.removeClass('dragover');
@@ -1981,6 +1978,7 @@
1981
1978
  var names = getFileNames(files);
1982
1979
  var expanded = [];
1983
1980
  if (files.length === 0) return;
1981
+ useQuickView = importCount === 0 && (opts.quick_view || overQuickView);
1984
1982
  try {
1985
1983
  expanded = await expandFiles(files);
1986
1984
  } catch(e) {
@@ -1995,7 +1993,7 @@
1995
1993
  return;
1996
1994
  }
1997
1995
  gui.enterMode('import');
1998
- if (useQuickView()) {
1996
+ if (useQuickView) {
1999
1997
  await importQueuedFiles();
2000
1998
  } else {
2001
1999
  gui.container.addClass('queued-files');
@@ -2091,7 +2089,7 @@
2091
2089
 
2092
2090
  function readImportOpts() {
2093
2091
  var importOpts;
2094
- if (useQuickView()) {
2092
+ if (useQuickView) {
2095
2093
  importOpts = {}; // default opts using quickview
2096
2094
  } else {
2097
2095
  var freeform = El('#import-options .advanced-options').node().value;
package/www/mapshaper.js CHANGED
@@ -1,6 +1,6 @@
1
1
  (function () {
2
2
 
3
- var VERSION = "0.6.31";
3
+ var VERSION = "0.6.32";
4
4
 
5
5
 
6
6
  var utils = /*#__PURE__*/Object.freeze({
@@ -24840,13 +24840,12 @@ ${svg}
24840
24840
 
24841
24841
  parser.command('run')
24842
24842
  .describe('create commands on-the-fly and run them')
24843
- .option('include', {
24844
- // TODO: remove this option
24845
- })
24846
- .option('commands', {
24843
+ .option('expression', {
24847
24844
  DEFAULT: true,
24848
- describe: 'command string or JS expresson to generate command(s)'
24845
+ describe: 'JS expression to generate command(s)'
24849
24846
  })
24847
+ // deprecated
24848
+ .option('commands', {alias_to: 'expression'})
24850
24849
  .option('target', targetOpt);
24851
24850
 
24852
24851
  parser.command('scalebar')
@@ -34730,7 +34729,64 @@ ${svg}
34730
34729
  };
34731
34730
  }
34732
34731
 
34733
- cmd.define = function(opts) {
34732
+ function compileIfCommandExpression(expr, catalog, opts) {
34733
+ return compileLayerExpression(expr, catalog, opts);
34734
+ }
34735
+
34736
+
34737
+ function compileLayerExpression(expr, catalog, opts) {
34738
+ var targetId = opts.layer || opts.target || null;
34739
+ var targets = catalog.findCommandTargets(targetId);
34740
+ var isSingle = targets.length == 1 && targets[0].layers.length == 1;
34741
+ if (targets.length === 0 && targetId) {
34742
+ stop('Layer not found:', targetId);
34743
+ }
34744
+ // var vars = getAssignedVars(exp);
34745
+ var defs = getStashedVar('defs') || {};
34746
+
34747
+ var ctx;
34748
+ if (isSingle) {
34749
+ ctx = getLayerProxy(targets[0].layers[0], targets[0].dataset.arcs);
34750
+ } else {
34751
+ ctx = getNullLayerProxy(targets);
34752
+ }
34753
+ ctx.global = defs; // TODO: remove duplication with mapshaper.expressions.mjs
34754
+ var exprOpts = Object.assign({returns: true}, opts);
34755
+ var func = compileExpressionToFunction(expr, exprOpts);
34756
+
34757
+ // @geoType: optional geometry type (polygon, polyline, point, null);
34758
+ ctx.layer_exists = function(name, geoType) {
34759
+ try {
34760
+ var targets = catalog.findCommandTargets(name, geoType);
34761
+ if (targets.length > 0) return true;
34762
+ } catch(e) {}
34763
+ return false;
34764
+ };
34765
+
34766
+ ctx.file_exists = function(file) {
34767
+ return cli.isFile(file);
34768
+ };
34769
+
34770
+ return function() {
34771
+ try {
34772
+ return func.call(ctx, defs, ctx);
34773
+ } catch(e) {
34774
+ // if (opts.quiet) throw e;
34775
+ stop(e.name, "in expression [" + expr + "]:", e.message);
34776
+ }
34777
+ };
34778
+ }
34779
+
34780
+ /*
34781
+ cmd.define_v2 = function(catalog, opts) {
34782
+ if (!opts.expression) {
34783
+ stop('Missing an assignment expression');
34784
+ }
34785
+ compileLayerExpression(opts.expression, catalog, opts)();
34786
+ };
34787
+ */
34788
+
34789
+ cmd.define = function(catalog, opts) {
34734
34790
  if (!opts.expression) {
34735
34791
  stop('Missing an assignment expression');
34736
34792
  }
@@ -38418,46 +38474,6 @@ ${svg}
38418
38474
  return job.control || (job.control = {});
38419
38475
  }
38420
38476
 
38421
- function compileIfCommandExpression(expr, catalog, opts) {
38422
- var targetId = opts.layer || opts.target || null;
38423
- var targets = catalog.findCommandTargets(targetId);
38424
- var isSingle = targets.length == 1 && targets[0].layers.length == 1;
38425
- if (targets.length === 0 && targetId) {
38426
- stop('Layer not found:', targetId);
38427
- }
38428
- var ctx;
38429
- if (isSingle) {
38430
- ctx = getLayerProxy(targets[0].layers[0], targets[0].dataset.arcs);
38431
- } else {
38432
- ctx = getNullLayerProxy(targets);
38433
- }
38434
- ctx.global = getStashedVar('defs') || {}; // TODO: remove duplication with mapshaper.expressions.mjs
38435
- var exprOpts = Object.assign({returns: true}, opts);
38436
- var func = compileExpressionToFunction(expr, exprOpts);
38437
-
38438
- // @geoType: optional geometry type (polygon, polyline, point, null);
38439
- ctx.layer_exists = function(name, geoType) {
38440
- try {
38441
- var targets = catalog.findCommandTargets(name, geoType);
38442
- if (targets.length > 0) return true;
38443
- } catch(e) {}
38444
- return false;
38445
- };
38446
-
38447
- ctx.file_exists = function(file) {
38448
- return cli.isFile(file);
38449
- };
38450
-
38451
- return function() {
38452
- try {
38453
- return func.call(ctx, {}, ctx);
38454
- } catch(e) {
38455
- // if (opts.quiet) throw e;
38456
- stop(e.name, "in expression [" + expr + "]:", e.message);
38457
- }
38458
- };
38459
- }
38460
-
38461
38477
  function skipCommand(cmdName, job) {
38462
38478
  // allow all control commands to run
38463
38479
  if (jobIsStopped(job)) return true;
@@ -40914,13 +40930,10 @@ ${svg}
40914
40930
 
40915
40931
  cmd.run = function(job, targets, opts, cb) {
40916
40932
  var commandStr, commands;
40917
- if (opts.include) {
40918
- cmd.include({file: opts.include});
40919
- }
40920
- if (!opts.commands) {
40921
- stop("Missing commands parameter");
40933
+ if (!opts.expression) {
40934
+ stop("Missing expression parameter");
40922
40935
  }
40923
- commandStr = runGlobalExpression(opts.commands, targets);
40936
+ commandStr = runGlobalExpression(opts.expression, targets);
40924
40937
  if (commandStr) {
40925
40938
  commands = parseCommands(commandStr);
40926
40939
  runParsedCommands(commands, job, cb);
@@ -40937,6 +40950,8 @@ ${svg}
40937
40950
  targetData = getRunCommandData(targets[0]);
40938
40951
  Object.defineProperty(ctx, 'target', {value: targetData});
40939
40952
  }
40953
+ // Add defined functions and data to the expression context
40954
+ // (Such as functions imported via the -require command)
40940
40955
  utils.extend(ctx, getStashedVar('defs'));
40941
40956
  try {
40942
40957
  output = Function('ctx', 'with(ctx) {return (' + expression + ');}').call({}, ctx);
@@ -43220,7 +43235,7 @@ ${svg}
43220
43235
  applyCommandToEachLayer(cmd.dashlines, targetLayers, targetDataset, opts);
43221
43236
 
43222
43237
  } else if (name == 'define') {
43223
- cmd.define(opts);
43238
+ cmd.define(job.catalog, opts);
43224
43239
 
43225
43240
  } else if (name == 'dissolve') {
43226
43241
  outputLayers = applyCommandToEachLayer(cmd.dissolve, targetLayers, arcs, opts);
@@ -43648,7 +43663,6 @@ ${svg}
43648
43663
 
43649
43664
  // Unified function for processing calls to runCommands() and applyCommands()
43650
43665
  function _runCommands(argv, opts, callback) {
43651
-
43652
43666
  var outputArr = opts.output || null,
43653
43667
  inputObj = opts.input,
43654
43668
  commands;