Skip to content

Instantly share code, notes, and snippets.

@ryansutc
Last active July 22, 2022 17:10
Show Gist options
  • Save ryansutc/ec2c8f25534a6cf50e7e60b773c0c166 to your computer and use it in GitHub Desktop.
Save ryansutc/ec2c8f25534a6cf50e7e60b773c0c166 to your computer and use it in GitHub Desktop.
A Snippet of a Custom BaseTileLayer rendering, serverside, a png layer
let CustomTileLayer = BaseTileLayer.createSubclass({
properties: {
urlTemplate: null,
},
getTileUrl: function (level, row, col) {
return this.urlTemplate
.replace("{z}", level)
.replace("{x}", col)
.replace("{y}", row);
},
fetchTile: function (level, row, col, options) {
let url = this.getTileUrl(level, row, col);
// request for the tile based on the url returned from getTileUrl() method.
// the signal option ensures that obsolete requests are aborted.
return esriRequest(url, {
//referrer: "origin",
responseType: "image",
signal: options && options.signal,
})
.then((response) => {
const image = response.data;
const width = this.tileInfo.size[0];
const height = this.tileInfo.size[0];
const canvas = document.createElement("canvas");
const context = canvas.getContext("2d");
canvas.width = width;
canvas.height = height;
context.drawImage(image, 0, 0, width, height);
console.log(`new: ${level}-${row}-${col}`);
return canvas;
})
.catch((err) => console.error(err.message));
},
}); // end class
let myLayer = new CustomTileLayer({
urlTemplate: [url],
id: "19"
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment