mapshaper 0.6.94 → 0.6.95

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
@@ -236,8 +236,7 @@
236
236
  if (!obj) return false;
237
237
  if (isArray(obj)) return true;
238
238
  if (isString(obj)) return false;
239
- if (obj.length === 0) return true;
240
- if (obj.length > 0) return true;
239
+ if (obj.length === 0 || obj.length > 0) return true;
241
240
  return false;
242
241
  }
243
242
 
@@ -28103,9 +28102,9 @@ ${svg}
28103
28102
  var BUFLEN = 1e7; // buffer chunk size
28104
28103
  var MAX_STRLEN = 5e6; // max byte len of a value string (object keys are shorter)
28105
28104
 
28106
- // Parse from a Buffer -- similar to JSON.parse(), used for testing
28107
- function parse(buf) {
28108
- var reader = new BufferReader(buf);
28105
+ // Parse from a Buffer or FileReader
28106
+ function parseJSON(arg) {
28107
+ var reader = isArrayLike(arg) ? new BufferReader(arg) : arg;
28109
28108
  var src = ByteReader(reader, 0);
28110
28109
  skipWS(src);
28111
28110
  var val = readValue(src);
@@ -28116,11 +28115,18 @@ ${svg}
28116
28115
  return val;
28117
28116
  }
28118
28117
 
28119
- // parse data from:
28120
- // * FeatureCollection
28121
- // * GeometryCollection
28122
- // * Single Feature or Geometry
28123
- // * WS-delimited sequence of Features or geometries
28118
+ // Parse data from:
28119
+ // * FeatureCollection
28120
+ // * GeometryCollection
28121
+ // * Single Feature or Geometry
28122
+ // * WS-delimited sequence of Features or geometries
28123
+ //
28124
+ // reader: FileReader or compatible reader
28125
+ // cb: callback function, called once for each parsed Feature or bare geometry
28126
+ //
28127
+ // Returns:
28128
+ // * collections - top-level object with features/geometries array set to null
28129
+ // * others - null
28124
28130
  //
28125
28131
  function parseGeoJSON(reader, cb) {
28126
28132
  var src = ByteReader(reader, 0);
@@ -28145,6 +28151,7 @@ ${svg}
28145
28151
  return null;
28146
28152
  }
28147
28153
 
28154
+
28148
28155
  function parseError(msg, i) {
28149
28156
  if (i >= 0) {
28150
28157
  msg += ' at position ' + i;
@@ -28596,19 +28603,6 @@ ${svg}
28596
28603
  }
28597
28604
  }
28598
28605
 
28599
- // Read GeoJSON Features or geometry objects from a file
28600
- // @reader: a FileReader
28601
- function GeoJSONReader(reader) {
28602
-
28603
- this.readObjects = function(onObject) {
28604
- T$1.start();
28605
- var val = parseGeoJSON(reader, onObject);
28606
- // var val = parseGeoJSON_native(reader, onObject);
28607
- debug('Parse GeoJSON', T$1.stop());
28608
- return val;
28609
- };
28610
- }
28611
-
28612
28606
  // Identify JSON type from the initial subset of a JSON string
28613
28607
  function identifyJSONString(str, opts) {
28614
28608
  var maxChars = 1000;
@@ -28642,7 +28636,7 @@ ${svg}
28642
28636
 
28643
28637
  function importGeoJSONFile(fileReader, opts) {
28644
28638
  var importer = new GeoJSONParser(opts);
28645
- new GeoJSONReader(fileReader).readObjects(importer.parseObject);
28639
+ parseGeoJSON(fileReader, importer.parseObject);
28646
28640
  // TODO: examine top-level objects, like crs
28647
28641
  return importer.done();
28648
28642
  }
@@ -45678,7 +45672,7 @@ ${svg}
45678
45672
  });
45679
45673
  }
45680
45674
 
45681
- var version = "0.6.94";
45675
+ var version = "0.6.95";
45682
45676
 
