mapshaper 0.6.100 → 0.6.101

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
@@ -18516,18 +18516,19 @@
18516
18516
 
18517
18517
  function calcFrameData(dataset, opts) {
18518
18518
  var bounds;
18519
- if (opts.svg_bbox) {
18520
- bounds = new Bounds(opts.svg_bbox);
18519
+ var outputBbox = opts.svg_bbox || opts.output_bbox || null;
18520
+ if (outputBbox) {
18521
+ bounds = new Bounds(outputBbox);
18521
18522
  opts = Object.assign({margin: 0}, opts); // prevent default pixel margin around content
18522
18523
  } else {
18523
18524
  bounds = getDatasetBounds(dataset);
18524
18525
  }
18525
- var pixBounds = calcOutputSizeInPixels(bounds, opts);
18526
+ var outputBounds = calcOutputSizeInPixels(bounds, opts);
18526
18527
  return {
18527
18528
  bbox: bounds.toArray(),
18528
- bbox2: pixBounds.toArray(),
18529
- width: Math.round(pixBounds.width()),
18530
- height: Math.round(pixBounds.height()) || 1,
18529
+ bbox2: outputBounds.toArray(),
18530
+ width: Math.round(outputBounds.width()),
18531
+ height: Math.round(outputBounds.height()) || 1,
18531
18532
  type: 'frame'
18532
18533
  };
18533
18534
  }
@@ -18709,6 +18710,7 @@
18709
18710
  __proto__: null,
18710
18711
  getFrameData: getFrameData,
18711
18712
  getFrameLayerData: getFrameLayerData,
18713
+ calcFrameData: calcFrameData,
18712
18714
  getFrameSize: getFrameSize,
18713
18715
  isFrameLayer: isFrameLayer,
18714
18716
  findFrameLayerInDataset: findFrameLayerInDataset,
@@ -18772,6 +18774,9 @@
18772
18774
  geometry_type: 'point', shapes: targetPoints}, {geometry_type: 'polyline',
18773
18775
  shapes: targetShapes}]}, opts);
18774
18776
  transform = getAffineTransform(rotateArg, scaleArg, shiftArg, anchorArg);
18777
+ if (opts.fit_bbox) {
18778
+ transform = getFitBoxTransform(opts.fit_bbox, targetPoints, targetShapes, arcs);
18779
+ }
18775
18780
  if (targetShapes.length > 0) {
18776
18781
  targetFlags = new Uint8Array(arcs.size());
18777
18782
  otherFlags = new Uint8Array(arcs.size());
@@ -18821,6 +18826,33 @@
18821
18826
  };
18822
18827
  }
18823
18828
 
18829
+ function getFitBoxTransform(bbox, points, shapes, arcs) {
18830
+ var dataset = {
18831
+ arcs: arcs,
18832
+ info: {},
18833
+ layers: []
18834
+ };
18835
+ if (points && points.length) {
18836
+ dataset.layers.push({
18837
+ geometry_type: 'point',
18838
+ shapes: points
18839
+ });
18840
+ }
18841
+ if (shapes && shapes.length) {
18842
+ dataset.layers.push({
18843
+ geometry_type: 'polyline',
18844
+ shapes: shapes
18845
+ });
18846
+ }
18847
+ var frame = calcFrameData(dataset, {fit_bbox: bbox});
18848
+ var fromBounds = new Bounds(frame.bbox);
18849
+ var toBounds = new Bounds(frame.bbox2);
18850
+ var fwd = fromBounds.getTransform(toBounds, false);
18851
+ return function(x, y) {
18852
+ return fwd.transform(x, y);
18853
+ };
18854
+ }
18855
+
18824
18856
  function applyArrayMask(destArr, maskArr) {
18825
18857
  for (var i=0, n=destArr.length; i<n; i++) {
18826
18858
  if (maskArr[i] === 0) destArr[i] = 0;
@@ -24609,6 +24641,10 @@ ${svg}
24609
24641
  type: 'numbers',
24610
24642
  describe: 'center of rotation/scaling (default is center of selected shapes)'
24611
24643
  })
