mapshaper 0.7.16 → 0.7.18

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
@@ -18595,6 +18595,7 @@
18595
18595
  icon: null,
18596
18596
  'icon-color': 'color',
18597
18597
  'icon-size': 'number',
18598
+ 'label-pos': 'labelposition',
18598
18599
  'label-text': null, // leaving this null
18599
18600
  'letter-spacing': 'measure',
18600
18601
  'line-height': 'measure',
@@ -18646,6 +18647,20 @@
18646
18647
  'fill,font-family,font-size,text-anchor,font-weight,font-style,font-stretch,letter-spacing,dominant-baseline'.split(',')))
18647
18648
  };
18648
18649
 
18650
+ var labelPositionFields = ['label-pos', 'dx', 'dy', 'text-anchor'];
18651
+
18652
+ var labelPositionStyles = {
18653
+ n: {dx: 0, dy: '-0.5em', 'text-anchor': 'middle'},
18654
+ s: {dx: 0, dy: '1.1em', 'text-anchor': 'middle'},
18655
+ e: {dx: '0.45em', dy: '0.23em', 'text-anchor': 'start'},
18656
+ w: {dx: '-0.45em', dy: '0.23em', 'text-anchor': 'end'},
18657
+ ne: {dx: '0.4em', dy: '-0.15em', 'text-anchor': 'start'},
18658
+ se: {dx: '0.4em', dy: '0.7em', 'text-anchor': 'start'},
18659
+ nw: {dx: '-0.4em', dy: '-0.15em', 'text-anchor': 'end'},
18660
+ sw: {dx: '-0.4em', dy: '0.7em', 'text-anchor': 'end'},
18661
+ c: {dx: 0, dy: '0.25em', 'text-anchor': 'middle'}
18662
+ };
18663
+
18649
18664
  // symType: point, polygon, polyline, label
18650
18665
  function applyStyleAttributes(svgObj, symType, rec, filter) {
18651
18666
  var fields = findStylePropertiesBySymbolGeom(Object.keys(rec || {}), symType);
@@ -18777,6 +18792,8 @@
18777
18792
  val = parseBoolean(strVal);
18778
18793
  } else if (type == 'inlinecss') {
18779
18794
  val = strVal; // TODO: validate
18795
+ } else if (type == 'labelposition') {
18796
+ val = parseLabelPosition(strVal);
18780
18797
  }
18781
18798
  // else {
18782
18799
  // // unknown type -- assume literal value
@@ -18808,6 +18825,26 @@
18808
18825
  return null;
18809
18826
  }
18810
18827
 
18828
+ function parseLabelPosition(str) {
18829
+ var pos = String(str).trim();
18830
+ return /^(n|s|e|w|ne|se|nw|sw|c)$/i.test(pos) ? pos : null;
18831
+ }
18832
+
18833
+ function getLabelPositionStyle(pos) {
18834
+ pos = parseLabelPosition(pos);
18835
+ if (!pos) return null;
18836
+ return Object.assign({'label-pos': pos}, labelPositionStyles[pos.toLowerCase()]);
18837
+ }
18838
+
18839
+ function setLabelPositionStyle(rec, pos) {
18840
+ var style = getLabelPositionStyle(pos);
18841
+ if (!style) return false;
18842
+ labelPositionFields.forEach(function(field) {
18843
+ rec[field] = style[field];
18844
+ });
18845
+ return true;
18846
+ }
18847
+
18811
18848
  function isSvgMeasure(o) {
18812
18849
  return utils.isFiniteNumber(o) || utils.isString(o) && /^-?[.0-9]+[a-z]*$/.test(o);
18813
18850
  }
@@ -18826,6 +18863,7 @@
18826
18863
  __proto__: null,
18827
18864
  applyStyleAttributes: applyStyleAttributes,
18828
18865
  findStylePropertiesBySymbolGeom: findStylePropertiesBySymbolGeom,
