252 lines
7.7 KiB
JavaScript
252 lines
7.7 KiB
JavaScript
// node_modules/topojson-client/src/reverse.js
|
|
function reverse_default(array, n) {
|
|
var t, j = array.length, i = j - n;
|
|
while (i < --j) t = array[i], array[i++] = array[j], array[j] = t;
|
|
}
|
|
|
|
// node_modules/topojson-client/src/identity.js
|
|
function identity_default(x) {
|
|
return x;
|
|
}
|
|
|
|
// node_modules/topojson-client/src/transform.js
|
|
function transform_default(transform) {
|
|
if (transform == null) return identity_default;
|
|
var x0, y0, kx = transform.scale[0], ky = transform.scale[1], dx = transform.translate[0], dy = transform.translate[1];
|
|
return function(input, i) {
|
|
if (!i) x0 = y0 = 0;
|
|
var j = 2, n = input.length, output = new Array(n);
|
|
output[0] = (x0 += input[0]) * kx + dx;
|
|
output[1] = (y0 += input[1]) * ky + dy;
|
|
while (j < n) output[j] = input[j], ++j;
|
|
return output;
|
|
};
|
|
}
|
|
|
|
// node_modules/topojson-client/src/feature.js
|
|
function feature_default(topology, o) {
|
|
if (typeof o === "string") o = topology.objects[o];
|
|
return o.type === "GeometryCollection" ? { type: "FeatureCollection", features: o.geometries.map(function(o2) {
|
|
return feature(topology, o2);
|
|
}) } : feature(topology, o);
|
|
}
|
|
function feature(topology, o) {
|
|
var id = o.id, bbox = o.bbox, properties = o.properties == null ? {} : o.properties, geometry = object(topology, o);
|
|
return id == null && bbox == null ? { type: "Feature", properties, geometry } : bbox == null ? { type: "Feature", id, properties, geometry } : { type: "Feature", id, bbox, properties, geometry };
|
|
}
|
|
function object(topology, o) {
|
|
var transformPoint = transform_default(topology.transform), arcs = topology.arcs;
|
|
function arc(i, points) {
|
|
if (points.length) points.pop();
|
|
for (var a = arcs[i < 0 ? ~i : i], k = 0, n = a.length; k < n; ++k) {
|
|
points.push(transformPoint(a[k], k));
|
|
}
|
|
if (i < 0) reverse_default(points, n);
|
|
}
|
|
function point(p) {
|
|
return transformPoint(p);
|
|
}
|
|
function line(arcs2) {
|
|
var points = [];
|
|
for (var i = 0, n = arcs2.length; i < n; ++i) arc(arcs2[i], points);
|
|
if (points.length < 2) points.push(points[0]);
|
|
return points;
|
|
}
|
|
function ring(arcs2) {
|
|
var points = line(arcs2);
|
|
while (points.length < 4) points.push(points[0]);
|
|
return points;
|
|
}
|
|
function polygon(arcs2) {
|
|
return arcs2.map(ring);
|
|
}
|
|
function geometry(o2) {
|
|
var type = o2.type, coordinates;
|
|
switch (type) {
|
|
case "GeometryCollection":
|
|
return { type, geometries: o2.geometries.map(geometry) };
|
|
case "Point":
|
|
coordinates = point(o2.coordinates);
|
|
break;
|
|
case "MultiPoint":
|
|
coordinates = o2.coordinates.map(point);
|
|
break;
|
|
case "LineString":
|
|
coordinates = line(o2.arcs);
|
|
break;
|
|
case "MultiLineString":
|
|
coordinates = o2.arcs.map(line);
|
|
break;
|
|
case "Polygon":
|
|
coordinates = polygon(o2.arcs);
|
|
break;
|
|
case "MultiPolygon":
|
|
coordinates = o2.arcs.map(polygon);
|
|
break;
|
|
default:
|
|
return null;
|
|
}
|
|
return { type, coordinates };
|
|
}
|
|
return geometry(o);
|
|
}
|
|
|
|
// node_modules/topojson-client/src/stitch.js
|
|
function stitch_default(topology, arcs) {
|
|
var stitchedArcs = {}, fragmentByStart = {}, fragmentByEnd = {}, fragments = [], emptyIndex = -1;
|
|
arcs.forEach(function(i, j) {
|
|
var arc = topology.arcs[i < 0 ? ~i : i], t;
|
|
if (arc.length < 3 && !arc[1][0] && !arc[1][1]) {
|
|
t = arcs[++emptyIndex], arcs[emptyIndex] = i, arcs[j] = t;
|
|
}
|
|
});
|
|
arcs.forEach(function(i) {
|
|
var e = ends(i), start = e[0], end = e[1], f, g;
|
|
if (f = fragmentByEnd[start]) {
|
|
delete fragmentByEnd[f.end];
|
|
f.push(i);
|
|
f.end = end;
|
|
if (g = fragmentByStart[end]) {
|
|
delete fragmentByStart[g.start];
|
|
var fg = g === f ? f : f.concat(g);
|
|
fragmentByStart[fg.start = f.start] = fragmentByEnd[fg.end = g.end] = fg;
|
|
} else {
|
|
fragmentByStart[f.start] = fragmentByEnd[f.end] = f;
|
|
}
|
|
} else if (f = fragmentByStart[end]) {
|
|
delete fragmentByStart[f.start];
|
|
f.unshift(i);
|
|
f.start = start;
|
|
if (g = fragmentByEnd[start]) {
|
|
delete fragmentByEnd[g.end];
|
|
var gf = g === f ? f : g.concat(f);
|
|
fragmentByStart[gf.start = g.start] = fragmentByEnd[gf.end = f.end] = gf;
|
|
} else {
|
|
fragmentByStart[f.start] = fragmentByEnd[f.end] = f;
|
|
}
|
|
} else {
|
|
f = [i];
|
|
fragmentByStart[f.start = start] = fragmentByEnd[f.end = end] = f;
|
|
}
|
|
});
|
|
function ends(i) {
|
|
var arc = topology.arcs[i < 0 ? ~i : i], p0 = arc[0], p1;
|
|
if (topology.transform) p1 = [0, 0], arc.forEach(function(dp) {
|
|
p1[0] += dp[0], p1[1] += dp[1];
|
|
});
|
|
else p1 = arc[arc.length - 1];
|
|
return i < 0 ? [p1, p0] : [p0, p1];
|
|
}
|
|
function flush(fragmentByEnd2, fragmentByStart2) {
|
|
for (var k in fragmentByEnd2) {
|
|
var f = fragmentByEnd2[k];
|
|
delete fragmentByStart2[f.start];
|
|
delete f.start;
|
|
delete f.end;
|
|
f.forEach(function(i) {
|
|
stitchedArcs[i < 0 ? ~i : i] = 1;
|
|
});
|
|
fragments.push(f);
|
|
}
|
|
}
|
|
flush(fragmentByEnd, fragmentByStart);
|
|
flush(fragmentByStart, fragmentByEnd);
|
|
arcs.forEach(function(i) {
|
|
if (!stitchedArcs[i < 0 ? ~i : i]) fragments.push([i]);
|
|
});
|
|
return fragments;
|
|
}
|
|
|
|
// node_modules/topojson-client/src/merge.js
|
|
function planarRingArea(ring) {
|
|
var i = -1, n = ring.length, a, b = ring[n - 1], area = 0;
|
|
while (++i < n) a = b, b = ring[i], area += a[0] * b[1] - a[1] * b[0];
|
|
return Math.abs(area);
|
|
}
|
|
function merge_default(topology) {
|
|
return object(topology, mergeArcs.apply(this, arguments));
|
|
}
|
|
function mergeArcs(topology, objects) {
|
|
var polygonsByArc = {}, polygons = [], groups = [];
|
|
objects.forEach(geometry);
|
|
function geometry(o) {
|
|
switch (o.type) {
|
|
case "GeometryCollection":
|
|
o.geometries.forEach(geometry);
|
|
break;
|
|
case "Polygon":
|
|
extract(o.arcs);
|
|
break;
|
|
case "MultiPolygon":
|
|
o.arcs.forEach(extract);
|
|
break;
|
|
}
|
|
}
|
|
function extract(polygon) {
|
|
polygon.forEach(function(ring) {
|
|
ring.forEach(function(arc) {
|
|
(polygonsByArc[arc = arc < 0 ? ~arc : arc] || (polygonsByArc[arc] = [])).push(polygon);
|
|
});
|
|
});
|
|
polygons.push(polygon);
|
|
}
|
|
function area(ring) {
|
|
return planarRingArea(object(topology, { type: "Polygon", arcs: [ring] }).coordinates[0]);
|
|
}
|
|
polygons.forEach(function(polygon) {
|
|
if (!polygon._) {
|
|
var group = [], neighbors = [polygon];
|
|
polygon._ = 1;
|
|
groups.push(group);
|
|
while (polygon = neighbors.pop()) {
|
|
group.push(polygon);
|
|
polygon.forEach(function(ring) {
|
|
ring.forEach(function(arc) {
|
|
polygonsByArc[arc < 0 ? ~arc : arc].forEach(function(polygon2) {
|
|
if (!polygon2._) {
|
|
polygon2._ = 1;
|
|
neighbors.push(polygon2);
|
|
}
|
|
});
|
|
});
|
|
});
|
|
}
|
|
}
|
|
});
|
|
polygons.forEach(function(polygon) {
|
|
delete polygon._;
|
|
});
|
|
return {
|
|
type: "MultiPolygon",
|
|
arcs: groups.map(function(polygons2) {
|
|
var arcs = [], n;
|
|
polygons2.forEach(function(polygon) {
|
|
polygon.forEach(function(ring) {
|
|
ring.forEach(function(arc) {
|
|
if (polygonsByArc[arc < 0 ? ~arc : arc].length < 2) {
|
|
arcs.push(arc);
|
|
}
|
|
});
|
|
});
|
|
});
|
|
arcs = stitch_default(topology, arcs);
|
|
if ((n = arcs.length) > 1) {
|
|
for (var i = 1, k = area(arcs[0]), ki, t; i < n; ++i) {
|
|
if ((ki = area(arcs[i])) > k) {
|
|
t = arcs[0], arcs[0] = arcs[i], arcs[i] = t, k = ki;
|
|
}
|
|
}
|
|
}
|
|
return arcs;
|
|
}).filter(function(arcs) {
|
|
return arcs.length > 0;
|
|
})
|
|
};
|
|
}
|
|
|
|
export {
|
|
feature_default,
|
|
merge_default
|
|
};
|
|
//# sourceMappingURL=chunk-C5ESQFF4.js.map
|