mapshaper 0.5.73 → 0.5.74
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 +4 -0
- package/package.json +1 -1
- package/www/mapshaper-gui.js +70 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
v0.5.74
|
|
2
|
+
* Added support for importing data in the GUI by pasting JSON and delimited text onto the browser window.
|
|
3
|
+
* Sped up drawing shapes in the GUI.
|
|
4
|
+
|
|
1
5
|
v0.5.73
|
|
2
6
|
* Added this.geojson getter/setter to -each expressions. This can be used in combination with -require to transform the geometry of individual features using an external script.
|
|
3
7
|
|
package/package.json
CHANGED
package/www/mapshaper-gui.js
CHANGED
|
@@ -1107,7 +1107,8 @@
|
|
|
1107
1107
|
var area = El(el);
|
|
1108
1108
|
area.on('dragleave', ondragleave)
|
|
1109
1109
|
.on('dragover', ondragover)
|
|
1110
|
-
.on('drop', ondrop)
|
|
1110
|
+
.on('drop', ondrop)
|
|
1111
|
+
.on('paste', onpaste);
|
|
1111
1112
|
function ondragleave(e) {
|
|
1112
1113
|
block(e);
|
|
1113
1114
|
out();
|
|
@@ -1128,12 +1129,39 @@
|
|
|
1128
1129
|
function out() {
|
|
1129
1130
|
area.removeClass('dragover');
|
|
1130
1131
|
}
|
|
1132
|
+
function onpaste(e) {
|
|
1133
|
+
var text, file;
|
|
1134
|
+
block(e);
|
|
1135
|
+
try {
|
|
1136
|
+
text = e.clipboardData.getData('text/plain').trim();
|
|
1137
|
+
file = text ? pastedTextToFile(text) : null;
|
|
1138
|
+
if (file) {
|
|
1139
|
+
cb([file]);
|
|
1140
|
+
}
|
|
1141
|
+
} catch(err) {
|
|
1142
|
+
console.error(err);
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1131
1145
|
function block(e) {
|
|
1132
1146
|
e.preventDefault();
|
|
1133
1147
|
e.stopPropagation();
|
|
1134
1148
|
}
|
|
1135
1149
|
}
|
|
1136
1150
|
|
|
1151
|
+
function pastedTextToFile(str) {
|
|
1152
|
+
var type = internal.guessInputContentType(str);
|
|
1153
|
+
var name;
|
|
1154
|
+
if (type == 'text') {
|
|
1155
|
+
name = 'pasted.txt';
|
|
1156
|
+
} else if (type == 'json') {
|
|
1157
|
+
name = 'pasted.json';
|
|
1158
|
+
} else {
|
|
1159
|
+
return null;
|
|
1160
|
+
}
|
|
1161
|
+
var blob = new Blob([str]);
|
|
1162
|
+
return new File([blob], name);
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1137
1165
|
// @el DOM element for select button
|
|
1138
1166
|
// @cb function(<FileList>)
|
|
1139
1167
|
function FileChooser(el, cb) {
|
|
@@ -9880,9 +9908,6 @@
|
|
|
9880
9908
|
|
|
9881
9909
|
utils$1.inherit(MapExtent, EventDispatcher);
|
|
9882
9910
|
|
|
9883
|
-
var MIN_ARC_LEN = 0.1;
|
|
9884
|
-
var MIN_PATH_LEN = 0.1;
|
|
9885
|
-
|
|
9886
9911
|
// TODO: consider moving this upstream
|
|
9887
9912
|
function getArcsForRendering(obj, ext) {
|
|
9888
9913
|
var dataset = obj.source.dataset;
|
|
@@ -9942,6 +9967,7 @@
|
|
|
9942
9967
|
|
|
9943
9968
|
// Return a function for testing if an arc should be drawn in the current view
|
|
9944
9969
|
function getArcFilter(arcs, ext, usedFlag, arcCounts) {
|
|
9970
|
+
var MIN_PATH_LEN = 0.1;
|
|
9945
9971
|
var minPathLen = ext.getPixelSize() * MIN_PATH_LEN, // * 0.5
|
|
9946
9972
|
geoBounds = ext.getBounds(),
|
|
9947
9973
|
geoBBox = geoBounds.toArray(),
|
|
@@ -10194,7 +10220,8 @@
|
|
|
10194
10220
|
startPath(ctx, style);
|
|
10195
10221
|
}
|
|
10196
10222
|
iter = protectIterForDrawing(arcs.getArcIter(i), _ext);
|
|
10197
|
-
drawPath(iter, t, ctx,
|
|
10223
|
+
// drawPath(iter, t, ctx, 0.1);
|
|
10224
|
+
drawPath2(iter, t, ctx, roundToHalfPix);
|
|
10198
10225
|
}
|
|
10199
10226
|
endPath(ctx, style);
|
|
10200
10227
|
};
|
|
@@ -10281,6 +10308,9 @@
|
|
|
10281
10308
|
}
|
|
10282
10309
|
}
|
|
10283
10310
|
|
|
10311
|
+
// Draw a path, but skip vertices within a given pixel threshold from the prev. vertex
|
|
10312
|
+
// This optimization introduces visible gaps between filled polygons unless the
|
|
10313
|
+
// threshold is much smaller than a pixel, so switching to drawPath2.
|
|
10284
10314
|
function drawPath(vec, t, ctx, minLen) {
|
|
10285
10315
|
// copy to local variables because of odd performance regression in Chrome 80
|
|
10286
10316
|
var mx = t.mx,
|
|
@@ -10289,7 +10319,6 @@
|
|
|
10289
10319
|
by = t.by;
|
|
10290
10320
|
var x, y, xp, yp;
|
|
10291
10321
|
if (!vec.hasNext()) return;
|
|
10292
|
-
minLen = utils$1.isNonNegNumber(minLen) ? minLen : 0.4;
|
|
10293
10322
|
x = xp = vec.x * mx + bx;
|
|
10294
10323
|
y = yp = vec.y * my + by;
|
|
10295
10324
|
ctx.moveTo(x, y);
|
|
@@ -10304,6 +10333,39 @@
|
|
|
10304
10333
|
}
|
|
10305
10334
|
}
|
|
10306
10335
|
|
|
10336
|
+
|
|
10337
|
+
// Draw a path, optimized by snapping pixel coordinates and skipping
|
|
10338
|
+
// duplicate coords.
|
|
10339
|
+
function drawPath2(vec, t, ctx, round) {
|
|
10340
|
+
// copy to local variables because of odd performance regression in Chrome 80
|
|
10341
|
+
var mx = t.mx,
|
|
10342
|
+
my = t.my,
|
|
10343
|
+
bx = t.bx,
|
|
10344
|
+
by = t.by;
|
|
10345
|
+
var x, y, xp, yp;
|
|
10346
|
+
if (!vec.hasNext()) return;
|
|
10347
|
+
x = xp = round(vec.x * mx + bx);
|
|
10348
|
+
y = yp = round(vec.y * my + by);
|
|
10349
|
+
ctx.moveTo(x, y);
|
|
10350
|
+
while (vec.hasNext()) {
|
|
10351
|
+
x = round(vec.x * mx + bx);
|
|
10352
|
+
y = round(vec.y * my + by);
|
|
10353
|
+
if (x != xp || y != yp) {
|
|
10354
|
+
ctx.lineTo(x, y);
|
|
10355
|
+
xp = x;
|
|
10356
|
+
yp = y;
|
|
10357
|
+
}
|
|
10358
|
+
}
|
|
10359
|
+
}
|
|
10360
|
+
|
|
10361
|
+
function roundToPix(x) {
|
|
10362
|
+
return x + 0.5 | 0;
|
|
10363
|
+
}
|
|
10364
|
+
|
|
10365
|
+
function roundToHalfPix(x) {
|
|
10366
|
+
return (x * 2 | 0) / 2;
|
|
10367
|
+
}
|
|
10368
|
+
|
|
10307
10369
|
function getShapePencil(arcs, ext) {
|
|
10308
10370
|
var t = getScaledTransform(ext);
|
|
10309
10371
|
var iter = new internal.ShapeIter(arcs);
|
|
@@ -10311,7 +10373,8 @@
|
|
|
10311
10373
|
for (var i=0, n=shp ? shp.length : 0; i<n; i++) {
|
|
10312
10374
|
iter.init(shp[i]);
|
|
10313
10375
|
// 0.2 trades visible seams for performance
|
|
10314
|
-
drawPath(protectIterForDrawing(iter, ext), t, ctx, 0.2);
|
|
10376
|
+
// drawPath(protectIterForDrawing(iter, ext), t, ctx, 0.2);
|
|
10377
|
+
drawPath2(protectIterForDrawing(iter, ext), t, ctx, roundToPix);
|
|
10315
10378
|
}
|
|
10316
10379
|
};
|
|
10317
10380
|
}
|