StephanGeorg / staticmaps

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

Possible to add layers? #48

Closed BoxSo closed 1 year ago

BoxSo commented 3 years ago

Let's say i want to add another layer from a tile-Server (http://openfiremap.org/hytiles/z/x/y.png). Would this be possible somehow?

Regards

BoxSon

StephanGeorg commented 3 years ago

Sure, but it's a basemap not a layer:

const StaticMaps = require('staticmaps');
const options = {
  width: 600,
  height: 400,
  tileUrl: 'http://openfiremap.org/hytiles/{z}/{x}/{y}.png',
};

const map = new StaticMaps(options);
BoxSo commented 3 years ago

This does not seem to work. All i get is a white image. Maybe i'm doing something wrong?

var StaticMaps = require('staticmaps');

const options = {
    width: 600,
    height: 400,
    tileUrl: 'http://openfiremap.org/hytiles/{z}/{x}/{y}.png',
};

const map = new StaticMaps(options);

/ THIS WORKS const options = { width: 600, height: 400, zoomRange: { max: 20, } }; const map = new StaticMaps(options); /

const marker = {
    img: `${__dirname}/marker.png`, // can also be a URL,
    offsetX: 24,
    offsetY: 48,
    width: 48,
    height: 48,
    coord: [lon, lat],
};
map.addMarker(marker);
map.render()
    .then(() => map.image.save('single-marker.png'))
    .then(() => {
        console.log('File saved!');
        callback(true);
    })
    .catch((err) => {
        console.log('Error generating map: ' + err.message);
        callback(false);
    });
StephanGeorg commented 3 years ago

Can I see a code snippet?

BoxSo commented 3 years ago

single-marker

This is the resulting image

StephanGeorg commented 3 years ago

Ok, I checked the tiles and its indeed a layer and not a basemap: http://openfiremap.org/hytiles/11/1084/700.png

Sorry, I thought the hydrant icons are rendered onto the tile images. This is a new use case and will add a feature to support that kind of "layers".

BoxSo commented 3 years ago

Thanks Stephan! appreciate!

Regards

Jens

Semurak commented 2 years ago

Is there any news regarding this feature?

Thanks!

JorgenPhi commented 2 years ago

Added a PR for the modifications I made to add 2 tile servers: https://github.com/StephanGeorg/staticmaps/pull/68

StephanGeorg commented 1 year ago

Closed with #68