mapshaper 0.5.109 → 0.5.110

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mapshaper",
3
- "version": "0.5.109",
3
+ "version": "0.5.110",
4
4
  "description": "A tool for editing vector datasets for mapping and GIS.",
5
5
  "keywords": [
6
6
  "shapefile",
@@ -27,7 +27,7 @@
27
27
  "prepublishOnly": "npm test; ./pre-publish",
28
28
  "postpublish": "./release_web_ui; ./release_github_version",
29
29
  "browserify_old": "browserify -r sync-request -r mproj -r buffer -r iconv-lite -r fs -r flatbush -r rw -r path -r d3-scale-chromatic -r d3-color -r d3-interpolate -o www/modules.js",
30
- "browserify": "browserify -r sync-request -r mproj -r buffer -r iconv-lite -r fs -r flatbush -r rw -r path -r d3-scale-chromatic -r d3-color -r d3-interpolate -r kdbush -o www/modules.js",
30
+ "browserify": "browserify -r sync-request -r mproj -r buffer -r iconv-lite -r fs -r flatbush -r rw -r path -r d3-scale-chromatic -r d3-color -r d3-interpolate -r kdbush -r @tmcw/togeojson -o www/modules.js",
31
31
  "watch": "rollup --config --watch",
32
32
  "dev": "rollup --config --watch"
33
33
  },
@@ -41,6 +41,8 @@
41
41
  "!.DS_Store"
42
42
  ],
43
43
  "dependencies": {
44
+ "@tmcw/togeojson": "^4.7.0",
45
+ "@xmldom/xmldom": "^0.8.2",
44
46
  "commander": "7.0.0",
45
47
  "cookies": "^0.8.0",
46
48
  "d3-color": "2.0.0",
@@ -1376,7 +1376,7 @@
1376
1376
  async function expandFiles(files) {
1377
1377
  var files2 = [], expanded;
1378
1378
  for (var f of files) {
1379
- if (internal.isZipFile(f.name)) {
1379
+ if (internal.isZipFile(f.name) || /\.kmz$/.test(f.name)) {
1380
1380
  expanded = await readZipFile(f);
1381
1381
  files2 = files2.concat(expanded);
1382
1382
  } else {
@@ -2861,8 +2861,9 @@
2861
2861
  prevArcs = active.dataset.arcs,
2862
2862
  prevTable = active.layer.data,
2863
2863
  prevTableSize = prevTable ? prevTable.size() : 0,
2864
- prevArcCount = prevArcs ? prevArcs.size() : 0;
2865
- internal.runParsedCommands(commands, model, function(err) {
2864
+ prevArcCount = prevArcs ? prevArcs.size() : 0,
2865
+ job = new internal.Job(model);
2866
+ internal.runParsedCommands(commands, job, function(err) {
2866
2867
  var flags = getCommandFlags(commands),
2867
2868
  active2 = model.getActiveLayer(),
2868
2869
  postArcs = active2.dataset.arcs,
@@ -2872,10 +2873,6 @@
2872
2873
  sameTable = prevTable == postTable && prevTableSize == postTableSize,
2873
2874
  sameArcs = prevArcs == postArcs && postArcCount == prevArcCount;
2874
2875
 
2875
- // restore default logging options, in case they were changed by the command
2876
- internal.setStateVar('QUIET', false);
2877
- internal.setStateVar('VERBOSE', false);
2878
-
2879
2876
  // kludge to signal map that filtered arcs need refreshing
2880
2877
  // TODO: find a better solution, outside the console
2881
2878
  if (!sameArcs) {
@@ -2922,7 +2919,7 @@
2922
2919
 
2923
2920
  function consoleMessage() {
2924
2921
  var msg = GUI.formatMessageArgs(arguments);
2925
- if (internal.loggingEnabled() && !internal.getStateVar('QUIET')) {
2922
+ if (internal.loggingEnabled()) {
2926
2923
  toLog(msg, 'console-message');
2927
2924
  }
2928
2925
  }
@@ -4396,51 +4393,28 @@
4396
4393
 
4397
4394
  var Buffer = require('buffer').Buffer; // works with browserify
4398
4395
 
4399
- var context = createContext(); // command context (persist for the current command cycle)
4396
+ // This module provides a way for multiple jobs to run together asynchronously
4397
+ // while keeping job-level context variables (like "defs") separate.
4400
4398
 
4401
- function runningInBrowser() {
4402
- return typeof window !== 'undefined' && typeof window.document !== 'undefined';
4403
- }
4399
+ var stash = {};
4404
4400
 
4405
- function getStateVar(key) {
4406
- return context[key];
4407
- }
4408
-
4409
- function setStateVar(key, val) {
4410
- context[key] = val;
4411
- }
4412
-
4413
- function createContext() {
4414
- return {
4415
- DEBUG: false,
4416
- QUIET: false,
4417
- VERBOSE: false,
4418
- defs: {},
4419
- input_files: []
4420
- };
4401
+ function stashVar(key, val) {
4402
+ if (key in stash) {
4403
+ error('Tried to replace a stashed variable:', key);
4404
+ }
4405
+ stash[key] = val;
4421
4406
  }
4422
4407
 
4423
- // Install a new set of context variables, clear them when an async callback is called.
4424
- // @cb callback function to wrap
4425
- // returns wrapped callback function
4426
- function createAsyncContext(cb) {
4427
- context = createContext();
4428
- return function() {
4429
- cb.apply(null, utils.toArray(arguments));
4430
- // clear context after cb(), so output/errors can be handled in current context
4431
- context = createContext();
4432
- };
4408
+ function getStashedVar(key) {
4409
+ if (key in stash === false) {
4410
+ return undefined; // to support running commands in tests
4411
+ // error('Tried to read a nonexistent variable from the stash:', key);
4412
+ }
4413
+ return stash[key];
4433
4414
  }
4434
4415
 
4435
- // Save the current context, restore it when an async callback is called
4436
- // @cb callback function to wrap
4437
- // returns wrapped callback function
4438
- function preserveContext(cb) {
4439
- var ctx = context;
4440
- return function() {
4441
- context = ctx;
4442
- cb.apply(null, utils.toArray(arguments));
4443
- };
4416
+ function clearStash() {
4417
+ stash = {};
4444
4418
  }
4445
4419
 
4446
4420
  var LOGGING = false;
@@ -4522,13 +4496,13 @@
4522
4496
 
4523
4497
  function verbose() {
4524
4498
  // verbose can be set globally with the -verbose command or separately for each command
4525
- if (getStateVar('VERBOSE') || getStateVar('verbose')) {
4499
+ if (getStashedVar('VERBOSE')) {
4526
4500
  message.apply(null, arguments);
4527
4501
  }
4528
4502
  }
4529
4503
 
4530
4504
  function debug() {
4531
- if (getStateVar('DEBUG') || getStateVar('debug')) {
4505
+ if (getStashedVar('DEBUG')) {
4532
4506
  logArgs(arguments);
4533
4507
  }
4534
4508
  }
@@ -4608,7 +4582,7 @@
4608
4582
 
4609
4583
  function messageArgs(args) {
4610
4584
  var arr = utils.toArray(args);
4611
- var cmd = getStateVar('current_command');
4585
+ var cmd = getStashedVar('current_command');
4612
4586
  if (cmd && cmd != 'help') {
4613
4587
  arr.unshift('[' + cmd + ']');
4614
4588
  }
@@ -4616,7 +4590,7 @@
4616
4590
  }
4617
4591
 
4618
4592
  function logArgs(args) {
4619
- if (!LOGGING || getStateVar('QUIET') || !utils.isArrayLike(args)) return;
4593
+ if (!LOGGING || getStashedVar('QUIET') || !utils.isArrayLike(args)) return;
4620
4594
  var msg = formatLogArgs(args);
4621
4595
  if (STDOUT) console.log(msg);
4622
4596
  else console.error(msg);
@@ -7585,7 +7559,10 @@
7585
7559
  if (!active(e)) return;
7586
7560
  var textNode = getTextTarget3(e);
7587
7561
  var table = hit.getTargetDataTable();
7588
- if (!textNode || !table) return false;
7562
+ if (!textNode || !table) {
7563
+ activeId = -1;
7564
+ return false;
7565
+ }
7589
7566
  activeId = e.id;
7590
7567
  activeRecord = getLabelRecordById(activeId);
7591
7568
  downEvt = e;
@@ -7593,7 +7570,7 @@
7593
7570
  });
7594
7571
 
7595
7572
  hit.on('drag', function(e) {
7596
- if (!active(e)) return;
7573
+ if (!active(e) || activeId == -1) return;
7597
7574
  if (e.id != activeId) {
7598
7575
  error$1("Mismatched hit ids:", e.id, activeId);
7599
7576
  }
@@ -7613,7 +7590,7 @@
7613
7590
  });
7614
7591
 
7615
7592
  hit.on('dragend', function(e) {
7616
- if (!active(e)) return;
7593
+ if (!active(e) || activeId == -1) return;
7617
7594
  gui.dispatchEvent('label_dragend', {FID: e.id});
7618
7595
  activeId = -1;
7619
7596
  activeRecord = null;
@@ -8898,8 +8875,7 @@
8898
8875
  if (mapScale < 0.5) {
8899
8876
  s *= Math.pow(mapScale + 0.5, 0.35);
8900
8877
  } else if (mapScale > 100) {
8901
- if (!internal.getStateVar('DEBUG')) // thin lines for debugging
8902
- s *= Math.pow(mapScale - 99, 0.10);
8878
+ s *= Math.pow(mapScale - 99, 0.10);
8903
8879
  }
8904
8880
  return s;
8905
8881
  }