Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offset custom marker in a static map #431

Open
greenafrican opened this issue Nov 17, 2021 · 0 comments
Open

Offset custom marker in a static map #431

greenafrican opened this issue Nov 17, 2021 · 0 comments

Comments

@greenafrican
Copy link

It would be great if we could provide an offset for the custom markers. Something like:

client.getStaticImage({
    ...
    overlays: {
        coordinates: [18, -33],
        url: "../../customPin.png",
        offset: [0.5, 1]
    }

This would help when we use a custom pin or flag or something where the bottom-centre point should mark the location.

As a workaround, I currently use this to offset the latitude coordinate:

// From https://stackoverflow.com/a/30773300/1177562
const metersPerPixel = (latitude: number, zoomLevel: number) => {
  const earthCircumference = 40075017
  const latitudeRadians = latitude * (Math.PI / 180)
  return (earthCircumference * Math.cos(latitudeRadians)) / Math.pow(2, zoomLevel + 9)
}

export const getLatitudeDegreesOffset = (latitude: number, pixels: number, zoomLevel: number) => {
  // https://gis.stackexchange.com/questions/2951/algorithm-for-offsetting-a-latitude-longitude-by-some-amount-of-meters
  return (metersPerPixel(latitude, zoomLevel) * pixels) / 111111
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant