Skip to content

Commit

Permalink
Continue linting fixes [#287] (#332)
Browse files Browse the repository at this point in the history
* make use of ===, if branches, let/const, string templates, var names consistent style.
  • Loading branch information
bdon authored Jan 29, 2024
1 parent 3b61cc8 commit a6cbc19
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 189 deletions.
110 changes: 53 additions & 57 deletions js/adapters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ export const leafletRasterLayer = (source: PMTiles, options: any) => {
};
if (!loaded) {
source.getHeader().then((header) => {
if (header.tileType == TileType.Mvt) {
if (header.tileType === TileType.Mvt) {
console.error(
"Error: archive contains MVT vector tiles, but leafletRasterLayer is for displaying raster tiles. See https://github.com/protomaps/PMTiles/tree/main/js for details."
);
} else if (header.tileType == 2) {
} else if (header.tileType === 2) {
mimeType = "image/png";
} else if (header.tileType == 3) {
} else if (header.tileType === 3) {
mimeType = "image/jpeg";
} else if (header.tileType == 4) {
} else if (header.tileType === 4) {
mimeType = "image/webp";
} else if (header.tileType == 5) {
} else if (header.tileType === 5) {
mimeType = "image/avif";
}
});
Expand Down Expand Up @@ -115,7 +115,7 @@ export class Protocol {
params: RequestParameters,
callback: ResponseCallback
): Cancelable => {
if (params.type == "json") {
if (params.type === "json") {
const pmtilesUrl = params.url.substr(10);
let instance = this.tiles.get(pmtilesUrl);
if (!instance) {
Expand All @@ -127,7 +127,7 @@ export class Protocol {
.getHeader()
.then((h) => {
const tilejson = {
tiles: [params.url + "/{z}/{x}/{y}"],
tiles: [`${params.url}/{z}/{x}/{y}`],
minzoom: h.minZoom,
maxzoom: h.maxZoom,
bounds: [h.minLon, h.minLat, h.maxLon, h.maxLat],
Expand All @@ -141,60 +141,56 @@ export class Protocol {
return {
cancel: () => {},
};
} else {
const re = new RegExp(/pmtiles:\/\/(.+)\/(\d+)\/(\d+)\/(\d+)/);
const result = params.url.match(re);
if (!result) {
throw new Error("Invalid PMTiles protocol URL");
return {
cancel: () => {},
};
}
const pmtilesUrl = result[1];
}
const re = new RegExp(/pmtiles:\/\/(.+)\/(\d+)\/(\d+)\/(\d+)/);
const result = params.url.match(re);
if (!result) {
throw new Error("Invalid PMTiles protocol URL");
}
const pmtilesUrl = result[1];

let instance = this.tiles.get(pmtilesUrl);
if (!instance) {
instance = new PMTiles(pmtilesUrl);
this.tiles.set(pmtilesUrl, instance);
}
const z = result[2];
const x = result[3];
const y = result[4];
let instance = this.tiles.get(pmtilesUrl);
if (!instance) {
instance = new PMTiles(pmtilesUrl);
this.tiles.set(pmtilesUrl, instance);
}
const z = result[2];
const x = result[3];
const y = result[4];

const controller = new AbortController();
const signal = controller.signal;
const cancel = () => {
controller.abort();
};
const controller = new AbortController();
const signal = controller.signal;
const cancel = () => {
controller.abort();
};

instance.getHeader().then((header) => {
instance!
.getZxy(+z, +x, +y, signal)
.then((resp) => {
if (resp) {
callback(
null,
new Uint8Array(resp.data),
resp.cacheControl,
resp.expires
);
instance.getHeader().then((header) => {
instance
?.getZxy(+z, +x, +y, signal)
.then((resp) => {
if (resp) {
callback(
null,
new Uint8Array(resp.data),
resp.cacheControl,
resp.expires
);
} else {
if (header.tileType === TileType.Mvt) {
callback(null, new Uint8Array(), null, null);
} else {
if (header.tileType == TileType.Mvt) {
callback(null, new Uint8Array(), null, null);
} else {
callback(null, null, null, null);
}
}
})
.catch((e) => {
if ((e as Error).name !== "AbortError") {
callback(e, null, null, null);
callback(null, null, null, null);
}
});
});
return {
cancel: cancel,
};
}
}
})
.catch((e) => {
if ((e as Error).name !== "AbortError") {
callback(e, null, null, null);
}
});
});
return {
cancel: cancel,
};
};
}
Loading

0 comments on commit a6cbc19

Please # to comment.