mapbox-gl-js
mapbox-gl-js copied to clipboard
Style spec validator allows any `string` as a value for `projection` field
Style-spec validator allows projection to be a string which is not supported by the spec itself. The spec states that it should be an object
with a name
field.
This line is the source of the problem: https://github.com/mapbox/mapbox-gl-js/blob/5859fd8103adc1781e047d89189d7e5f96f5df9a/src/style-spec/validate/validate_projection.js#L29
Somewhat related: https://github.com/mapbox/mapbox-gl-js/issues/12028
This page in the documentation describes where shorthand is appropriate. It seems like it should never be present in a style.
const token = 'pk.eyJ1IjoiYWxleGFuZGVyLWJlbG9rb24iLCJhIjoiY2w3Z2R0cTRiMDNmZTN2b2E1NTNoZGVsOCJ9.UJGcVwpGNY34ApOhnkw4wg'
mapboxgl.accessToken = token
async function create() {
const res = await fetch(`https://api.mapbox.com/styles/v1/mapbox/streets-v11?access_token=${token}`)
const style = await res.json()
// works
const map1 = new mapboxgl.Map({ container: 'map1', style: { ...style }, projection: 'globe' })
// doesn't work
const map2 = new mapboxgl.Map({ container: 'map2', style: { ...style, projection: 'globe' } })
}
create()
mapbox-gl-js version: 2.10.0
browser: any
Steps to Trigger Behavior
- create a style with
{ "projection": "chair" }
- try to validate it
- observe return value
Link to Demonstration
Expected Behavior
Validator rejects string
values for the projection
field
Actual Behavior
Validator allows string
values for the projection
field