mapshaper 0.6.11 → 0.6.12

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.11";
3
+ var VERSION = "0.6.12";
4
4
 
5
5
 
6
6
  var utils = /*#__PURE__*/Object.freeze({
@@ -15644,9 +15644,11 @@ ${svg}
15644
15644
  } else if (buf instanceof ArrayBuffer) {
15645
15645
  // we're good
15646
15646
  } else if (typeof B$3 == 'function' && buf instanceof B$3) {
15647
- // Since node 0.10, DataView constructor doesn't accept Buffers,
15648
- // so need to copy Buffer to ArrayBuffer
15649
- buf = BinArray.toArrayBuffer(buf);
15647
+ if (buf.buffer && buf.buffer.byteLength == buf.length) {
15648
+ buf = buf.buffer;
15649
+ } else {
15650
+ buf = BinArray.copyToArrayBuffer(buf);
15651
+ }
15650
15652
  } else {
15651
15653
  error("BinArray constructor takes an integer, ArrayBuffer or Buffer argument");
15652
15654
  }
@@ -15692,7 +15694,7 @@ ${svg}
15692
15694
  return bytes;
15693
15695
  };
15694
15696
 
15695
- BinArray.toArrayBuffer = function(src) {
15697
+ BinArray.copyToArrayBuffer = function(src) {
15696
15698
  var n = src.length,
15697
15699
  dest = new ArrayBuffer(n),
15698
15700
  view = new Uint8Array(dest);
@@ -23497,9 +23499,9 @@ ${svg}
23497
23499
 
23498
23500
  if (!content) {
23499
23501
  reader = new FileReader(filename);
23500
- } else if (content instanceof ArrayBuffer) {
23502
+ } else if (content instanceof ArrayBuffer || content instanceof Buffer) {
23501
23503
  // Web API imports JSON as ArrayBuffer, to support larger files
23502
- if (content.byteLength < 1e7) {
23504
+ if ((content.byteLength || content.length) < 1e7) {
23503
23505
  // content = utils.createBuffer(content).toString();
23504
23506
  content = bufferToString(utils.createBuffer(content));
23505
23507
  } else {
@@ -23524,7 +23526,7 @@ ${svg}
23524
23526
  content = JSON.parse(content); // ~3sec for 100MB string
23525
23527
  } catch(e) {
23526
23528
  // stop("Unable to parse JSON");
23527
- stop('JSON parsing error --', e.message);
23529
+ stop('JSON parsing error:', e.message);
23528
23530
  }
23529
23531
  }
23530
23532
  if (opts.json_path) {
@@ -23816,9 +23818,6 @@ ${svg}
23816
23818
  }
23817
23819
  // TODO: consider using a temp file, to support incremental reading
23818
23820
  content = require('zlib').gunzipSync(cli.readFile(pathgz));
23819
- if (fileType == 'json' || fileType == 'text') {
23820
- content = trimBOM(decodeString(content, encoding || 'utf-8'));
23821
- }
23822
23821
 
23823
23822
  } else { // type can't be inferred from filename -- try reading as text
23824
23823
  content = cli.readFile(path, encoding || 'utf-8', cache);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mapshaper",
3
- "version": "0.6.11",
3
+ "version": "0.6.12",
4
4
  "description": "A tool for editing vector datasets for mapping and GIS.",
5
5
  "keywords": [
6
6
  "shapefile",
package/www/index.html CHANGED
@@ -97,7 +97,10 @@
97
97
  <img class="pin-btn pinned" src="images/eye2.png">
98
98
  </div>
99
99
  <div class="layer-list"></div>
100
- <div><div id="add-file-btn" class="dialog-btn btn">Add a file</div></div>
100
+ <div>
101
+ <div id="add-file-btn" class="dialog-btn btn">Add a file</div>
102
+ <!-- <div id="add-empty-btn" class="dialog-btn btn">Empty layer</div> -->
103
+ </div>
101
104
  </div>
102
105
  </div>
103
106
  </div>
@@ -1277,6 +1277,7 @@
1277
1277
  new FileChooser('#file-selection-btn', receiveFiles);
1278
1278
  new FileChooser('#import-buttons .add-btn', receiveFiles);
1279
1279
  new FileChooser('#add-file-btn', receiveFiles);
1280
+ // new SimpleButton('#add-empty-btn').on('click', addEmptyLayer);
1280
1281
  initDropArea('#import-quick-drop', true);
1281
1282
  initDropArea('#import-drop');
1282
1283
  gui.keyboard.onMenuSubmit(El('#import-options'), importQueuedFiles);
@@ -1322,9 +1323,12 @@
1322
1323
  await importFiles(files);
1323
1324
  }
1324
1325
  } catch(e) {
1325
- console.error(e);
1326
+ gui.alert(e.message, 'Import error');
1327
+ }
1328
+ if (gui.getMode() == 'import') {
1329
+ // Mode could also be 'alert' if an error is thrown and handled
1330
+ gui.clearMode();
1326
1331
  }
1327
- gui.clearMode();
1328
1332
  }
1329
1333
 
1330
1334
  function turnOn() {
@@ -1388,10 +1392,20 @@
1388
1392
  }
1389
1393
 
1390
1394
  async function receiveFiles(files) {
1391
- // TODO: show importing message here?
1392
- var expanded = await expandFiles(files);
1395
+ var expanded = [];
1396
+ try {
1397
+ expanded = await expandFiles(files);
1398
+ } catch(e) {
1399
+ gui.alert(e.message, 'Import error');
1400
+ return;
1401
+ }
1393
1402
  addFilesToQueue(expanded);
1394
- if (queuedFiles.length === 0) return;
1403
+ if (queuedFiles.length === 0) {
1404
+ var names = getFileNames(files);
1405
+ var msg = `Unable to import data from: ${names.join(', ')}`;
1406
+ gui.alert(msg, 'Import error');
1407
+ return;
1408
+ }
1395
1409
  gui.enterMode('import');
1396
1410
  if (useQuickView()) {
1397
1411
  importQueuedFiles();
@@ -1402,6 +1416,10 @@
1402
1416
  }
1403
1417
  }
1404
1418
 
1419
+ function getFileNames(files) {
1420
+ return Array.from(files).map(function(f) {return f.name;});
1421
+ }
1422
+
1405
1423
  async function expandFiles(files) {
1406
1424
  var files2 = [], expanded;
1407
1425
  for (var f of files) {
@@ -1442,6 +1460,19 @@
1442
1460
  gui.session.fileImported(group.filename, optStr);
1443
1461
  }
1444
1462
 
1463
+ function addEmptyLayer() {
1464
+ var dataset = {
1465
+ layers: [{
1466
+ name: 'New layer',
1467
+ geometry_type: 'point',
1468
+ shapes: []
1469
+ }],
1470
+ info: {}
1471
+ };
1472
+ model.addDataset(dataset);
1473
+ gui.clearMode();
1474
+ }
1475
+
1445
1476
  function filesMayContainPaths(files) {
1446
1477
  return utils$1.some(files, function(f) {
1447
1478
  var type = internal.guessInputFileType(f.name);
@@ -1497,16 +1528,6 @@
1497
1528
  }
1498
1529
  }
1499
1530
 
1500
- function handleImportError(e, fileName) {
1501
- var msg = utils$1.isString(e) ? e : e.message;
1502
- if (fileName) {
1503
- msg = "Error importing <i>" + fileName + "</i><br>" + msg;
1504
- }
1505
- clearQueuedFiles();
1506
- gui.alert(msg);
1507
- console.error(e);
1508
- }
1509
-
1510
1531
  function prepFilesForDownload(names) {
1511
1532
  var items = names.map(function(name) {
1512
1533
  var isUrl = /:\/\//.test(name);
@@ -1565,7 +1586,7 @@
1565
1586
  }
1566
1587
 
1567
1588
  async function readZipFile(file) {
1568
- var files;
1589
+ var files = [];
1569
1590
  await wait(35); // pause a beat so status message can display
1570
1591
  try {
1571
1592
  files = await runAsync(GUI.readZipFile, file);
@@ -1575,8 +1596,8 @@
1575
1596
  return !/\.txt$/i.test(f.name);
1576
1597
  });
1577
1598
  } catch(e) {
1578
- handleImportError(e, file.name);
1579
- files = [];
1599
+ console.error(e);
1600
+ throw Error(`Unable to unzip ${file.name}`);
1580
1601
  }
1581
1602
  return files;
1582
1603
  }
@@ -1592,9 +1613,9 @@
1592
1613
  type: internal.guessInputType(file.name, content)
1593
1614
  };
1594
1615
  } catch (e) {
1595
- handleImportError("Web browser was unable to load the file.", file.name);
1616
+ console.error(e);
1617
+ throw Error(`Browser was unable to load the file ${file.name}`);
1596
1618
  }
1597
- return null;
1598
1619
  }
