mapshaper 0.5.81 → 0.5.82

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/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ v0.5.82
2
+ * More options for arrow styling.
3
+
1
4
  v0.5.81
2
5
  * Bug fixes
3
6
 
package/mapshaper.js CHANGED
@@ -2359,6 +2359,12 @@
2359
2359
  }, 0);
2360
2360
  }
2361
2361
 
2362
+ // export function getEllipsoidalShapeArea(shp, arcs, crs) {
2363
+ // return (shp || []).reduce(function(area, ids) {
2364
+ // return area + getEllipsoidalPathArea(ids, arcs, crs);
2365
+ // }, 0);
2366
+ // }
2367
+
2362
2368
  // Return true if point is inside or on boundary of a shape
2363
2369
  //
2364
2370
  function testPointInPolygon(x, y, shp, arcs) {
@@ -13699,6 +13705,8 @@
13699
13705
  'arrow-stem-width': 'number',
13700
13706
  'arrow-stem-curve': 'number', // degrees of arc
13701
13707
  'arrow-stem-taper': 'number',
13708
+ 'arrow-stem-length': 'number',
13709
+ 'arrow-head-length': 'number',
13702
13710
  'arrow-min-stem': 'number',
13703
13711
  'arrow-scaling': 'number',
13704
13712
  effect: null // e.g. "fade"
@@ -20096,9 +20104,18 @@ ${svg}
20096
20104
  .option('arrow-head-width', {
20097
20105
  describe: 'size of arrow head from side to side'
20098
20106
  })
20107
+ .option('arrow-head-length', {
20108
+ describe: 'length of arrow head (alternative to arrow-head-angle)'
20109
+ })
20110
+ .option('arrow-head-shape', {
20111
+ // describe: 'options: a b c'
20112
+ })
20099
20113
  .option('arrow-stem-width', {
20100
20114
  describe: 'width of stem at its widest point'
20101
20115
  })
20116
+ .option('arrow-stem-length', {
20117
+ describe: 'alternative to arrow-length'
20118
+ })
20102
20119
  .option('arrow-stem-taper', {
20103
20120
  describe: 'factor for tapering the width of the stem'
20104
20121
  })
@@ -37929,47 +37946,63 @@ ${svg}
37929
37946
  points.push(p2);
37930
37947
  }
37931
37948
 
37932
- function getStickArrowCoords(d, totalLen) {
37933
- var minStemRatio = getMinStemRatio(d);
37934
- var headAngle = d['arrow-head-angle'] || 90;
37935
- var curve = d['arrow-stem-curve'] || 0;
37936
- var unscaledHeadWidth = d['arrow-head-width'] || 9;
37937
- var unscaledHeadLen = getHeadLength(unscaledHeadWidth, headAngle);
37938
- var scale = getScale(totalLen, unscaledHeadLen, minStemRatio);
37939
- var headWidth = unscaledHeadWidth * scale;
37940
- var headLen = unscaledHeadLen * scale;
37941
- var tip = getStickArrowTip(totalLen, curve);
37942
- var stem = [[0, 0], tip.concat()];
37943
- if (curve) {
37944
- addBezierArcControlPoints(stem, curve);
37945
- }
37946
- if (!headLen) return [stem];
37947
- var head = [addPoints([-headWidth / 2, -headLen], tip), tip.concat(), addPoints([headWidth / 2, -headLen], tip)];
37949
+ // export function getStickArrowCoords(d, totalLen) {
37950
+ // var minStemRatio = getMinStemRatio(d);
37951
+ // var headAngle = d['arrow-head-angle'] || 90;
37952
+ // var curve = d['arrow-stem-curve'] || 0;
37953
+ // var unscaledHeadWidth = d['arrow-head-width'] || 9;
37954
+ // var unscaledHeadLen = getHeadLength(unscaledHeadWidth, headAngle);
37955
+ // var scale = getScale(totalLen, unscaledHeadLen, minStemRatio);
37956
+ // var headWidth = unscaledHeadWidth * scale;
37957
+ // var headLen = unscaledHeadLen * scale;
37958
+ // var tip = getStickArrowTip(totalLen, curve);
37959
+ // var stem = [[0, 0], tip.concat()];
37960
+ // if (curve) {
37961
+ // addBezierArcControlPoints(stem, curve);
37962
+ // }
37963
+ // if (!headLen) return [stem];
37964
+ // var head = [addPoints([-headWidth / 2, -headLen], tip), tip.concat(), addPoints([headWidth / 2, -headLen], tip)];
37948
37965
 
37949
- rotateCoords(stem, d.rotation);
37950
- rotateCoords(head, d.rotation);
37951
- return [stem, head];
37952
- }
37966
+ // rotateCoords(stem, d.rotation);
37967
+ // rotateCoords(head, d.rotation);
37968
+ // return [stem, head];
37969
+ // }
37953
37970
 
