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 +119 -16
- package/package.json +2 -2
- package/www/index.html +6 -1
- package/www/mapshaper-gui.js +6746 -9956
- package/www/mapshaper.js +119 -16
- package/www/page.css +643 -16
package/www/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
|
-
|
|
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
|
-
|
|
18972
|
-
if (d
|
|
18973
|
-
|
|
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
|
|
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
|
-
}
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
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.
|
|
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.
|