• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

glandais / elevation / 17899710778

21 Sep 2025 10:21PM UTC coverage: 94.896% (-5.0%) from 99.891%
17899710778

push

github

glandais
feat: add Node.js support with environment-specific implementations

- Implement cross-platform support for both Browser and Node.js environments
- Create Tile abstraction layer with environment-specific implementations:
  - BrowserTileFetcher: Uses native browser APIs (Canvas, fetch, ImageBitmap)
  - NodeJsTileFetcher: Uses canvas package for Node.js compatibility
- Add dynamic module loading based on __NODE__ build flag
- Separate build targets for browser (ES, UMD, IIFE) and Node.js (ES, CommonJS)
- Lazy initialization of cache to support async module imports
- Merge ElevationDecoder functionality directly into Tile implementations
- Add optional Node.js dependencies: canvas, node-fetch, abort-controller

BREAKING CHANGE: Removed clearCache() method from public API - cache is now managed
internally with LRU eviction only

BREAKING CHANGE: Removed timeout parameter from ElevationProviderConfig - timeout
handling is now environment-specific

253 of 267 branches covered (94.76%)

Branch coverage included in aggregate %.

73 of 108 new or added lines in 10 files covered. (67.59%)

658 of 693 relevant lines covered (94.95%)

102.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/tile/fetcher/nodejs/NodeJsTileFetcher.ts
NEW
1
import { CanvasPool, TileFetcher } from '..';
×
NEW
2
import { NodeTile } from './NodeJsTile';
×
3
import { Tile } from '../..';
NEW
4
import { Canvas, createCanvas, loadImage } from 'canvas';
×
5

NEW
6
export class NodeJsTileFetcher implements TileFetcher {
×
7
    private readonly canvasPool: CanvasPool<Canvas>;
8

9
    constructor() {
NEW
10
        this.canvasPool = new CanvasPool<Canvas>(() => createCanvas(256, 256));
×
11
    }
12

13
    /**
14
     * Fetch a tile image and return both ImageData and ImageBitmap for memory management
15
     * @param url - The URL of the tile to fetch
16
     * @param tileKey - The tile identifier for logging
17
     * @returns Promise<Tile> - Object containing ImageData and ImageBitmap
18
     */
19
    public async fetchTile(url: string): Promise<Tile> {
NEW
20
        const image = await loadImage(url);
×
21
        // Acquire canvas from pool
NEW
22
        const canvas = this.canvasPool.acquire();
×
23

NEW
24
        try {
×
25
            // Resize canvas to match image dimensions
NEW
26
            if (canvas.width !== image.width) {
×
NEW
27
                canvas.width = image.width;
×
28
            }
NEW
29
            if (canvas.height !== image.height) {
×
NEW
30
                canvas.height = image.height;
×
31
            }
32

NEW
33
            const ctx = canvas.getContext('2d');
×
34

NEW
35
            ctx.drawImage(image, 0, 0);
×
NEW
36
            const data = ctx.getImageData(0, 0, image.width, image.height);
×
NEW
37
            return new NodeTile(data);
×
38
        } finally {
39
            // Always return canvas to pool for reuse
NEW
40
            this.canvasPool.release(canvas);
×
41
        }
42
    }
43
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc