mapbox / mapbox/mapbox-sdk-js

Offset custom marker in a static map

Open
#431 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
768
Forks
191
PR merge metrics
No merged PRs in 30d

Description

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
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names client.getStaticImage as the entry point and shows overlays with a custom URL and offset. Trace that static-map request path first; done means accepting the offset so the marker's bottom-centre point marks the supplied coordinates.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.