staticmaps icon indicating copy to clipboard operation
staticmaps copied to clipboard

Possible to add layers?

Open BoxSo opened this issue 3 years ago • 8 comments

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

BoxSo avatar Oct 11 '20 18:10 BoxSo

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);

StephanGeorg avatar Oct 13 '20 08:10 StephanGeorg

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);
    });

BoxSo avatar Oct 15 '20 14:10 BoxSo

Can I see a code snippet?

StephanGeorg avatar Oct 15 '20 14:10 StephanGeorg

single-marker

This is the resulting image

BoxSo avatar Oct 15 '20 14:10 BoxSo

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".

StephanGeorg avatar Oct 15 '20 14:10 StephanGeorg

Thanks Stephan! appreciate!

Regards

Jens

BoxSo avatar Oct 15 '20 17:10 BoxSo

Is there any news regarding this feature?

Thanks!

Semurak avatar Apr 28 '22 10:04 Semurak

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

JorgenPhi avatar May 15 '22 17:05 JorgenPhi

Closed with #68

StephanGeorg avatar Jan 23 '23 08:01 StephanGeorg