24644
+ .option('fit-bbox', {
24645
+ type: 'bbox',
24646
+ describe: 'scale and shift coordinates to fit a bbox'
24647
+ })
24612
24648
  .option('where', whereOpt)
24613
24649
  .option('target', targetOpt);
24614
24650
 
@@ -44521,6 +44557,7 @@ ${svg}
44521
44557
  if (!size) return null;
44522
44558
  var stemLen = size.stemLen,
44523
44559
  headLen = size.headLen,
44560
+ totalLen = stickArrow ? Math.max(stemLen, headLen) : stemLen + headLen,
44524
44561
  headDx = size.headWidth / 2,
44525
44562
  stemDx = size.stemWidth / 2,
44526
44563
  baseDx = stemDx * (1 - stemTaper),
@@ -44573,11 +44610,10 @@ ${svg}
44573
44610
  }
44574
44611
 
44575
44612
  if (d.anchor == 'end') {
44576
- scaleAndShiftCoords(coords, 1, [-dx, -dy - headLen]);
44613
+ scaleAndShiftCoords(coords, 1, [-dx, -totalLen]);
44577
44614
  } else if (d.anchor == 'middle') {
44578
44615
  // shift midpoint away from the head a bit for a more balanced placement
44579
- // scaleAndShiftCoords(coords, 1, [-dx/2, (-dy - headLen)/2]);
44580
- scaleAndShiftCoords(coords, 1, [-dx * 0.5, -dy * 0.5 - headLen * 0.25]);
44616
+ scaleAndShiftCoords(coords, 1, [-dx * 0.5, -dy * 0.5 - totalLen * 0.25]);
44581
44617
  }
44582
44618
 
44583
44619
  rotateCoords(coords, direction);
@@ -44594,15 +44630,16 @@ ${svg}
44594
44630
 
44595
44631
  function calcArrowSize(d, stickArrow) {
44596
44632
  // don't display arrows with negative length
44597
- var totalLen = Math.max(d.radius || d.length || d.r || 0, 0),
44598
- scale = 1,
44599
- o = initArrowSize(d); // calc several parameters
44633
+ var o = initArrowSize(d), // calc several parameters
44634
+ dataLen = Math.max(d.radius || d.length || d.r || 0),
44635
+ totalLen = Math.max(dataLen, o.headLen, 0),
44636
+ scale = 1;
44600
44637
  if (totalLen >= 0) {
44601
44638
  scale = calcScale(totalLen, o.headLen, d);
44602
44639
  o.stemWidth *= scale;
44603
44640
  o.headWidth *= scale;
44604
44641
  o.headLen *= scale;
44605
- o.stemLen = stickArrow ? totalLen : totalLen - o.headLen;
44642
+ o.stemLen = stickArrow ? dataLen : totalLen - o.headLen;
44606
44643
  }
44607
44644
 
44608
44645
  if (o.headWidth < o.stemWidth && o.headWidth > 0) {
@@ -44651,13 +44688,11 @@ ${svg}
44651
44688
  return o;
44652
44689
  }
44653
44690
 
44654
-
44655
44691
  // Returns ratio of head length to head width
44656
44692
  function getHeadSizeRatio(headAngle) {
44657
44693
  return 1 / Math.tan(Math.PI * headAngle / 180 / 2) / 2;
44658
44694
  }
44659
44695
 
44660
-
44661
44696
  // ax, ay: point on the base
44662
44697
  // bx, by: point on the stem
44663
44698
  function getCurvedStemCoords(ax, ay, bx, by) {
@@ -45870,7 +45905,7 @@ ${svg}
45870
45905
  });
45871
45906
  }
45872
45907
 
45873
- var version = "0.6.100";
45908
+ var version = "0.6.101";
45874
45909
 
45875
45910
  // Parse command line args into commands and run them
45876
45911
  // Function takes an optional Node-style callback. A Promise is returned if no callback is given.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mapshaper",
3
- "version": "0.6.100",
3
+ "version": "0.6.101",
4
4
  "description": "A tool for editing vector datasets for mapping and GIS.",
