m4-w-fast 1.0.11 → 1.0.12
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/dist/index.cjs +157 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +157 -0
- package/dist/intersect.worker.js +2 -2
- package/dist/isoBands.worker.js +1 -1
- package/dist/m4-w-fast.umd.js +1 -1
- package/dist/readFile.d.ts +5 -0
- package/dist/readFile.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -6517,6 +6517,163 @@ class readFileM4 {
|
|
|
6517
6517
|
}
|
|
6518
6518
|
return json;
|
|
6519
6519
|
}
|
|
6520
|
+
/**
|
|
6521
|
+
* 获取挖孔等值面 他可以设置透明度
|
|
6522
|
+
* @param breaks
|
|
6523
|
+
*/
|
|
6524
|
+
getIsoBandsFastByMask(breaks) {
|
|
6525
|
+
if (this.values.length === 0)
|
|
6526
|
+
return { type: 'FeatureCollection', features: [] };
|
|
6527
|
+
const localBreaks = (breaks && breaks.length) ? breaks : this.getBreaks();
|
|
6528
|
+
if (!localBreaks.length)
|
|
6529
|
+
return { type: 'FeatureCollection', features: [] };
|
|
6530
|
+
const baseLng = this.minLng;
|
|
6531
|
+
const baseLat = this.minLat;
|
|
6532
|
+
const stepLng = this.gjLng;
|
|
6533
|
+
const stepLat = this.gjLat;
|
|
6534
|
+
// ring 有向面积(用于外环/内环判定)
|
|
6535
|
+
const ringArea = (ring) => {
|
|
6536
|
+
let a = 0;
|
|
6537
|
+
for (let i = 0, n = ring.length; i < n; i++) {
|
|
6538
|
+
const p1 = ring[i];
|
|
6539
|
+
const p2 = ring[(i + 1) % n];
|
|
6540
|
+
if (!p1 || !p2)
|
|
6541
|
+
continue;
|
|
6542
|
+
a += p1[0] * p2[1] - p2[0] * p1[1];
|
|
6543
|
+
}
|
|
6544
|
+
return a / 2;
|
|
6545
|
+
};
|
|
6546
|
+
// 点在环内
|
|
6547
|
+
const pointInRing = (pt, ring) => {
|
|
6548
|
+
if (!pt)
|
|
6549
|
+
return false;
|
|
6550
|
+
const x = pt[0];
|
|
6551
|
+
const y = pt[1];
|
|
6552
|
+
let inside = false;
|
|
6553
|
+
for (let i = 0, j = ring.length - 1; i < ring.length; j = i++) {
|
|
6554
|
+
const xi = ring[i][0];
|
|
6555
|
+
const yi = ring[i][1];
|
|
6556
|
+
const xj = ring[j][0];
|
|
6557
|
+
const yj = ring[j][1];
|
|
6558
|
+
const intersect = ((yi > y) !== (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
|
|
6559
|
+
if (intersect)
|
|
6560
|
+
inside = !inside;
|
|
6561
|
+
}
|
|
6562
|
+
return inside;
|
|
6563
|
+
};
|
|
6564
|
+
// 栅格索引 -> 经纬度,且去重 + 闭合
|
|
6565
|
+
const convertAndClean = (gridRing) => {
|
|
6566
|
+
const out = [];
|
|
6567
|
+
let prevX = null;
|
|
6568
|
+
let prevY = null;
|
|
6569
|
+
for (let k = 0; k < gridRing.length; k++) {
|
|
6570
|
+
const pt = gridRing[k];
|
|
6571
|
+
if (!pt)
|
|
6572
|
+
continue;
|
|
6573
|
+
const x = pt[0];
|
|
6574
|
+
const y = pt[1];
|
|
6575
|
+
if (x == null || y == null || Number.isNaN(x) || Number.isNaN(y))
|
|
6576
|
+
continue;
|
|
6577
|
+
const lng = baseLng + x * stepLng;
|
|
6578
|
+
const lat = baseLat + y * stepLat;
|
|
6579
|
+
if (prevX !== null && prevY !== null && prevX === lng && prevY === lat)
|
|
6580
|
+
continue;
|
|
6581
|
+
out.push([lng, lat]);
|
|
6582
|
+
prevX = lng;
|
|
6583
|
+
prevY = lat;
|
|
6584
|
+
}
|
|
6585
|
+
if (!out.length)
|
|
6586
|
+
return out;
|
|
6587
|
+
const first = out[0];
|
|
6588
|
+
const last = out[out.length - 1];
|
|
6589
|
+
if (first[0] !== last[0] || first[1] !== last[1])
|
|
6590
|
+
out.push([first[0], first[1]]);
|
|
6591
|
+
return out;
|
|
6592
|
+
};
|
|
6593
|
+
const features = [];
|
|
6594
|
+
const lastIndex = localBreaks.length - 1;
|
|
6595
|
+
// 每层单独做二值 mask,天然互斥,无需布尔挖孔
|
|
6596
|
+
for (let i = 0; i < localBreaks.length; i++) {
|
|
6597
|
+
const lower = localBreaks[i];
|
|
6598
|
+
const upper = (i < lastIndex) ? localBreaks[i + 1] : Infinity;
|
|
6599
|
+
const mask = new Array(this.values.length);
|
|
6600
|
+
let anyOne = false;
|
|
6601
|
+
for (let k = 0; k < this.values.length; k++) {
|
|
6602
|
+
const v = this.values[k];
|
|
6603
|
+
const on = (v != null && v >= lower && v < upper) ? 1 : 0;
|
|
6604
|
+
mask[k] = on;
|
|
6605
|
+
if (on)
|
|
6606
|
+
anyOne = true;
|
|
6607
|
+
}
|
|
6608
|
+
if (!anyOne)
|
|
6609
|
+
continue;
|
|
6610
|
+
// 用 d3-contour 在二值场提取该层轮廓
|
|
6611
|
+
const gen = contours().size([this.nx, this.ny]).thresholds([0.5]);
|
|
6612
|
+
const allGeos = gen.contours ? gen.contours(mask) : gen(mask);
|
|
6613
|
+
if (!allGeos || !allGeos.length)
|
|
6614
|
+
continue;
|
|
6615
|
+
for (const g of allGeos) {
|
|
6616
|
+
const coordsGroups = g?.coordinates;
|
|
6617
|
+
if (!coordsGroups)
|
|
6618
|
+
continue;
|
|
6619
|
+
for (const polyOrRings of coordsGroups) {
|
|
6620
|
+
let rings = [];
|
|
6621
|
+
// 兼容 d3-contour 返回结构
|
|
6622
|
+
if (Array.isArray(polyOrRings) && polyOrRings.length > 0 && typeof polyOrRings[0][0] === 'number') {
|
|
6623
|
+
rings = [polyOrRings];
|
|
6624
|
+
}
|
|
6625
|
+
else if (Array.isArray(polyOrRings)) {
|
|
6626
|
+
rings = polyOrRings;
|
|
6627
|
+
}
|
|
6628
|
+
else {
|
|
6629
|
+
continue;
|
|
6630
|
+
}
|
|
6631
|
+
// 按面积从大到小,先外环后洞
|
|
6632
|
+
const ringsWithArea = rings
|
|
6633
|
+
.map(r => ({ ring: r, area: Math.abs(ringArea(r)) }))
|
|
6634
|
+
.sort((a, b) => b.area - a.area);
|
|
6635
|
+
const used = new Array(ringsWithArea.length).fill(false);
|
|
6636
|
+
for (let ri = 0; ri < ringsWithArea.length; ri++) {
|
|
6637
|
+
if (used[ri])
|
|
6638
|
+
continue;
|
|
6639
|
+
const outerGrid = ringsWithArea[ri].ring;
|
|
6640
|
+
used[ri] = true;
|
|
6641
|
+
const holesGrid = [];
|
|
6642
|
+
for (let hj = 0; hj < ringsWithArea.length; hj++) {
|
|
6643
|
+
if (used[hj])
|
|
6644
|
+
continue;
|
|
6645
|
+
const cand = ringsWithArea[hj].ring;
|
|
6646
|
+
const testPt = cand[0];
|
|
6647
|
+
if (testPt && pointInRing(testPt, outerGrid)) {
|
|
6648
|
+
holesGrid.push(cand);
|
|
6649
|
+
used[hj] = true;
|
|
6650
|
+
}
|
|
6651
|
+
}
|
|
6652
|
+
const outer = convertAndClean(outerGrid);
|
|
6653
|
+
if (outer.length < 4)
|
|
6654
|
+
continue;
|
|
6655
|
+
const holes = [];
|
|
6656
|
+
for (const h of holesGrid) {
|
|
6657
|
+
const hc = convertAndClean(h);
|
|
6658
|
+
if (hc.length >= 4)
|
|
6659
|
+
holes.push(hc);
|
|
6660
|
+
}
|
|
6661
|
+
features.push({
|
|
6662
|
+
type: 'Feature',
|
|
6663
|
+
properties: { z: lower },
|
|
6664
|
+
geometry: {
|
|
6665
|
+
type: 'Polygon',
|
|
6666
|
+
coordinates: [outer, ...holes]
|
|
6667
|
+
}
|
|
6668
|
+
});
|
|
6669
|
+
}
|
|
6670
|
+
}
|
|
6671
|
+
}
|
|
6672
|
+
}
|
|
6673
|
+
// 低->高,兼容你现有 getColorFast(level.indexOf(z))
|
|
6674
|
+
features.sort((a, b) => Number(a.properties?.z ?? 0) - Number(b.properties?.z ?? 0));
|
|
6675
|
+
return { type: 'FeatureCollection', features };
|
|
6676
|
+
}
|
|
6520
6677
|
// --------------------------------------------- 融合工具 ---------------------------------------------
|
|
6521
6678
|
buildGridLineCanvas(options) {
|
|
6522
6679
|
if (this.nx <= 0 || this.ny <= 0 || this.gjLng === 0 || this.gjLat === 0)
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function a0_0x117c(_0x1a92ae,_0x7eaf56){var _0x21f240=a0_0x21f2();return a0_0x117c=function(_0x117c50,_0x1069b1){_0x117c50=_0x117c50-0x12e;var _0x4d7d15=_0x21f240[_0x117c50];return _0x4d7d15;},a0_0x117c(_0x1a92ae,_0x7eaf56);}(function(_0x402a9d,_0x270621){var _0x5b1842=a0_0x117c,_0x950f09=_0x402a9d();while(!![]){try{var _0x3e15d4=parseInt(_0x5b1842(0x12e))/0x1+parseInt(_0x5b1842(0x12f))/0x2+-parseInt(_0x5b1842(0x134))/0x3+-parseInt(_0x5b1842(0x136))/0x4+parseInt(_0x5b1842(0x131))/0x5*(parseInt(_0x5b1842(0x133))/0x6)+parseInt(_0x5b1842(0x132))/0x7*(-parseInt(_0x5b1842(0x130))/0x8)+-parseInt(_0x5b1842(0x137))/0x9*(-parseInt(_0x5b1842(0x135))/0xa);if(_0x3e15d4===_0x270621)break;else _0x950f09['push'](_0x950f09['shift']());}catch(_0x1b6f39){_0x950f09['push'](_0x950f09['shift']());}}}(a0_0x21f2,0xb7c3f));import a0_0x2b5a1f from'./readFile';export default a0_0x2b5a1f;function a0_0x21f2(){var _0x466243=['406288GyEkQv','3411Mapibk','979834UWyApq','2448516zBACKg','38960mAzbLX','2533145GtbDYr','1673LAltqD','6Tmmbbh','4044558sEbDoJ','17300gDSMkf'];a0_0x21f2=function(){return _0x466243;};return a0_0x21f2();}
|
package/dist/index.mjs
CHANGED
|
@@ -6515,6 +6515,163 @@ class readFileM4 {
|
|
|
6515
6515
|
}
|
|
6516
6516
|
return json;
|
|
6517
6517
|
}
|
|
6518
|
+
/**
|
|
6519
|
+
* 获取挖孔等值面 他可以设置透明度
|
|
6520
|
+
* @param breaks
|
|
6521
|
+
*/
|
|
6522
|
+
getIsoBandsFastByMask(breaks) {
|
|
6523
|
+
if (this.values.length === 0)
|
|
6524
|
+
return { type: 'FeatureCollection', features: [] };
|
|
6525
|
+
const localBreaks = (breaks && breaks.length) ? breaks : this.getBreaks();
|
|
6526
|
+
if (!localBreaks.length)
|
|
6527
|
+
return { type: 'FeatureCollection', features: [] };
|
|
6528
|
+
const baseLng = this.minLng;
|
|
6529
|
+
const baseLat = this.minLat;
|
|
6530
|
+
const stepLng = this.gjLng;
|
|
6531
|
+
const stepLat = this.gjLat;
|
|
6532
|
+
// ring 有向面积(用于外环/内环判定)
|
|
6533
|
+
const ringArea = (ring) => {
|
|
6534
|
+
let a = 0;
|
|
6535
|
+
for (let i = 0, n = ring.length; i < n; i++) {
|
|
6536
|
+
const p1 = ring[i];
|
|
6537
|
+
const p2 = ring[(i + 1) % n];
|
|
6538
|
+
if (!p1 || !p2)
|
|
6539
|
+
continue;
|
|
6540
|
+
a += p1[0] * p2[1] - p2[0] * p1[1];
|
|
6541
|
+
}
|
|
6542
|
+
return a / 2;
|
|
6543
|
+
};
|
|
6544
|
+
// 点在环内
|
|
6545
|
+
const pointInRing = (pt, ring) => {
|
|
6546
|
+
if (!pt)
|
|
6547
|
+
return false;
|
|
6548
|
+
const x = pt[0];
|
|
6549
|
+
const y = pt[1];
|
|
6550
|
+
let inside = false;
|
|
6551
|
+
for (let i = 0, j = ring.length - 1; i < ring.length; j = i++) {
|
|
6552
|
+
const xi = ring[i][0];
|
|
6553
|
+
const yi = ring[i][1];
|
|
6554
|
+
const xj = ring[j][0];
|
|
6555
|
+
const yj = ring[j][1];
|
|
6556
|
+
const intersect = ((yi > y) !== (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
|
|
6557
|
+
if (intersect)
|
|
6558
|
+
inside = !inside;
|
|
6559
|
+
}
|
|
6560
|
+
return inside;
|
|
6561
|
+
};
|
|
6562
|
+
// 栅格索引 -> 经纬度,且去重 + 闭合
|
|
6563
|
+
const convertAndClean = (gridRing) => {
|
|
6564
|
+
const out = [];
|
|
6565
|
+
let prevX = null;
|
|
6566
|
+
let prevY = null;
|
|
6567
|
+
for (let k = 0; k < gridRing.length; k++) {
|
|
6568
|
+
const pt = gridRing[k];
|
|
6569
|
+
if (!pt)
|
|
6570
|
+
continue;
|
|
6571
|
+
const x = pt[0];
|
|
6572
|
+
const y = pt[1];
|
|
6573
|
+
if (x == null || y == null || Number.isNaN(x) || Number.isNaN(y))
|
|
6574
|
+
continue;
|
|
6575
|
+
const lng = baseLng + x * stepLng;
|
|
6576
|
+
const lat = baseLat + y * stepLat;
|
|
6577
|
+
if (prevX !== null && prevY !== null && prevX === lng && prevY === lat)
|
|
6578
|
+
continue;
|
|
6579
|
+
out.push([lng, lat]);
|
|
6580
|
+
prevX = lng;
|
|
6581
|
+
prevY = lat;
|
|
6582
|
+
}
|
|
6583
|
+
if (!out.length)
|
|
6584
|
+
return out;
|
|
6585
|
+
const first = out[0];
|
|
6586
|
+
const last = out[out.length - 1];
|
|
6587
|
+
if (first[0] !== last[0] || first[1] !== last[1])
|
|
6588
|
+
out.push([first[0], first[1]]);
|
|
6589
|
+
return out;
|
|
6590
|
+
};
|
|
6591
|
+
const features = [];
|
|
6592
|
+
const lastIndex = localBreaks.length - 1;
|
|
6593
|
+
// 每层单独做二值 mask,天然互斥,无需布尔挖孔
|
|
6594
|
+
for (let i = 0; i < localBreaks.length; i++) {
|
|
6595
|
+
const lower = localBreaks[i];
|
|
6596
|
+
const upper = (i < lastIndex) ? localBreaks[i + 1] : Infinity;
|
|
6597
|
+
const mask = new Array(this.values.length);
|
|
6598
|
+
let anyOne = false;
|
|
6599
|
+
for (let k = 0; k < this.values.length; k++) {
|
|
6600
|
+
const v = this.values[k];
|
|
6601
|
+
const on = (v != null && v >= lower && v < upper) ? 1 : 0;
|
|
6602
|
+
mask[k] = on;
|
|
6603
|
+
if (on)
|
|
6604
|
+
anyOne = true;
|
|
6605
|
+
}
|
|
6606
|
+
if (!anyOne)
|
|
6607
|
+
continue;
|
|
6608
|
+
// 用 d3-contour 在二值场提取该层轮廓
|
|
6609
|
+
const gen = contours().size([this.nx, this.ny]).thresholds([0.5]);
|
|
6610
|
+
const allGeos = gen.contours ? gen.contours(mask) : gen(mask);
|
|
6611
|
+
if (!allGeos || !allGeos.length)
|
|
6612
|
+
continue;
|
|
6613
|
+
for (const g of allGeos) {
|
|
6614
|
+
const coordsGroups = g?.coordinates;
|
|
6615
|
+
if (!coordsGroups)
|
|
6616
|
+
continue;
|
|
6617
|
+
for (const polyOrRings of coordsGroups) {
|
|
6618
|
+
let rings = [];
|
|
6619
|
+
// 兼容 d3-contour 返回结构
|
|
6620
|
+
if (Array.isArray(polyOrRings) && polyOrRings.length > 0 && typeof polyOrRings[0][0] === 'number') {
|
|
6621
|
+
rings = [polyOrRings];
|
|
6622
|
+
}
|
|
6623
|
+
else if (Array.isArray(polyOrRings)) {
|
|
6624
|
+
rings = polyOrRings;
|
|
6625
|
+
}
|
|
6626
|
+
else {
|
|
6627
|
+
continue;
|
|
6628
|
+
}
|
|
6629
|
+
// 按面积从大到小,先外环后洞
|
|
6630
|
+
const ringsWithArea = rings
|
|
6631
|
+
.map(r => ({ ring: r, area: Math.abs(ringArea(r)) }))
|
|
6632
|
+
.sort((a, b) => b.area - a.area);
|
|
6633
|
+
const used = new Array(ringsWithArea.length).fill(false);
|
|
6634
|
+
for (let ri = 0; ri < ringsWithArea.length; ri++) {
|
|
6635
|
+
if (used[ri])
|
|
6636
|
+
continue;
|
|
6637
|
+
const outerGrid = ringsWithArea[ri].ring;
|
|
6638
|
+
used[ri] = true;
|
|
6639
|
+
const holesGrid = [];
|
|
6640
|
+
for (let hj = 0; hj < ringsWithArea.length; hj++) {
|
|
6641
|
+
if (used[hj])
|
|
6642
|
+
continue;
|
|
6643
|
+
const cand = ringsWithArea[hj].ring;
|
|
6644
|
+
const testPt = cand[0];
|
|
6645
|
+
if (testPt && pointInRing(testPt, outerGrid)) {
|
|
6646
|
+
holesGrid.push(cand);
|
|
6647
|
+
used[hj] = true;
|
|
6648
|
+
}
|
|
6649
|
+
}
|
|
6650
|
+
const outer = convertAndClean(outerGrid);
|
|
6651
|
+
if (outer.length < 4)
|
|
6652
|
+
continue;
|
|
6653
|
+
const holes = [];
|
|
6654
|
+
for (const h of holesGrid) {
|
|
6655
|
+
const hc = convertAndClean(h);
|
|
6656
|
+
if (hc.length >= 4)
|
|
6657
|
+
holes.push(hc);
|
|
6658
|
+
}
|
|
6659
|
+
features.push({
|
|
6660
|
+
type: 'Feature',
|
|
6661
|
+
properties: { z: lower },
|
|
6662
|
+
geometry: {
|
|
6663
|
+
type: 'Polygon',
|
|
6664
|
+
coordinates: [outer, ...holes]
|
|
6665
|
+
}
|
|
6666
|
+
});
|
|
6667
|
+
}
|
|
6668
|
+
}
|
|
6669
|
+
}
|
|
6670
|
+
}
|
|
6671
|
+
// 低->高,兼容你现有 getColorFast(level.indexOf(z))
|
|
6672
|
+
features.sort((a, b) => Number(a.properties?.z ?? 0) - Number(b.properties?.z ?? 0));
|
|
6673
|
+
return { type: 'FeatureCollection', features };
|
|
6674
|
+
}
|
|
6518
6675
|
// --------------------------------------------- 融合工具 ---------------------------------------------
|
|
6519
6676
|
buildGridLineCanvas(options) {
|
|
6520
6677
|
if (this.nx <= 0 || this.ny <= 0 || this.gjLng === 0 || this.gjLat === 0)
|