18866
+ getLabelPositionStyle: getLabelPositionStyle,
18829
18867
  getSymbolDataAccessor: getSymbolDataAccessor,
18830
18868
  getSymbolPropertyAccessor: getSymbolPropertyAccessor,
18831
18869
  isSupportedSvgStyleProperty: isSupportedSvgStyleProperty,
@@ -18833,9 +18871,12 @@
18833
18871
  isSvgColor: isSvgColor,
18834
18872
  isSvgMeasure: isSvgMeasure,
18835
18873
  isSvgNumber: isSvgNumber,
18874
+ labelPositionFields: labelPositionFields,
18836
18875
  mightBeExpression: mightBeExpression,
18837
18876
  parseBoolean: parseBoolean,
18838
- parseSvgMeasure: parseSvgMeasure
18877
+ parseLabelPosition: parseLabelPosition,
18878
+ parseSvgMeasure: parseSvgMeasure,
18879
+ setLabelPositionStyle: setLabelPositionStyle
18839
18880
  });
18840
18881
 
18841
18882
  function toLabelString(val) {
@@ -18957,7 +18998,7 @@
18957
18998
 
18958
18999
  function renderIcon(d) {
18959
19000
  var type = d.icon || 'circle';
18960
- var r = getIconRadius(d);
19001
+ var r = getIconRadius(d, type);
18961
19002
  if (r > 0 === false) return empty();
18962
19003
  if (type == 'circle') return circle(getIconStyleData(d, r));
18963
19004
  if (type == 'square') return square(getIconStyleData(d, r), 0, 0);
@@ -18967,10 +19008,18 @@
18967
19008
  return empty();
18968
19009
  }
18969
19010
 
18970
- function getIconRadius(d) {
18971
- if (d['icon-size'] > 0) return d['icon-size'] / 2;
18972
- if (d.r > 0) return d.r;
18973
- return 5;
19011
+ function getIconRadius(d, type) {
19012
+ var size;
19013
+ if (d['icon-size'] > 0 === false) {
19014
+ return d.r > 0 ? d.r : 5;
19015
+ }
19016
+ size = d['icon-size'];
19017
+ if (type == 'circle' || type == 'ring') {
19018
+ size -= 1;
19019
+ } else if (type == 'star') {
19020
+ size += 1;
19021
+ }
19022
+ return size / 2;
18974
19023
  }
18975
19024
 
18976
19025
  function getIconStyleData(d, r) {
@@ -31618,6 +31667,10 @@ ${svg}
31618
31667
  type: 'flag'
31619
31668
  })
31620
31669
  .option('where', whereOpt)
31670
+ .option('ids', {
31671
+ describe: 'comma-sep. list of feature ids to style',
31672
+ type: 'numbers'
31673
+ })
31621
31674
  .option('class', {
31622
31675
  describe: 'name of CSS class or classes (space-separated)'
31623
31676
  })
@@ -31669,6 +31722,9 @@ ${svg}
31669
31722
  .option('label-text', {
31670
31723
  describe: 'label text (set this to export points as labels)'
31671
31724
  })
31725
+ .option('label-pos', {
31726
+ describe: 'label position; one of: n, s, e, w, ne, se, nw, sw, c'
31727
+ })
31672
31728
  .option('text-anchor', {
31673
31729
  describe: 'label alignment; one of: start, end, middle (default)'
31674
31730
  })
@@ -44025,7 +44081,17 @@ ${svg}
44025
44081
  return utils.pickOne(schemes) || 'Tableau20';
44026
44082
  }
44027
44083
 