5
5
  "keywords": [
6
6
  "shapefile",
package/www/mapshaper.js CHANGED
@@ -18516,18 +18516,19 @@
18516
18516
 
18517
18517
  function calcFrameData(dataset, opts) {
18518
18518
  var bounds;
18519
- if (opts.svg_bbox) {
18520
- bounds = new Bounds(opts.svg_bbox);
18519
+ var outputBbox = opts.svg_bbox || opts.output_bbox || null;
18520
+ if (outputBbox) {
18521
+ bounds = new Bounds(outputBbox);
18521
18522
  opts = Object.assign({margin: 0}, opts); // prevent default pixel margin around content
18522
18523
  } else {
18523
18524
  bounds = getDatasetBounds(dataset);
18524
18525
  }
18525
- var pixBounds = calcOutputSizeInPixels(bounds, opts);
18526
+ var outputBounds = calcOutputSizeInPixels(bounds, opts);
18526
18527
  return {
18527
18528
  bbox: bounds.toArray(),
18528
- bbox2: pixBounds.toArray(),
18529
- width: Math.round(pixBounds.width()),
18530
- height: Math.round(pixBounds.height()) || 1,
18529
+ bbox2: outputBounds.toArray(),
18530
+ width: Math.round(outputBounds.width()),
18531
+ height: Math.round(outputBounds.height()) || 1,
18531
18532
  type: 'frame'
18532
18533
  };
18533
18534
  }
@@ -18709,6 +18710,7 @@
18709
18710
  __proto__: null,
18710
18711
  getFrameData: getFrameData,
18711
18712
  getFrameLayerData: getFrameLayerData,
18713
+ calcFrameData: calcFrameData,
18712
18714
  getFrameSize: getFrameSize,
18713
18715
  isFrameLayer: isFrameLayer,
18714
18716
  findFrameLayerInDataset: findFrameLayerInDataset,
@@ -18772,6 +18774,9 @@
18772
18774
  geometry_type: 'point', shapes: targetPoints}, {geometry_type: 'polyline',
18773
18775
  shapes: targetShapes}]}, opts);
18774
18776
  transform = getAffineTransform(rotateArg, scaleArg, shiftArg, anchorArg);
18777
+ if (opts.fit_bbox) {
18778
+ transform = getFitBoxTransform(opts.fit_bbox, targetPoints, targetShapes, arcs);
18779
+ }
18775
18780
  if (targetShapes.length > 0) {
18776
18781
  targetFlags = new Uint8Array(arcs.size());
18777
18782
  otherFlags = new Uint8Array(arcs.size());
@@ -18821,6 +18826,33 @@
18821
18826
  };
18822
18827
  }
18823
18828
 
18829
+ function getFitBoxTransform(bbox, points, shapes, arcs) {
18830
+ var dataset = {
18831
+ arcs: arcs,
18832
+ info: {},
18833
+ layers: []
18834
+ };
18835
+ if (points && points.length) {
18836
+ dataset.layers.push({
18837
+ geometry_type: 'point',
18838
+ shapes: points
18839
+ });
18840
+ }
18841
+ if (shapes && shapes.length) {
18842
+ dataset.layers.push({
18843
+ geometry_type: 'polyline',
18844
+ shapes: shapes
18845
+ });
18846
+ }
18847
+ var frame = calcFrameData(dataset, {fit_bbox: bbox});
18848
+ var fromBounds = new Bounds(frame.bbox);
18849
+ var toBounds = new Bounds(frame.bbox2);
18850
+ var fwd = fromBounds.getTransform(toBounds, false);
18851
+ return function(x, y) {
18852
+ return fwd.transform(x, y);
18853
+ };
18854
+ }
18855
+
18824
18856
  function applyArrayMask(destArr, maskArr) {
18825
18857
  for (var i=0, n=destArr.length; i<n; i++) {
18826
18858
  if (maskArr[i] === 0) destArr[i] = 0;
@@ -24609,6 +24641,10 @@ ${svg}
24609
24641
  type: 'numbers',
24610
24642
  describe: 'center of rotation/scaling (default is center of selected shapes)'
24611
24643
  })
