mapshaper 0.5.92 → 0.5.93
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 +111 -19
- package/package.json +1 -1
- package/www/manifest.js +7 -1
- package/www/mapshaper-gui.js +1595 -122
- package/www/mapshaper.js +111 -19
package/mapshaper.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
(function () {
|
|
2
2
|
|
|
3
|
-
var VERSION = "0.5.
|
|
3
|
+
var VERSION = "0.5.92";
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
var utils = /*#__PURE__*/Object.freeze({
|
|
@@ -994,15 +994,23 @@
|
|
|
994
994
|
}
|
|
995
995
|
|
|
996
996
|
function copyElements(src, i, dest, j, n, rev) {
|
|
997
|
-
|
|
997
|
+
var same = src == dest || src.buffer && src.buffer == dest.buffer;
|
|
998
998
|
var inc = 1,
|
|
999
|
-
offs = 0
|
|
999
|
+
offs = 0,
|
|
1000
|
+
k;
|
|
1000
1001
|
if (rev) {
|
|
1002
|
+
if (same) error('copy error');
|
|
1001
1003
|
inc = -1;
|
|
1002
1004
|
offs = n - 1;
|
|
1003
1005
|
}
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
+
if (same && j > i) {
|
|
1007
|
+
for (k=n-1; k>=0; k--) {
|
|
1008
|
+
dest[j + k] = src[i + k];
|
|
1009
|
+
}
|
|
1010
|
+
} else {
|
|
1011
|
+
for (k=0; k<n; k++, offs += inc) {
|
|
1012
|
+
dest[k + j] = src[i + offs];
|
|
1013
|
+
}
|
|
1006
1014
|
}
|
|
1007
1015
|
}
|
|
1008
1016
|
|
|
@@ -1756,6 +1764,69 @@
|
|
|
1756
1764
|
return [xmin, ymin, xmax, ymax];
|
|
1757
1765
|
}
|
|
1758
1766
|
|
|
1767
|
+
function deleteVertex(arcs, i) {
|
|
1768
|
+
var data = arcs.getVertexData();
|
|
1769
|
+
var nn = data.nn;
|
|
1770
|
+
var n = data.xx.length;
|
|
1771
|
+
// avoid re-allocating memory
|
|
1772
|
+
var xx2 = new Float64Array(data.xx.buffer, 0, n-1);
|
|
1773
|
+
var yy2 = new Float64Array(data.yy.buffer, 0, n-1);
|
|
1774
|
+
var count = 0;
|
|
1775
|
+
var found = false;
|
|
1776
|
+
for (var j=0; j<nn.length; j++) {
|
|
1777
|
+
count += nn[j];
|
|
1778
|
+
if (count >= i && !found) { // TODO: confirm this
|
|
1779
|
+
nn[j] = nn[j] - 1;
|
|
1780
|
+
found = true;
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
utils.copyElements(data.xx, 0, xx2, 0, i);
|
|
1784
|
+
utils.copyElements(data.yy, 0, yy2, 0, i);
|
|
1785
|
+
utils.copyElements(data.xx, i+1, xx2, i, n-i-1);
|
|
1786
|
+
utils.copyElements(data.yy, i+1, yy2, i, n-i-1);
|
|
1787
|
+
arcs.updateVertexData(nn, xx2, yy2, null);
|
|
1788
|
+
}
|
|
1789
|
+
|
|
1790
|
+
function insertVertex(arcs, i, p) {
|
|
1791
|
+
// TODO: add extra bytes to the buffers, to reduce new memory allocation
|
|
1792
|
+
var data = arcs.getVertexData();
|
|
1793
|
+
var nn = data.nn;
|
|
1794
|
+
var n = data.xx.length;
|
|
1795
|
+
var count = 0;
|
|
1796
|
+
var found = false;
|
|
1797
|
+
var xx2, yy2;
|
|
1798
|
+
// avoid re-allocating memory on each insertion
|
|
1799
|
+
if (data.xx.buffer.byteLength >= data.xx.length * 8 + 8) {
|
|
1800
|
+
xx2 = new Float64Array(data.xx.buffer, 0, n+1);
|
|
1801
|
+
yy2 = new Float64Array(data.yy.buffer, 0, n+1);
|
|
1802
|
+
} else {
|
|
1803
|
+
xx2 = new Float64Array(new ArrayBuffer((n + 20) * 8), 0, n+1);
|
|
1804
|
+
yy2 = new Float64Array(new ArrayBuffer((n + 20) * 8), 0, n+1);
|
|
1805
|
+
}
|
|
1806
|
+
for (var j=0; j<nn.length; j++) {
|
|
1807
|
+
count += nn[j];
|
|
1808
|
+
if (count >= i && !found) { // TODO: confirm this
|
|
1809
|
+
nn[j] = nn[j] + 1;
|
|
1810
|
+
found = true;
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
utils.copyElements(data.xx, 0, xx2, 0, i);
|
|
1814
|
+
utils.copyElements(data.yy, 0, yy2, 0, i);
|
|
1815
|
+
utils.copyElements(data.xx, i, xx2, i+1, n-i);
|
|
1816
|
+
utils.copyElements(data.yy, i, yy2, i+1, n-i);
|
|
1817
|
+
xx2[i] = p[0];
|
|
1818
|
+
yy2[i] = p[1];
|
|
1819
|
+
arcs.updateVertexData(nn, xx2, yy2, null);
|
|
1820
|
+
}
|
|
1821
|
+
|
|
1822
|
+
var ArcUtils = /*#__PURE__*/Object.freeze({
|
|
1823
|
+
__proto__: null,
|
|
1824
|
+
absArcId: absArcId,
|
|
1825
|
+
calcArcBounds: calcArcBounds,
|
|
1826
|
+
deleteVertex: deleteVertex,
|
|
1827
|
+
insertVertex: insertVertex
|
|
1828
|
+
});
|
|
1829
|
+
|
|
1759
1830
|
var WGS84 = {
|
|
1760
1831
|
// https://en.wikipedia.org/wiki/Earth_radius
|
|
1761
1832
|
SEMIMAJOR_AXIS: 6378137,
|
|
@@ -4922,6 +4993,7 @@
|
|
|
4922
4993
|
this._n = 0;
|
|
4923
4994
|
this.x = 0;
|
|
4924
4995
|
this.y = 0;
|
|
4996
|
+
this.i = -1;
|
|
4925
4997
|
}
|
|
4926
4998
|
|
|
4927
4999
|
ShapeIter.prototype.hasNext = function() {
|
|
@@ -4932,6 +5004,7 @@
|
|
|
4932
5004
|
if (arc.hasNext()) {
|
|
4933
5005
|
this.x = arc.x;
|
|
4934
5006
|
this.y = arc.y;
|
|
5007
|
+
this.i = arc.i;
|
|
4935
5008
|
return true;
|
|
4936
5009
|
}
|
|
4937
5010
|
this.nextArc();
|
|
@@ -5498,6 +5571,8 @@
|
|
|
5498
5571
|
}
|
|
5499
5572
|
};
|
|
5500
5573
|
|
|
5574
|
+
this.isFlat = function() { return !_zz; };
|
|
5575
|
+
|
|
5501
5576
|
this.getRetainedInterval = function() {
|
|
5502
5577
|
return _zlimit;
|
|
5503
5578
|
};
|
|
@@ -23447,7 +23522,16 @@ ${svg}
|
|
|
23447
23522
|
// should be in gui-model.js, moved here for testing
|
|
23448
23523
|
this.getActiveLayer = function() {
|
|
23449
23524
|
var targ = (this.getDefaultTargets() || [])[0];
|
|
23450
|
-
|
|
23525
|
+
// var lyr = targ.layers[0];
|
|
23526
|
+
// Reasons to select the last layer of a multi-layer target:
|
|
23527
|
+
// * This layer was imported last
|
|
23528
|
+
// * This layer is displayed on top of other layers
|
|
23529
|
+
// * This layer is at the top of the layers list
|
|
23530
|
+
// * In TopoJSON input, it makes sense to think of the last object/layer
|
|
23531
|
+
// as the topmost one -- it corresponds to the painter's algorithm and
|
|
23532
|
+
// the way that objects are ordered in SVG.
|
|
23533
|
+
var lyr = targ.layers[targ.layers.length - 1];
|
|
23534
|
+
return targ ? {layer: lyr, dataset: targ.dataset} : null;
|
|
23451
23535
|
};
|
|
23452
23536
|
|
|
23453
23537
|
function layerObject(lyr, dataset) {
|
|
@@ -34968,16 +35052,7 @@ ${svg}
|
|
|
34968
35052
|
return findVertexIds(p2.x, p2.y, arcs);
|
|
34969
35053
|
}
|
|
34970
35054
|
|
|
34971
|
-
// Given a location @p (e.g. corresponding to the mouse pointer location),
|
|
34972
|
-
// find the midpoint of two vertices on @shp suitable for inserting a new vertex,
|
|
34973
|
-
// but only if:
|
|
34974
|
-
// 1. point @p is closer to the midpoint than either adjacent vertex
|
|
34975
|
-
// 2. the segment containing @p is longer than a minimum distance in pixels.
|
|
34976
|
-
//
|
|
34977
|
-
function findInsertionPoint(p, shp, arcs, pixelSize) {
|
|
34978
|
-
var p2 = findNearestVertex(p[0], p[1], shp, arcs);
|
|
34979
35055
|
|
|
34980
|
-
}
|
|
34981
35056
|
|
|
34982
35057
|
function snapVerticesToPoint(ids, p, arcs, final) {
|
|
34983
35058
|
ids.forEach(function(idx) {
|
|
@@ -35058,7 +35133,7 @@ ${svg}
|
|
|
35058
35133
|
function findNearestVertex(x, y, shp, arcs, spherical) {
|
|
35059
35134
|
var calcLen = spherical ? geom.greatCircleDistance : geom.distance2D,
|
|
35060
35135
|
minLen = Infinity,
|
|
35061
|
-
minX, minY, dist, iter;
|
|
35136
|
+
minX, minY, vId, dist, iter;
|
|
35062
35137
|
for (var i=0; i<shp.length; i++) {
|
|
35063
35138
|
iter = arcs.getShapeIter(shp[i]);
|
|
35064
35139
|
while (iter.hasNext()) {
|
|
@@ -35067,16 +35142,31 @@ ${svg}
|
|
|
35067
35142
|
minLen = dist;
|
|
35068
35143
|
minX = iter.x;
|
|
35069
35144
|
minY = iter.y;
|
|
35145
|
+
vId = iter.i;
|
|
35070
35146
|
}
|
|
35071
35147
|
}
|
|
35072
35148
|
}
|
|
35073
|
-
return minLen < Infinity ? {x: minX, y: minY} : null;
|
|
35149
|
+
return minLen < Infinity ? {x: minX, y: minY, i: vId} : null;
|
|
35150
|
+
}
|
|
35151
|
+
|
|
35152
|
+
// v: vertex in {x, y, i} format
|
|
35153
|
+
function findAdjacentVertex(v, shp, arcs, offs) {
|
|
35154
|
+
var p, i;
|
|
35155
|
+
var arcEnd = offs == 1 && vertexIsArcEnd(v.i, arcs);
|
|
35156
|
+
var arcStart = offs == -1 && vertexIsArcStart(v.i, arcs);
|
|
35157
|
+
if (arcEnd || arcStart) return null;
|
|
35158
|
+
i = v.i + offs;
|
|
35159
|
+
p = getVertexCoords(i, arcs);
|
|
35160
|
+
return {
|
|
35161
|
+
i: i,
|
|
35162
|
+
x: p[0],
|
|
35163
|
+
y: p[1]
|
|
35164
|
+
};
|
|
35074
35165
|
}
|
|
35075
35166
|
|
|
35076
35167
|
var VertexUtils = /*#__PURE__*/Object.freeze({
|
|
35077
35168
|
__proto__: null,
|
|
35078
35169
|
findNearestVertices: findNearestVertices,
|
|
35079
|
-
findInsertionPoint: findInsertionPoint,
|
|
35080
35170
|
snapVerticesToPoint: snapVerticesToPoint,
|
|
35081
35171
|
snapPointToArcEndpoint: snapPointToArcEndpoint,
|
|
35082
35172
|
findVertexIds: findVertexIds,
|
|
@@ -35084,7 +35174,8 @@ ${svg}
|
|
|
35084
35174
|
vertexIsArcEnd: vertexIsArcEnd,
|
|
35085
35175
|
vertexIsArcStart: vertexIsArcStart,
|
|
35086
35176
|
setVertexCoords: setVertexCoords,
|
|
35087
|
-
findNearestVertex: findNearestVertex
|
|
35177
|
+
findNearestVertex: findNearestVertex,
|
|
35178
|
+
findAdjacentVertex: findAdjacentVertex
|
|
35088
35179
|
});
|
|
35089
35180
|
|
|
35090
35181
|
// Returns x,y coordinates of the point that is at the midpoint of each polyline feature
|
|
@@ -40269,6 +40360,7 @@ ${svg}
|
|
|
40269
40360
|
AnchorPoints,
|
|
40270
40361
|
ArcClassifier,
|
|
40271
40362
|
ArcDissolve,
|
|
40363
|
+
ArcUtils,
|
|
40272
40364
|
Bbox2Clipping,
|
|
40273
40365
|
BinArray$1,
|
|
40274
40366
|
BufferCommon,
|
package/package.json
CHANGED