mapbox / mapbox-gl-language

Switch language of your Mapbox GL JS style
https://mapbox.github.io/mapbox-gl-language/
BSD 3-Clause "New" or "Revised" License
192 stars 51 forks source link

Error: terrain: terrain is missing required property "source" when use projection: "globe" ! #55

Open DennisGuo opened 2 years ago

DennisGuo commented 2 years ago

When I use {projection: "globe"} to init map will cause th error .

const map = new mapboxgl.Map({
    container: "map", // container ID
    style: "mapbox://styles/mapbox/dark-v10", // style URL
    center: [106.55, 29.57], // starting position [lng, lat]
    zoom: 2, // starting zoom
    projection: "globe", // display the map as a 3D globe
  });
  map.addControl(
    new MapboxLanguage({
      defaultLanguage: "zh-Hans",
    })
  );

The error info

Error: terrain: terrain is missing required property "source"
    at Object.Mi [as emitValidationErrors] (validate_style.js:13:41)
    at Ht (style.js:57:5)
    at ei.setState (style.js:647:13)
    at Map._updateDiff (map.js:1887:28)
    at Map._diffStyle (map.js:1881:18)
    at Map.setStyle (map.js:1822:18)
    at MapboxLanguage._initialStyleUpdate (index.js:141:13)
    at Map.fire (evented.js:129:26)
    at ei.fire (evented.js:144:24)
    at ei._load (style.js:355:14)

if i do not use {projection: "globe"} , it work find !

leungMr commented 2 years ago

the same problem happened !!!

hqh15 commented 1 year ago

Everyone, I I solved it.

const map = new mapboxgl.Map({
  container: 'map',
  style: 'mapbox://styles/mapbox/satellite-streets-v11',
  zoom: 1.8,
  center: [118, 40]
})

const language = new MapboxLanguage({
  defaultLanguage: 'zh-Hans'
})
map.addControl(language)

map.on('load', () => {
  map.setStyle(
    Object.assign({}, map.getStyle(), { projection: { name: 'globe' } })
  )
})