44028
- function getCategoricalColorScheme(name, n) {
44084
+ function randomRotateArr(arr) {
44085
+ var n = Math.floor(Math.random() * arr.length);
44086
+ return arr.slice(-n).concat(arr.slice(0, -n));
44087
+ }
44088
+
44089
+ function getRandomizedCategoricalColorScheme(n) {
44090
+ var name = pickRandomCategoricalScheme(n);
44091
+ return getCategoricalColorScheme(name, n, true);
44092
+ }
44093
+
44094
+ function getCategoricalColorScheme(name, n, randomized) {
44029
44095
  var colors;
44030
44096
  initSchemes();
44031
44097
  name = standardName(name);
@@ -44040,7 +44106,11 @@ ${svg}
44040
44106
  // stop(name, 'does not contain', n, 'colors');
44041
44107
  message('Color scheme has', colors.length, 'colors. Using duplication to match', n, 'categories.');
44042
44108
  colors = wrapColors(colors, n);
44043
- } else {
44109
+ }
44110
+ if (randomized) {
44111
+ colors = randomRotateArr(colors);
44112
+ }
44113
+ if (n < colors.length) {
44044
44114
  colors = colors.slice(0, n);
44045
44115
  }
44046
44116
  return colors;
@@ -44131,7 +44201,7 @@ ${svg}
44131
44201
 
44132
44202
  if (colorArg == 'random') {
44133
44203
  if (categorical) {
44134
- colorScheme = pickRandomCategoricalScheme(n);
44204
+ return getRandomizedCategoricalColorScheme(n);
44135
44205
  } else {
44136
44206
  colorScheme = pickRandomColorScheme('sequential');
44137
44207
  }
@@ -56645,13 +56715,14 @@ ${svg}
56645
56715
  if (opts.where) {
56646
56716
  filterFn = compileFeatureExpression(opts.where, lyr, dataset.arcs);
56647
56717
  }
56718
+ if (opts.ids) {
56719
+ filterFn = combineFilters(filterFn, getIdFilter(opts.ids));
56720
+ }
56648
56721
  if (opts.clear) {
56649
56722
  lyr.data.getFields().filter(isSupportedSvgStyleProperty).forEach(lyr.data.deleteField, lyr.data);
56650
56723
  }
56651
56724
  table = getLayerDataTable(lyr);
56652
- fields = Object.keys(opts).map(function(optName) {
56653
- return optName.replace('_', '-');
56654
- }).filter(isSupportedSvgStyleProperty);
56725
+ fields = getStyleFields(opts);
56655
56726
  hasNewFields = fields.some(function(field) {
56656
56727
  return !table.fieldExists(field);
56657
56728
  });
@@ -56672,11 +56743,14 @@ ${svg}
56672
56743
  table.getRecords().forEach(function(rec, i) {
56673
56744
  if (filterFn && !filterFn(i)) {
56674
56745
  // make sure field exists if record is excluded by filter
56675
- if (svgName in rec === false) {
56676
- rec[svgName] = undefined;
56677
- }
56746
+ setUndefinedFields(rec, svgName == 'label-pos' ? labelPositionFields : [svgName]);
56678
56747
  } else {
56679
56748
  rec[svgName] = accessor(i);
56749
+ if (svgName == 'label-pos') {
56750
+ if (!setLabelPositionStyle(rec, rec['label-pos'])) {
56751
+ stop$1('Unexpected value for label-pos:', rec['label-pos']);
56752
+ }
56753
+ }
56680
56754
  }
56681
56755
  });
56682
56756
  });
@@ -56689,6 +56763,35 @@ ${svg}
56689
56763
  }
56690
56764
  };
56691
56765
 