45683
45677
  // Parse command line args into commands and run them
45684
45678
  // Function takes an optional Node-style callback. A Promise is returned if no callback is given.
@@ -46310,8 +46304,8 @@ ${svg}
46310
46304
  Dbf,
46311
46305
  DbfReader,
46312
46306
  DouglasPeucker,
46313
- geojson: GeoJSON,
46314
- json: { parse: parse },
46307
+ parseGeoJSON,
46308
+ json: { parse: parseJSON },
46315
46309
  ShpType,
46316
46310
  topojson: TopoJSON,
46317
46311
  Visvalingam,
@@ -46321,7 +46315,6 @@ ${svg}
46321
46315
  CommandParser,
46322
46316
  DataTable,
46323
46317
  editArcs,
46324
- GeoJSONReader,
46325
46318
  Heap,
46326
46319
  IdLookupIndex,
46327
46320
  NodeCollection,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mapshaper",
3
- "version": "0.6.94",
3
+ "version": "0.6.95",
4
4
  "description": "A tool for editing vector datasets for mapping and GIS.",
5
5
  "keywords": [
6
6
  "shapefile",
@@ -3707,7 +3707,13 @@
3707
3707
  // init simplify button and mode
3708
3708
  gui.addMode('simplify', turnOn, turnOff, menuBtn);
3709
3709
 
3710
- model.on('update', function() {
3710
+ model.on('update', function(e) {
3711
+ // exit simplify mode if data has been changed from outside the simplify
3712
+ // tool
3713
+ // (TODO: try to only respond to changes that might affect simplification)
3714
+ if (e.flags.simplify_method || e.flags.simplify_amount) {
3715
+ return;
3716
+ }
3711
3717
  menuBtn.classed('disabled', !model.getActiveLayer());
3712
3718
  if (gui.getMode() == 'simplify') gui.clearMode();
3713
3719
  });
@@ -5890,7 +5896,7 @@
5890
5896
 
5891
5897
  var menus = {
5892
5898
  standard: ['info', 'selection', 'box'],
5893
- empty: ['edit_points', 'edit_lines', 'edit_polygons', 'box'],
5899
+ empty: ['edit_polygons', 'edit_lines', 'edit_points', 'box'],
5894
5900
  polygons: ['info', 'selection', 'box', 'edit_polygons'],
5895
5901
  rectangles: ['info', 'selection', 'box', 'rectangles', 'edit_polygons'],
5896
5902
  lines: ['info', 'selection', 'box' , 'edit_lines'],
@@ -5908,11 +5914,11 @@
5908
5914
  // mode name -> menu text lookup
5909
5915
  var labels = {
5910
5916
  info: 'inspect features',
5911
- box: 'shift-drag box tool',
5917
+ box: 'rectangle tool',
5912
5918
  data: 'edit attributes',
5913
5919
  labels: 'position labels',
5914
- edit_points: 'draw/edit points',
5915
- edit_lines: 'draw/edit lines',
5920
+ edit_points: 'add/edit points',
5921
+ edit_lines: 'draw/edit polylines',
5916
5922
  edit_polygons: 'draw/edit polygons',
5917
5923
  vertices: 'edit vertices',
5918
5924
  selection: 'selection tool',
@@ -6531,8 +6537,7 @@
6531
6537
  if (!obj) return false;
6532
6538
  if (isArray(obj)) return true;
6533
6539
  if (isString(obj)) return false;
6534
- if (obj.length === 0) return true;
6535
- if (obj.length > 0) return true;
6540
+ if (obj.length === 0 || obj.length > 0) return true;
6536
6541
  return false;
6537
6542
  }
6538
6543
 
@@ -8830,12 +8835,12 @@
8830
8835
  element.addEventListener('mousedown', onAreaDown);
8831
8836
  element.addEventListener('dblclick', onAreaDblClick);
8832
8837
  document.addEventListener('contextmenu', function(e) {
8833
- if (!e.ctrlKey) {
8838
+ if (!(e.ctrlKey && e.altKey)) {
8834
8839
  e.preventDefault();
8835
8840
  }
8836
8841
  });
8837
8842
  element.addEventListener('contextmenu', function(e) {
8838
- if (!e.ctrlKey) {
8843
+ if (!(e.ctrlKey && e.altKey)) {
8839
8844
  _self.dispatchEvent('contextmenu', procMouseEvent(e));
8840
8845
  }
8841
8846
  });
@@ -12142,6 +12147,8 @@
12142
12147
  var popup = gui.container.findChild('.box-tool-options');
12143
12148
  var coords = popup.findChild('.box-coords');
12144
12149
  var _on = false;
12150
+ var instructionsShown = false;
12151
+ var alert;
12145
12152
 
12146
12153
  var infoBtn = new SimpleButton(popup.findChild('.info-btn')).on('click', function() {
12147
12154
  if (coords.visible()) hideCoords(); else showCoords();
@@ -12188,6 +12195,10 @@
12188
12195
  gui.on('interaction_mode_change', function(e) {
12189
12196
  if (e.mode === 'box') {
12190
12197
  gui.enterMode('box_tool');
12198
+ if (!instructionsShown) {
12199
+ instructionsShown = true;
12200
+ showInstructions();
12201
+ }
12191
12202
  } else if (_on) {
12192
12203
  turnOff();
12193
12204
  }
@@ -12198,7 +12209,10 @@
12198
12209
  });
12199
12210
 
12200
12211
  box.on('dragend', function(e) {
12201
- if (_on) popup.show();
12212
+ if (_on) {
12213
+ hideInstructions();
12214
+ popup.show();
12215
+ }
12202
12216
  });
12203
12217
 
12204
12218
  box.on('handle_drag', function() {
@@ -12207,6 +12221,19 @@
12207
12221
  }
12208
12222
  });
12209
12223
 
12224
+ function showInstructions() {
12225
+ var isMac = navigator.userAgent.includes('Mac');
12226
+ var symbol = isMac ? '⌘' : '^';
12227
+ var msg = `Instructions: Shift-drag to draw a rectangle. Drag handles to resize. Shift-drag handles to resize symmetrically.`;
12228
+ alert = showPopupAlert(msg, null, { non_blocking: true, max_width: '360px'});
12229
+ }
12230
+
12231
+ function hideInstructions() {
12232
+ if (!alert) return;
12233
+ alert.close('fade');
12234
+ alert = null;
12235
+ }
12236
+
12210
12237
  function inZoomMode() {
12211
12238
  return !_on && gui.getMode() != 'selection_tool';
12212
12239
  }
@@ -12242,6 +12269,7 @@
12242
12269
 
12243
12270
  function turnOff() {
12244
12271
  box.turnOff();
12272
+ hideInstructions();
12245
12273
  if (gui.interaction.getMode() == 'box') {
12246
12274
  // mode change was not initiated by interactive menu -- turn off interactivity
12247
12275
  gui.interaction.turnOff();
package/www/mapshaper.js CHANGED
@@ -236,8 +236,7 @@
236
236
  if (!obj) return false;
237
237
  if (isArray(obj)) return true;
238
238
  if (isString(obj)) return false;
239
- if (obj.length === 0) return true;
240
- if (obj.length > 0) return true;
239
+ if (obj.length === 0 || obj.length > 0) return true;
241
240
  return false;
242
241
  }
243
242
 
@@ -28103,9 +28102,9 @@ ${svg}
28103
28102
  var BUFLEN = 1e7; // buffer chunk size
28104
28103
  var MAX_STRLEN = 5e6; // max byte len of a value string (object keys are shorter)
28105
28104
 
28106
- // Parse from a Buffer -- similar to JSON.parse(), used for testing
28107
- function parse(buf) {
28108
- var reader = new BufferReader(buf);
28105
+ // Parse from a Buffer or FileReader
28106
+ function parseJSON(arg) {
28107
+ var reader = isArrayLike(arg) ? new BufferReader(arg) : arg;
28109
28108
  var src = ByteReader(reader, 0);
28110
28109
  skipWS(src);
28111
28110
  var val = readValue(src);
@@ -28116,11 +28115,18 @@ ${svg}
28116
28115
  return val;
28117
28116
  }
28118
28117
 
28119
- // parse data from:
28120
- // * FeatureCollection
28121
- // * GeometryCollection
28122
- // * Single Feature or Geometry
28123
- // * WS-delimited sequence of Features or geometries
28118
+ // Parse data from:
28119
+ // * FeatureCollection
28120
+ // * GeometryCollection
28121
+ // * Single Feature or Geometry
28122
+ // * WS-delimited sequence of Features or geometries
28123
+ //
28124
+ // reader: FileReader or compatible reader
28125
+ // cb: callback function, called once for each parsed Feature or bare geometry
28126
+ //
28127
+ // Returns:
28128
+ // * collections - top-level object with features/geometries array set to null
28129
+ // * others - null
28124
28130
  //
28125
28131
  function parseGeoJSON(reader, cb) {
28126
28132
  var src = ByteReader(reader, 0);
@@ -28145,6 +28151,7 @@ ${svg}
28145
28151
  return null;
28146
28152
  }
28147
28153
 
28154
+
28148
28155
  function parseError(msg, i) {
28149
28156
  if (i >= 0) {
28150
28157
  msg += ' at position ' + i;
@@ -28596,19 +28603,6 @@ ${svg}
28596
28603
  }
28597
28604
  }
28598
28605
 
28599
- // Read GeoJSON Features or geometry objects from a file
28600
- // @reader: a FileReader
28601
- function GeoJSONReader(reader) {
28602
-
28603
- this.readObjects = function(onObject) {
28604
- T$1.start();
28605
- var val = parseGeoJSON(reader, onObject);
28606
- // var val = parseGeoJSON_native(reader, onObject);
28607
- debug('Parse GeoJSON', T$1.stop());
28608
- return val;
28609
- };
28610
- }
28611
-
28612
28606
  // Identify JSON type from the initial subset of a JSON string
28613
28607
  function identifyJSONString(str, opts) {
28614
28608
  var maxChars = 1000;
@@ -28642,7 +28636,7 @@ ${svg}
28642
28636
 
28643
28637
  function importGeoJSONFile(fileReader, opts) {
28644
28638
  var importer = new GeoJSONParser(opts);
28645
- new GeoJSONReader(fileReader).readObjects(importer.parseObject);
28639
+ parseGeoJSON(fileReader, importer.parseObject);
28646
28640
  // TODO: examine top-level objects, like crs
28647
28641
  return importer.done();
28648
28642
  }
@@ -45678,7 +45672,7 @@ ${svg}
45678
45672
  });
45679
45673
  }
45680
45674
 
45681
- var version = "0.6.94";
45675
+ var version = "0.6.95";
45682
45676
 
45683
45677
  // Parse command line args into commands and run them
45684
45678
  // Function takes an optional Node-style callback. A Promise is returned if no callback is given.
@@ -46310,8 +46304,8 @@ ${svg}
46310
46304
  Dbf,
46311
46305
  DbfReader,
46312
46306
  DouglasPeucker,
46313
- geojson: GeoJSON,
46314
- json: { parse: parse },
46307
+ parseGeoJSON,
46308
+ json: { parse: parseJSON },
46315
46309
  ShpType,
46316
46310
  topojson: TopoJSON,
46317
46311
  Visvalingam,
@@ -46321,7 +46315,6 @@ ${svg}
46321
46315
  CommandParser,
46322
46316
  DataTable,
46323
46317
  editArcs,
46324
- GeoJSONReader,
46325
46318
  Heap,
46326
46319
  IdLookupIndex,
46327
46320
  NodeCollection,