StephanGeorg / staticmaps

A Node.js library for creating map images with markers, polylines, polygons and text.
MIT License
170 stars 49 forks source link

Changes in 1.12 breaks old code? #91

Closed MrAmericanMike closed 11 months ago

MrAmericanMike commented 11 months ago

So I have this very basic example that works when using Staticmaps 1.9.1

import StaticMaps from "staticmaps";

const MAP_OPTIONS = {
  width: 600,
  height: 300,
  subdomains: "abcd",
  tileUrl: "https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png",
};

const MAP = new StaticMaps(MAP_OPTIONS);
await MAP.render([-115.172977, 36.100822], 14);
await MAP.image.save("test.jpg", { quality: 70 });

However when upgrading to 1.12.0 it breaks.

It saves a file, but it's all black.

I can't find what the changes were between 1.9 and 1.12 for this to break. (It's not a mayor version change, so technically it should still work)

StephanGeorg commented 11 months ago
const options = {
  width: 1024,
  height: 1024,
  tileSubdomains: ['a', 'b', 'c', 'd'],
  tileUrl: 'https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}@2x.png',
  tileSize: 512,
};

See https://github.com/CartoDB/basemap-styles#1-web-raster-basemaps

MrAmericanMike commented 11 months ago

Thanks. Totally missed the subdomains been now tileSubdomains.

I guess the documentation here also would need to be updated to reflect those changes: https://github.com/CartoDB/basemap-styles#1-web-raster-basemaps

I wasn't familiar with the "scale" option. I guess I will have to look into that closer, as I can see it affects the zoom at the same time.

StephanGeorg commented 11 months ago

The code above never worked:

  1. subdomains: "abcd", was always expecting an array
  2. {r} was never supported.

I can't find what the changes were between 1.9 and 1.12 for this to break. (It's not a mayor version change, so technically it should still work)

MrAmericanMike commented 11 months ago
import StaticMaps from "staticmaps";

const MAP_OPTIONS = {
  width: 600,
  height: 300,
  subdomains: "abcd",
  tileUrl: "https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png",
};

const MAP = new StaticMaps(MAP_OPTIONS);
await MAP.render([-115.172977, 36.100822], 14);
await MAP.image.save("test.jpg", { quality: 70 });

I have this test here. https://replit.com/@MrAmericanMike/StaticMaps-1#index.js

Took it from some old code I used. I never had issues with it. I guess if it worked was only by chance? But it never gave me problems in that 1.9.1 version.