Skip to content

Commit 44a7e18

Browse files
XinyueDuduxinyue.dxy
andauthored
feat: maplibre 兼容 pmtiles (#2666)
* feat: maplibre 兼容 pmtiles * fix: lint fixed * fix: lint fixed * fix: update artifact-actions * fix: test error * feat: test png update * feat: integration fixed * feat: integration fixed * feat: intergration fixed * feat: intergration fixed * feat: bug test * feat: bug test * feat: intergration test * feat: intergration test * feat: inter test * feat: inter test * feat: intergration test * feat: intergration test * feat: intergration test * feat: inter test * feat: deleted png * feat: update png * feat: intergration test * feat: intergration test * feat: intergration fixed * feat: intergration fixed * feat: maplibre compat pmTiles * feat: bug fixed * feat: intergration fixed --------- Co-authored-by: duxinyue.dxy <[email protected]>
1 parent e9464e7 commit 44a7e18

File tree

5 files changed

+13
-27
lines changed

5 files changed

+13
-27
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -91,31 +91,14 @@ jobs:
9191
- name: Integration Test
9292
run: pnpm test:integration
9393

94-
- name: Check if snapshot files exist
95-
run: |
96-
if [ ! -d "__tests__/integration/snapshots/" ]; then
97-
echo "Directory __tests__/integration/snapshots/ does not exist"
98-
exit 1
99-
fi
100-
if [ ! "$(ls -A __tests__/integration/snapshots/*-actual.png)" ]; then
101-
echo "No files matching __tests__/integration/snapshots/*-actual.png found"
102-
exit 1
103-
fi
104-
- name: Generate timestamp and random string
105-
run: |
106-
echo "TIMESTAMP=$(date +%s)" >> $GITHUB_ENV
107-
echo "RANDOM_STRING=$(openssl rand -hex 4)" >> $GITHUB_ENV
108-
10994
- name: Upload snapshots to GitHub Actions Artifacts
11095
if: always()
11196
uses: actions/upload-artifact@v4
11297
with:
113-
name: snapshots-${{ env.TIMESTAMP }}-${{ env.RANDOM_STRING }}
98+
name: snapshots
11499
path: |
115100
__tests__/integration/snapshots/*-actual.png
116101
retention-days: 1
117-
if-no-files-found: ignore
118-
include-hidden-files: true
119102

120103
size-test:
121104
runs-on: ubuntu-latest

__tests__/integration/utils/generator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export function generateCanvasTestCases(
5353
// Chart already rendered, capture into buffer.
5454
const buffer = await page.locator('canvas').screenshot();
5555
const dir = `${__dirname}/../snapshots`;
56-
const maxError = 100000;
56+
const maxError = 0;
5757

5858
try {
5959
expect(buffer).toMatchCanvasSnapshot(dir, key, { maxError });

__tests__/integration/utils/toMatchCanvasSnapshot.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,11 @@ function diff(
3535

3636
// @see https://github.com/mapbox/pixelmatch#pixelmatchimg1-img2-output-width-height-options
3737
const mismatch = pixelmatch(img1.data, img2.data, output, width, height, {
38-
threshold: 0.05,
38+
threshold: 0.1,
3939
});
4040

4141
if (showMismatchedPixels && mismatch > maxError && diffPNG) {
4242
fs.writeFileSync(diff, PNG.sync.write(diffPNG));
43-
console.log(`Mismatched pixels: ${mismatch}`);
4443
}
4544

4645
return mismatch;
@@ -82,7 +81,6 @@ export function toMatchCanvasSnapshot(
8281
writePNG(buffer, actualPath);
8382
const error = diff(actualPath, expectedPath, diffPath, maxError);
8483
if (error <= maxError) {
85-
console.log('toMatchCanvasSnapshot==>', error, maxError);
8684
if (fs.existsSync(diffPath)) fs.unlinkSync(diffPath);
8785
fs.unlinkSync(actualPath);
8886
return {
@@ -91,7 +89,7 @@ export function toMatchCanvasSnapshot(
9189
};
9290
}
9391
return {
94-
message: () => `mismatch ${namePath} (error: ${error}) (maxError: ${maxError})`,
92+
message: () => `mismatch ${namePath} (error: ${error})`,
9593
pass: false,
9694
};
9795
}

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@
7070
"react": "^18.2.0",
7171
"react-dom": "^18.2.0",
7272
"stats.js": "^0.17.0",
73-
"three": "0.115.0"
73+
"three": "0.115.0",
74+
"@types/pixelmatch": "^5.2.5",
75+
"pixelmatch": "5.3.0",
76+
"pngjs": "^6.0.0"
7477
},
7578
"devDependencies": {
7679
"@antv/translator": "^1.0.1",

packages/maps/src/maplibre/map.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ export default class Service extends BaseMapService<Map & IMapboxInstance> {
115115
this.$mapContainer = this.creatMapContainer(id);
116116

117117
if (typeof style !== 'string') {
118-
const protocol = new Protocol();
119-
maplibregl.addProtocol('pmtiles', protocol.tile);
118+
this.addProtocol();
120119
}
121120
// @ts-ignore
122121
this.map = new window.maplibregl.Map({
@@ -135,7 +134,10 @@ export default class Service extends BaseMapService<Map & IMapboxInstance> {
135134
// 不同于高德地图,需要手动触发首次渲染
136135
this.handleCameraChanged();
137136
}
138-
137+
public addProtocol() {
138+
const protocol = new Protocol();
139+
maplibregl.addProtocol('pmtiles', protocol.tile);
140+
}
139141
public destroy() {
140142
// 销毁地图可视化层的容器
141143
this.$mapContainer?.parentNode?.removeChild(this.$mapContainer);

0 commit comments

Comments
 (0)