1599
1620
 
1600
1621
  async function readFiles(files) {
@@ -2985,15 +3006,19 @@
2985
3006
  var el;
2986
3007
  gui.addMode('alert', function() {}, turnOff);
2987
3008
 
2988
- gui.alert = function(str) {
2989
- var infoBox;
3009
+ gui.alert = function(str, title) {
3010
+ var infoBox, html = '';
2990
3011
  if (!el) {
2991
3012
  el = El('div').appendTo('body').addClass('error-wrapper');
2992
3013
  infoBox = El('div').appendTo(el).addClass('error-box info-box selectable');
2993
- El('p').addClass('error-message').appendTo(infoBox);
3014
+ El('div').appendTo(infoBox).addClass('error-content');
2994
3015
  El('div').addClass("btn dialog-btn").appendTo(infoBox).html('close').on('click', gui.clearMode);
2995
3016
  }
2996
- el.findChild('.error-message').html(str);
3017
+ if (title) {
3018
+ html += `<div class="error-title">${title}</div>`;
3019
+ }
3020
+ html += `<p class="error-message">${str}</p>`;
3021
+ el.findChild('.error-content').html(html);
2997
3022
  gui.enterMode('alert');
2998
3023
  };
2999
3024
 
package/www/mapshaper.js CHANGED
@@ -1,6 +1,6 @@
1
1
  (function () {
2
2
 
3
- var VERSION = "0.6.11";
3
+ var VERSION = "0.6.12";
4
4
 
5
5
 
6
6
  var utils = /*#__PURE__*/Object.freeze({
@@ -15644,9 +15644,11 @@ ${svg}
15644
15644
  } else if (buf instanceof ArrayBuffer) {
15645
15645
  // we're good
15646
15646
  } else if (typeof B$3 == 'function' && buf instanceof B$3) {
15647
- // Since node 0.10, DataView constructor doesn't accept Buffers,
15648
- // so need to copy Buffer to ArrayBuffer
15649
- buf = BinArray.toArrayBuffer(buf);
15647
+ if (buf.buffer && buf.buffer.byteLength == buf.length) {
15648
+ buf = buf.buffer;
15649
+ } else {
15650
+ buf = BinArray.copyToArrayBuffer(buf);
15651
+ }
15650
15652
  } else {
15651
15653
  error("BinArray constructor takes an integer, ArrayBuffer or Buffer argument");
15652
15654
  }
@@ -15692,7 +15694,7 @@ ${svg}
15692
15694
  return bytes;
15693
15695
  };
15694
15696
 
15695
- BinArray.toArrayBuffer = function(src) {
15697
+ BinArray.copyToArrayBuffer = function(src) {
15696
15698
  var n = src.length,
15697
15699
  dest = new ArrayBuffer(n),
15698
15700
  view = new Uint8Array(dest);
@@ -23497,9 +23499,9 @@ ${svg}
23497
23499
 
23498
23500
  if (!content) {
23499
23501
  reader = new FileReader(filename);
23500
- } else if (content instanceof ArrayBuffer) {
23502
+ } else if (content instanceof ArrayBuffer || content instanceof Buffer) {
23501
23503
  // Web API imports JSON as ArrayBuffer, to support larger files
23502
- if (content.byteLength < 1e7) {
23504
+ if ((content.byteLength || content.length) < 1e7) {
23503
23505
  // content = utils.createBuffer(content).toString();
23504
23506
  content = bufferToString(utils.createBuffer(content));
23505
23507
  } else {
@@ -23524,7 +23526,7 @@ ${svg}
23524
23526
  content = JSON.parse(content); // ~3sec for 100MB string
23525
23527
  } catch(e) {
23526
23528
  // stop("Unable to parse JSON");
23527
- stop('JSON parsing error --', e.message);
23529
+ stop('JSON parsing error:', e.message);
23528
23530
  }
23529
23531
  }
23530
23532
  if (opts.json_path) {
@@ -23816,9 +23818,6 @@ ${svg}
23816
23818
  }
23817
23819
  // TODO: consider using a temp file, to support incremental reading
23818
23820
  content = require('zlib').gunzipSync(cli.readFile(pathgz));
23819
- if (fileType == 'json' || fileType == 'text') {
23820
- content = trimBOM(decodeString(content, encoding || 'utf-8'));
23821
- }
23822
23821
 
23823
23822
  } else { // type can't be inferred from filename -- try reading as text
23824
23823
  content = cli.readFile(path, encoding || 'utf-8', cache);
package/www/page.css CHANGED
@@ -251,6 +251,11 @@ body {
251
251
  left: 0;
252
252
  }
253
253
 
254
+ .error-title {
255
+ font-weight: bold;
256
+ margin-bottom: 4px;
257
+ }
258
+
254
259
  div.error-box {
255
260
  margin-top: 55px;
256
261
  overflow: auto;