`.getStyle` is broken for Standard style
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 12.4k
- Forks
- 2.4k
- PR merge metrics
- No merged PRs in 30d
Description
According to MapBox JS API docs, getStyle method returns Style JSON:
There is not any mention or hint about Standard style, for which this method returns different:
This makes harder to retrieve current style name or url property.
Some developers even think that Standard style doesn't have name at all: https://github.com/korywka/mapbox-controls/pull/55.
Current fix looks like this:
getCurrentStyleName() {
if (!this.map) throw Error('map is undefined');
/** @type {string} */
let name;
/** @type {any} mapbox standard style doesn't return JSON object */
const style = this.map.getStyle();
if (Array.isArray(style.imports) && style.imports.length) {
// mapbox standard style
name = style.imports[0].data.name;
console.log(style);
} else {
// classic style
name = style.name;
}
if (!name) throw Error('style must have name');
return name;
}
My proposal:
- fix documentation, add information about
Standardstyle - fix JSDoc for
.getStyle()documentation - add method to get real current style source
let it be string for url like mapbox://styles/mapbox/satellite-streets-v12 or mapbox://styles/mapbox/standard and Object for plain JSON style.
Or suggest please another way to identify loaded style among others.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the getStyle() API documentation and its Standard-style return shape, comparing it with the classic style shape described in the issue. Determine whether the intended change is documentation, JSDoc, or a new way to identify the loaded style; done should include a clearly documented and consistent result for Standard and plain JSON styles.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- api, frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100