MCPcopy Create free account
hub / github.com/StephanGeorg/staticmaps / drawLayer

Method drawLayer

src/staticmaps.js:250–298  ·  view source on GitHub ↗
(config)

Source from the content-addressed store, hash-verified

248 }
249
250 async drawLayer(config) {
251 if (!config || !config.tileUrl) {
252 // Early return if we shouldn't draw a base layer
253 console.log(1);
254 return this.image.draw([]);
255 }
256 const xMin = Math.floor(this.centerX - (0.5 * this.width / this.tileSize));
257 const yMin = Math.floor(this.centerY - (0.5 * this.height / this.tileSize));
258 const xMax = Math.ceil(this.centerX + (0.5 * this.width / this.tileSize));
259 const yMax = Math.ceil(this.centerY + (0.5 * this.height / this.tileSize));
260
261 const result = [];
262
263 for (let x = xMin; x < xMax; x++) {
264 for (let y = yMin; y < yMax; y++) {
265 // # x and y may have crossed the date line
266 const maxTile = (2 ** this.zoom);
267 const tileX = (x + maxTile) % maxTile;
268 let tileY = (y + maxTile) % maxTile;
269 if (this.reverseY) tileY = ((1 << this.zoom) - tileY) - 1;
270
271 let tileUrl;
272 if (config.tileUrl.includes('{quadkey}')) {
273 const quadKey = geoutils.tileXYToQuadKey(tileX, tileY, this.zoom);
274 tileUrl = config.tileUrl.replace('{quadkey}', quadKey);
275 } else {
276 tileUrl = config.tileUrl.replace('{z}', this.zoom).replace('{x}', tileX).replace('{y}', tileY);
277 }
278
279 if (config.tileSubdomains.length > 0) {
280 // replace subdomain with random domain from tileSubdomains array
281 tileUrl = tileUrl.replace('{s}', config.tileSubdomains[Math.floor(Math.random() * config.tileSubdomains.length)]);
282 }
283
284 result.push({
285 url: tileUrl,
286 box: [
287 this.xToPx(x),
288 this.yToPx(y),
289 this.xToPx(x + 1),
290 this.yToPx(y + 1),
291 ],
292 });
293 }
294 }
295
296 const tiles = await this.getTiles(result);
297 return this.image.draw(tiles.filter((v) => v.success).map((v) => v.tile));
298 }
299
300 async drawSVG(features, svgFunction) {
301 if (!features.length) return;

Callers 1

renderMethod · 0.95

Calls 4

xToPxMethod · 0.95
yToPxMethod · 0.95
getTilesMethod · 0.95
drawMethod · 0.80

Tested by

no test coverage detected