Skip to content

Commit

Permalink
add action to test build
Browse files Browse the repository at this point in the history
  • Loading branch information
msbarry committed Oct 1, 2023
1 parent b0eb796 commit 980b015
Show file tree
Hide file tree
Showing 7 changed files with 1,148 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
- run: npm ci
- run: npm test
- run: npm run build
- run: npm run test-build
# benchmark script only works on node 18+
- run: node benchmark.js
if: matrix.node-version != '16.x'
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"scripts": {
"bench": "npm run build && node benchmark.js",
"build": "rm -rf dist && rollup -c && npm run generate-types && tsc --project tsconfig.dist.json",
"test-build": "cd test-project && npm i && npm test",
"generate-types": "tsc --emitDeclarationOnly --declaration --outDir dist && rm -rf dist/*{.t,-j}est.d.ts",
"jest": "jest",
"jest:watch": "jest --watch",
Expand Down
14 changes: 7 additions & 7 deletions src/dem-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ type RequestParameters = {
headers?: any;
method?: "GET" | "POST" | "PUT";
body?: string;
type?: "string" | "json" | "arrayBuffer";
type?: "string" | "json" | "arrayBuffer" | "image";
credentials?: "same-origin" | "include";
collectResourceTiming?: boolean;
};
type ResponseCallback = (
error?: Error | undefined,
data?: any | undefined,
cacheControl?: string | undefined,
expires?: string | undefined,
expires?: string | undefined
) => void;
type Protocol = (
request: RequestParameters,
response: ResponseCallback,
response: ResponseCallback
) => Cancelable;

const used = new Set<string>();
Expand Down Expand Up @@ -93,7 +93,7 @@ export class DemSource {
encoding,
maxzoom,
timeoutMs,
actor,
actor
);
}

Expand Down Expand Up @@ -128,7 +128,7 @@ export class DemSource {
*/
sharedDemProtocol = (
request: RequestParameters,
response: ResponseCallback,
response: ResponseCallback
): Cancelable => {
const [z, x, y] = this.parseUrl(request.url);
const timer = new Timer("main");
Expand Down Expand Up @@ -164,7 +164,7 @@ export class DemSource {
*/
contourProtocol = (
request: RequestParameters,
response: ResponseCallback,
response: ResponseCallback
): Cancelable => {
const timer = new Timer("main");
const [z, x, y] = this.parseUrl(request.url);
Expand All @@ -174,7 +174,7 @@ export class DemSource {
x,
y,
getOptionsForZoom(options, z),
timer,
timer
);
let canceled = false;
(async () => {
Expand Down
95 changes: 95 additions & 0 deletions test-project/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import mlcontour from "maplibre-contour";
import maplibregl from "maplibre-gl";

const demSource = new mlcontour.DemSource({
url: "https://elevation-tiles-prod.s3.amazonaws.com/terrarium/{z}/{x}/{y}.png",
encoding: "terrarium",
maxzoom: 13,
});

// calls maplibregl.addProtocol for the shared cache and contour protocols
demSource.setupMaplibre(maplibregl);

const map = new maplibregl.Map({
container: "map",
zoom: 12.55,
center: [86.92731, 27.97797],
hash: true,
style: {
version: 8,
glyphs: "https://demotiles.maplibre.org/font/{fontstack}/{range}.pbf",
sources: {
dem: {
type: "raster-dem",
encoding: "terrarium",
tiles: [demSource.sharedDemProtocolUrl], // share cached DEM tiles with contour layer
maxzoom: 13,
tileSize: 256,
},
contours: {
type: "vector",
tiles: [
demSource.contourProtocolUrl({
// meters to feet
multiplier: 3.28084,
thresholds: {
// zoom: [minor, major]
11: [200, 1000],
12: [100, 500],
13: [100, 500],
14: [50, 200],
15: [20, 100],
},
elevationKey: "ele",
levelKey: "level",
contourLayer: "contours",
}),
],
maxzoom: 16,
},
},
layers: [
{
id: "hills",
type: "hillshade",
source: "dem",
paint: {
"hillshade-exaggeration": 0.25,
},
},
{
id: "contours",
type: "line",
source: "contours",
"source-layer": "contours",
paint: {
"line-color": "rgba(0,0,0, 50%)",
"line-width": ["match", ["get", "level"], 1, 1, 0.5],
},
layout: {
"line-join": "round",
},
},
{
id: "contour-text",
type: "symbol",
source: "contours",
"source-layer": "contours",
filter: [">", ["get", "level"], 0],
paint: {
"text-halo-color": "white",
"text-halo-width": 1,
},
layout: {
"symbol-placement": "line",
"text-anchor": "center",
"text-size": 10,
"text-field": ["concat", ["number-format", ["get", "ele"], {}], "'"],
"text-font": ["Noto Sans Bold"],
},
},
],
},
});

console.log(map);
Loading

0 comments on commit 980b015

Please sign in to comment.