StephanGeorg / staticmaps

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

Ability to render multiple maps with same options #62

Open roelandwyns opened 2 years ago

roelandwyns commented 2 years ago

Hi,

We have the following use case:

Staticmaps calculates the bounds for displaying the map based on the features on that map individually on the render. This means that if we have features that are outside of the boundaries of the background map, the centerX, centerY and zoom are recalculated and this does not work very well when overlaying the maps on each other. (Misaligned features on the background image).

What we do now as a fix for this is getting the { centerX, centerY, zoom } out of the background map, and using them in the render of the feature maps. (after re-converting x with xToLon and y using yToLat). This works perfectly, however it is not the cleanest.

If needed, we can also look into creating a PR if you tell me your thoughts on this idea :) .

Kind regards,

Roeland

StephanGeorg commented 2 years ago

Hi @roelandwyns

Ok, I understand your use case and needs. But what would be the perfect solution for that? In JS you can access map.zoom, map.center, map.centerX and map.centerY properties. So you could at them to the type definitions.

EvertEt commented 2 years ago

Using these properties would indeed help to solve this. But wouldn't there still be a problem needing to convert map.centerX and map.centerY back and forth, possibly introducing slight errors?

StephanGeorg commented 2 years ago

Maybe but I can't see any solution on staticmaps side or feature that could be included into this module.

EvertEt commented 2 years ago

Since xToLon, yToLat aren't exported in the default export, it might be easier for us to calculate the center ourselves. And render the first map with center + addBound (undocumented?) and let it calculate the zoom. Then we can use the calculated center and the map1.zoom for the second map.

EvertEt commented 2 years ago
  1. Would having a centerLat and centerLon property on the map next to centerX and centerY be acceptable?
  2. Would you be open for a PR documenting addBound?
StephanGeorg commented 2 years ago

Would having a centerLat and centerLon property on the map next to centerX and centerY be acceptable? Would you be open for a PR documenting addBound?

Sure.