37954
37971
  function getMinStemRatio(d) {
37955
37972
  return d['arrow-min-stem'] >= 0 ? d['arrow-min-stem'] : 0.4;
37956
37973
  }
37957
37974
 
37958
- function getFilledArrowCoords(totalLen, d) {
37959
- var minStemRatio = getMinStemRatio(d),
37960
- headAngle = d['arrow-head-angle'] || 40,
37975
+ function getFilledArrowCoords(d) {
37976
+ var totalLen = d['arrow-length'] || d.radius || d.length || d.r || 0,
37961
37977
  direction = d.rotation || d['arrow-direction'] || 0,
37962
37978
  unscaledStemWidth = d['arrow-stem-width'] || 2,
37963
37979
  unscaledHeadWidth = d['arrow-head-width'] || unscaledStemWidth * 3,
37964
- unscaledHeadLen = getHeadLength(unscaledHeadWidth, headAngle),
37965
- scale = getScale(totalLen, unscaledHeadLen, minStemRatio),
37966
- headWidth = unscaledHeadWidth * scale,
37967
- headLen = unscaledHeadLen * scale,
37968
- stemWidth = unscaledStemWidth * scale,
37980
+ unscaledHeadLen = getHeadLength(unscaledHeadWidth, d),
37969
37981
  stemTaper = d['arrow-stem-taper'] || 0,
37970
- stemCurve = d['arrow-stem-curve'] || 0,
37971
- stemLen = totalLen - headLen,
37972
- coords;
37982
+ stemCurve = d['arrow-stem-curve'] || 0;
37983
+
37984
+ var headLen, headWidth, stemLen, stemWidth;
37985
+
37986
+ var scale = 1;
37987
+
37988
+ if (totalLen > 0) {
37989
+ scale = getScale(totalLen, unscaledHeadLen, getMinStemRatio(d));
37990
+ headWidth = unscaledHeadWidth * scale;
37991
+ headLen = unscaledHeadLen * scale;
37992
+ stemWidth = unscaledStemWidth * scale;
37993
+ stemLen = totalLen - headLen;
37994
+
37995
+ } else {
37996
+ headWidth = unscaledHeadWidth;
37997
+ headLen = unscaledHeadLen;
37998
+ stemWidth = unscaledStemWidth;
37999
+ stemLen = d['arrow-stem-length'] || 0;
38000
+ totalLen = headLen + stemLen;
38001
+ }
38002
+
38003
+ if (totalLen > 0 === false) return null;
38004
+
38005
+ var coords;
37973
38006
 
37974
38007
  var headDx = headWidth / 2,
37975
38008
  stemDx = stemWidth / 2,
@@ -38001,20 +38034,23 @@ ${svg}
38001
38034
  return 1;
38002
38035
  }
38003
38036
 
38004
- function getStickArrowTip(totalLen, curve) {
38005
- // curve/2 intersects the arrowhead at 90deg (trigonometry)
38006
- var theta = Math.abs(curve/2) / 180 * Math.PI;
38007
- var dx = totalLen * Math.sin(theta) * (curve > 0 ? -1 : 1);
38008
- var dy = totalLen * Math.cos(theta);
38009
- return [dx, dy];
38010
- }
38037
+ // function getStickArrowTip(totalLen, curve) {
38038
+ // // curve/2 intersects the arrowhead at 90deg (trigonometry)
38039
+ // var theta = Math.abs(curve/2) / 180 * Math.PI;
38040
+ // var dx = totalLen * Math.sin(theta) * (curve > 0 ? -1 : 1);
38041
+ // var dy = totalLen * Math.cos(theta);
38042
+ // return [dx, dy];
38043
+ // }
38011
38044
 
38012
38045
  function addPoints(a, b) {
38013
38046
  return [a[0] + b[0], a[1] + b[1]];
38014
38047
  }
38015
38048
 
38016
38049
 
38017
- function getHeadLength(headWidth, headAngle) {
38050
+ function getHeadLength(headWidth, d) {
38051
+ var headLength = d['arrow-head-length'];
38052
+ if (headLength > 0) return headLength;
38053
+ var headAngle = d['arrow-head-angle'] || 40;
38018
38054
  var headRatio = 1 / Math.tan(Math.PI * headAngle / 180 / 2) / 2; // length-to-width head ratio
38019
38055
  return headWidth * headRatio;
38020
38056
  }
@@ -38073,7 +38109,9 @@ ${svg}
38073
38109
  // sides: e.g. 5-pointed star has 10 sides
38074
38110
  // radius: distance from center to point
38075
38111
  //
38076
- function getPolygonCoords(radius, opts) {
38112
+ function getPolygonCoords(opts) {
38113
+ var radius = opts.radius || opts.length || opts.r;
38114
+ if (radius > 0 === false) return null;
38077
38115
  var type = opts.type;
38078
38116
  var sides = +opts.sides || getDefaultSides(type);
38079
38117
  var isStar = type == 'star';
@@ -38133,16 +38171,13 @@ ${svg}
38133
38171
  if (!shp) return null;
38134
38172
  var d = getSymbolData(i);
38135
38173
  var rec = records[i] || {};
38136
- var coords, size, constructor;
38174
+ var coords;
38137
38175
  if (d.type == 'arrow') {
38138
- size = d.radius || d.length || d['arrow-length'] || d.r;
38139
- constructor = getFilledArrowCoords;
38176
+ coords = getFilledArrowCoords(d);
38140
38177
  } else {
38141
- size = d.radius || d.length || d.r;
38142
- constructor = getPolygonCoords;
38178
+ coords = getPolygonCoords(d);
38143
38179
  }
38144
- if (size > 0 === false) return null;
38145
- coords = constructor(size, d, opts);
38180
+ if (!coords) return null;
38146
38181
  rotateCoords(coords, +d.rotation || 0);
38147
38182
  if (!polygonMode) {
38148
38183
  flipY(coords);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mapshaper",
3
- "version": "0.5.81",
3
+ "version": "0.5.82",
4
4
  "description": "A tool for editing vector datasets for mapping and GIS.",
5
5
  "keywords": [
6
6
  "shapefile",
package/www/mapshaper.js CHANGED
@@ -2359,6 +2359,12 @@
2359
2359
  }, 0);
2360
2360
  }
2361
2361
 
2362
+ // export function getEllipsoidalShapeArea(shp, arcs, crs) {
2363
+ // return (shp || []).reduce(function(area, ids) {
2364
+ // return area + getEllipsoidalPathArea(ids, arcs, crs);
2365
+ // }, 0);
2366
+ // }
2367
+
2362
2368
  // Return true if point is inside or on boundary of a shape
2363
2369
  //
2364
2370
  function testPointInPolygon(x, y, shp, arcs) {
@@ -13699,6 +13705,8 @@
13699
13705
  'arrow-stem-width': 'number',
13700
13706
  'arrow-stem-curve': 'number', // degrees of arc
13701
13707
  'arrow-stem-taper': 'number',
13708
+ 'arrow-stem-length': 'number',
13709
+ 'arrow-head-length': 'number',
13702
13710
  'arrow-min-stem': 'number',
13703
13711
  'arrow-scaling': 'number',
13704
13712
  effect: null // e.g. "fade"
@@ -20096,9 +20104,18 @@ ${svg}
20096
20104
  .option('arrow-head-width', {
20097
20105
  describe: 'size of arrow head from side to side'
20098
20106
  })
20107
+ .option('arrow-head-length', {
20108
+ describe: 'length of arrow head (alternative to arrow-head-angle)'
20109
+ })
20110
+ .option('arrow-head-shape', {
20111
+ // describe: 'options: a b c'
20112
+ })
20099
20113
  .option('arrow-stem-width', {
20100
20114
  describe: 'width of stem at its widest point'
20101
20115
  })
20116
+ .option('arrow-stem-length', {
20117
+ describe: 'alternative to arrow-length'
20118
+ })
20102
20119
  .option('arrow-stem-taper', {
20103
20120
  describe: 'factor for tapering the width of the stem'
20104
20121
  })
@@ -37929,47 +37946,63 @@ ${svg}
37929
37946
  points.push(p2);
37930
37947
  }
37931
37948
 
37932
- function getStickArrowCoords(d, totalLen) {
37933
- var minStemRatio = getMinStemRatio(d);
37934
- var headAngle = d['arrow-head-angle'] || 90;
37935
- var curve = d['arrow-stem-curve'] || 0;
37936
- var unscaledHeadWidth = d['arrow-head-width'] || 9;
37937
- var unscaledHeadLen = getHeadLength(unscaledHeadWidth, headAngle);
37938
- var scale = getScale(totalLen, unscaledHeadLen, minStemRatio);
37939
- var headWidth = unscaledHeadWidth * scale;
37940
- var headLen = unscaledHeadLen * scale;
37941
- var tip = getStickArrowTip(totalLen, curve);
37942
- var stem = [[0, 0], tip.concat()];
37943
- if (curve) {
37944
- addBezierArcControlPoints(stem, curve);
37945
- }
37946
- if (!headLen) return [stem];
37947
- var head = [addPoints([-headWidth / 2, -headLen], tip), tip.concat(), addPoints([headWidth / 2, -headLen], tip)];
37949
+ // export function getStickArrowCoords(d, totalLen) {
37950
+ // var minStemRatio = getMinStemRatio(d);
37951
+ // var headAngle = d['arrow-head-angle'] || 90;
37952
+ // var curve = d['arrow-stem-curve'] || 0;
37953
+ // var unscaledHeadWidth = d['arrow-head-width'] || 9;
37954
+ // var unscaledHeadLen = getHeadLength(unscaledHeadWidth, headAngle);
37955
+ // var scale = getScale(totalLen, unscaledHeadLen, minStemRatio);
37956
+ // var headWidth = unscaledHeadWidth * scale;
37957
+ // var headLen = unscaledHeadLen * scale;
37958
+ // var tip = getStickArrowTip(totalLen, curve);
37959
+ // var stem = [[0, 0], tip.concat()];
37960
+ // if (curve) {
37961
+ // addBezierArcControlPoints(stem, curve);
37962
+ // }
37963
+ // if (!headLen) return [stem];
37964
+ // var head = [addPoints([-headWidth / 2, -headLen], tip), tip.concat(), addPoints([headWidth / 2, -headLen], tip)];
37948
37965
 
37949
- rotateCoords(stem, d.rotation);
37950
- rotateCoords(head, d.rotation);
37951
- return [stem, head];
37952
- }
37966
+ // rotateCoords(stem, d.rotation);
37967
+ // rotateCoords(head, d.rotation);
37968
+ // return [stem, head];
37969
+ // }
37953
37970
 
37954
37971
  function getMinStemRatio(d) {
37955
37972
  return d['arrow-min-stem'] >= 0 ? d['arrow-min-stem'] : 0.4;
37956
37973
  }
37957
37974
 
37958
- function getFilledArrowCoords(totalLen, d) {
37959
- var minStemRatio = getMinStemRatio(d),
37960
- headAngle = d['arrow-head-angle'] || 40,
37975
+ function getFilledArrowCoords(d) {
37976
+ var totalLen = d['arrow-length'] || d.radius || d.length || d.r || 0,
37961
37977
  direction = d.rotation || d['arrow-direction'] || 0,
37962
37978
  unscaledStemWidth = d['arrow-stem-width'] || 2,
37963
37979
  unscaledHeadWidth = d['arrow-head-width'] || unscaledStemWidth * 3,
37964
- unscaledHeadLen = getHeadLength(unscaledHeadWidth, headAngle),
37965
- scale = getScale(totalLen, unscaledHeadLen, minStemRatio),
37966
- headWidth = unscaledHeadWidth * scale,
37967
- headLen = unscaledHeadLen * scale,
37968
- stemWidth = unscaledStemWidth * scale,
37980
+ unscaledHeadLen = getHeadLength(unscaledHeadWidth, d),
37969
37981
  stemTaper = d['arrow-stem-taper'] || 0,
37970
- stemCurve = d['arrow-stem-curve'] || 0,
37971
- stemLen = totalLen - headLen,
37972
- coords;
37982
+ stemCurve = d['arrow-stem-curve'] || 0;
37983
+
37984
+ var headLen, headWidth, stemLen, stemWidth;
37985
+
37986
+ var scale = 1;
37987
+
37988
+ if (totalLen > 0) {
37989
+ scale = getScale(totalLen, unscaledHeadLen, getMinStemRatio(d));
37990
+ headWidth = unscaledHeadWidth * scale;
37991
+ headLen = unscaledHeadLen * scale;
37992
+ stemWidth = unscaledStemWidth * scale;
37993
+ stemLen = totalLen - headLen;
37994
+
37995
+ } else {
37996
+ headWidth = unscaledHeadWidth;
37997
+ headLen = unscaledHeadLen;
37998
+ stemWidth = unscaledStemWidth;
37999
+ stemLen = d['arrow-stem-length'] || 0;
38000
+ totalLen = headLen + stemLen;
38001
+ }
38002
+
38003
+ if (totalLen > 0 === false) return null;
38004
+
38005
+ var coords;
37973
38006
 
37974
38007
  var headDx = headWidth / 2,
37975
38008
  stemDx = stemWidth / 2,
@@ -38001,20 +38034,23 @@ ${svg}
38001
38034
  return 1;
38002
38035
  }
38003
38036
 
38004
- function getStickArrowTip(totalLen, curve) {
38005
- // curve/2 intersects the arrowhead at 90deg (trigonometry)
38006
- var theta = Math.abs(curve/2) / 180 * Math.PI;
38007
- var dx = totalLen * Math.sin(theta) * (curve > 0 ? -1 : 1);
38008
- var dy = totalLen * Math.cos(theta);
38009
- return [dx, dy];
38010
- }
38037
+ // function getStickArrowTip(totalLen, curve) {
38038
+ // // curve/2 intersects the arrowhead at 90deg (trigonometry)
38039
+ // var theta = Math.abs(curve/2) / 180 * Math.PI;
38040
+ // var dx = totalLen * Math.sin(theta) * (curve > 0 ? -1 : 1);
38041
+ // var dy = totalLen * Math.cos(theta);
38042
+ // return [dx, dy];
38043
+ // }
38011
38044
 
38012
38045
  function addPoints(a, b) {
38013
38046
  return [a[0] + b[0], a[1] + b[1]];
38014
38047
  }
38015
38048
 
38016
38049
 
38017
- function getHeadLength(headWidth, headAngle) {
38050
+ function getHeadLength(headWidth, d) {
38051
+ var headLength = d['arrow-head-length'];
38052
+ if (headLength > 0) return headLength;
38053
+ var headAngle = d['arrow-head-angle'] || 40;
38018
38054
  var headRatio = 1 / Math.tan(Math.PI * headAngle / 180 / 2) / 2; // length-to-width head ratio
38019
38055
  return headWidth * headRatio;
38020
38056
  }
@@ -38073,7 +38109,9 @@ ${svg}
38073
38109
  // sides: e.g. 5-pointed star has 10 sides
38074
38110
  // radius: distance from center to point
38075
38111
  //
38076
- function getPolygonCoords(radius, opts) {
38112
+ function getPolygonCoords(opts) {
38113
+ var radius = opts.radius || opts.length || opts.r;
38114
+ if (radius > 0 === false) return null;
38077
38115
  var type = opts.type;
38078
38116
  var sides = +opts.sides || getDefaultSides(type);
38079
38117
  var isStar = type == 'star';
@@ -38133,16 +38171,13 @@ ${svg}
38133
38171
  if (!shp) return null;
38134
38172
  var d = getSymbolData(i);
38135
38173
  var rec = records[i] || {};
38136
- var coords, size, constructor;
38174
+ var coords;
38137
38175
  if (d.type == 'arrow') {
38138
- size = d.radius || d.length || d['arrow-length'] || d.r;
38139
- constructor = getFilledArrowCoords;
38176
+ coords = getFilledArrowCoords(d);
38140
38177
  } else {
38141
- size = d.radius || d.length || d.r;
38142
- constructor = getPolygonCoords;
38178
+ coords = getPolygonCoords(d);
38143
38179
  }
38144
- if (size > 0 === false) return null;
38145
- coords = constructor(size, d, opts);
38180
+ if (!coords) return null;
38146
38181
  rotateCoords(coords, +d.rotation || 0);
38147
38182
  if (!polygonMode) {
38148
38183
  flipY(coords);