56766
+ function getStyleFields(opts) {
56767
+ var fields = [];
56768
+ Object.keys(opts).forEach(function(optName) {
56769
+ var svgName = optName.replace('_', '-');
56770
+ if (!isSupportedSvgStyleProperty(svgName)) return;
56771
+ addField(fields, svgName);
56772
+ if (svgName == 'label-pos') {
56773
+ labelPositionFields.forEach(function(field) {
56774
+ addField(fields, field);
56775
+ });
56776
+ }
56777
+ });
56778
+ return fields;
56779
+ }
56780
+
56781
+ function addField(fields, field) {
56782
+ if (fields.indexOf(field) == -1) {
56783
+ fields.push(field);
56784
+ }
56785
+ }
56786
+
56787
+ function setUndefinedFields(rec, fields) {
56788
+ fields.forEach(function(field) {
56789
+ if (field in rec === false) {
56790
+ rec[field] = undefined;
56791
+ }
56792
+ });
56793
+ }
56794
+
56692
56795
  var roundCoord$1 = getRoundingFunction(0.01);
56693
56796
 
56694
56797
  function getSymbolFillColor(d) {
@@ -58166,7 +58269,7 @@ ${svg}
58166
58269
  });
58167
58270
  }
58168
58271
 
58169
- var version = "0.7.16";
58272
+ var version = "0.7.18";
58170
58273
 
58171
58274
  // Parse command line args into commands and run them
58172
58275
  // Function takes an optional Node-style callback. A Promise is returned if no callback is given.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mapshaper",
3
- "version": "0.7.16",
4
- "description": "A tool for editing vector datasets for mapping and GIS.",
3
+ "version": "0.7.18",
4
+ "description": "A tool for editing geospatial data for mapping and GIS.",
5
5
  "keywords": [
6
6
  "shapefile",
7
7
  "topojson",
package/www/index.html CHANGED
@@ -47,6 +47,10 @@
47
47
  </g>
48
48
  </svg>
49
49
 
50
+ <svg id="text-tool-icon" xmlns="http://www.w3.org/2000/svg" width="15" height="22" viewBox="0 0 15 22">
51
+ <path d="M13.4125,6.1758c-.0735,0-.1704.0087-.3023.0225-.35.0418-1.1581.0841-1.6018.0841H3.4416c-.4199,0-1.2035-.0418-1.5848-.0845-.1272-.0133-.2242-.022-.2977-.022-.5733,0-.5733.5104-.5733.678v3.8421h.9614c.8167,0,1.1245-.4428,1.2361-.7083.43-1.0372.9151-1.2196,1.775-1.2196h.6348v9.7486c0,.3918-.0528.4281-.463.7111l-.0919.0634c-.4874.3427-.6362.5765-.6362,1.0014v1.1346h6.1463v-1.1346c0-.4222-.1617-.6753-.6992-1.0441-.435-.3023-.4708-.3266-.4708-.7318v-9.7486h.6353c.8439,0,1.3253.1833,1.7754,1.2205.1851.4428.6307.7074,1.1925.7074h1.0042v-3.8421c0-.1677,0-.678-.5733-.678Z"/>
52
+ </svg>
53
+
50
54
  <!-- adjusted height -->
51
55
  <svg id="pointer-icon" version="1.1" xmlns="http://www.w3.org/2000/svg" width="15" height="22" viewBox="0 0 15 20"><rect x="7.4126" y="11.0354" width="3.9102" height="7.9841" transform="translate(-5.8889 6.0377) rotate(-27.5536)" fill="#30d4ef"/><polygon points="2.57 2.086 2.718 16.056 13.944 10.198 2.57 2.086" fill="#30d4ef"/></svg>
52
56
 
@@ -102,8 +106,9 @@
102
106
  <label class="history-toggle-btn history-menu-item"><input type="checkbox" class="checkbox history-undo-checkbox">enable undo</label>
103
107
  <div class="history-menu-note"></div>
104
108
  <div class="history-clear-btn history-menu-item" role="menuitem">clear undo history</div>
105
- <div class="history-menu-separator"></div>
106
109
  <div class="history-command-log-btn history-menu-item" role="menuitem">view command history</div>
110
+ <div class="history-create-snapshot-btn history-menu-item" role="menuitem">create snapshot</div>
111
+ <div class="history-snapshot-list"></div>
107
112
  </div>
108
113
  </div>
109
114
  </div>