24644
+ .option('fit-bbox', {
24645
+ type: 'bbox',
24646
+ describe: 'scale and shift coordinates to fit a bbox'
24647
+ })
24612
24648
  .option('where', whereOpt)
24613
24649
  .option('target', targetOpt);
24614
24650
 
@@ -44521,6 +44557,7 @@ ${svg}
44521
44557
  if (!size) return null;
44522
44558
  var stemLen = size.stemLen,
44523
44559
  headLen = size.headLen,
44560
+ totalLen = stickArrow ? Math.max(stemLen, headLen) : stemLen + headLen,
44524
44561
  headDx = size.headWidth / 2,
44525
44562
  stemDx = size.stemWidth / 2,
44526
44563
  baseDx = stemDx * (1 - stemTaper),
@@ -44573,11 +44610,10 @@ ${svg}
44573
44610
  }
44574
44611
 
44575
44612
  if (d.anchor == 'end') {
44576
- scaleAndShiftCoords(coords, 1, [-dx, -dy - headLen]);
44613
+ scaleAndShiftCoords(coords, 1, [-dx, -totalLen]);
44577
44614
  } else if (d.anchor == 'middle') {
44578
44615
  // shift midpoint away from the head a bit for a more balanced placement
44579
- // scaleAndShiftCoords(coords, 1, [-dx/2, (-dy - headLen)/2]);
44580
- scaleAndShiftCoords(coords, 1, [-dx * 0.5, -dy * 0.5 - headLen * 0.25]);
44616
+ scaleAndShiftCoords(coords, 1, [-dx * 0.5, -dy * 0.5 - totalLen * 0.25]);
44581
44617
  }
44582
44618
 
44583
44619
  rotateCoords(coords, direction);
@@ -44594,15 +44630,16 @@ ${svg}
44594
44630
 
44595
44631
  function calcArrowSize(d, stickArrow) {
44596
44632
  // don't display arrows with negative length
44597
- var totalLen = Math.max(d.radius || d.length || d.r || 0, 0),
44598
- scale = 1,
44599
- o = initArrowSize(d); // calc several parameters
44633
+ var o = initArrowSize(d), // calc several parameters
44634
+ dataLen = Math.max(d.radius || d.length || d.r || 0),
44635
+ totalLen = Math.max(dataLen, o.headLen, 0),
44636
+ scale = 1;
44600
44637
  if (totalLen >= 0) {
44601
44638
  scale = calcScale(totalLen, o.headLen, d);
44602
44639
  o.stemWidth *= scale;
44603
44640
  o.headWidth *= scale;
44604
44641
  o.headLen *= scale;
44605
- o.stemLen = stickArrow ? totalLen : totalLen - o.headLen;
44642
+ o.stemLen = stickArrow ? dataLen : totalLen - o.headLen;
44606
44643
  }
44607
44644
 
44608
44645
  if (o.headWidth < o.stemWidth && o.headWidth > 0) {
@@ -44651,13 +44688,11 @@ ${svg}
44651
44688
  return o;
44652
44689
  }
44653
44690
 
44654
-
44655
44691
  // Returns ratio of head length to head width
44656
44692
  function getHeadSizeRatio(headAngle) {
44657
44693
  return 1 / Math.tan(Math.PI * headAngle / 180 / 2) / 2;
44658
44694
  }
44659
44695
 
44660
-
44661
44696
  // ax, ay: point on the base
44662
44697
  // bx, by: point on the stem
44663
44698
  function getCurvedStemCoords(ax, ay, bx, by) {
@@ -45870,7 +45905,7 @@ ${svg}
45870
45905
  });
45871
45906
  }
45872
45907
 
45873
- var version = "0.6.100";
45908
+ var version = "0.6.101";
45874
45909
 
45875
45910
  // Parse command line args into commands and run them
45876
45911
  // Function takes an optional Node-style callback. A Promise is returned if no callback is given.