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

Allow adding sources, layers & setting terrain without waiting for map load #10191

Open
mourner opened this issue Dec 11, 2020 · 4 comments
Open
Assignees
Labels
api 📝 feature 🍏 performance ⚡ Speed, stability, CPU usage, memory usage, or power usage

Comments

@mourner
Copy link
Member

mourner commented Dec 11, 2020

One of the biggest hurdles when adding terrain to an existing style is that we need to wait for the map load event first, and only then we can add the terrain source and set the terrain options. This is problematic both ergonomically (it's annoying to use map.on('load', () => { ... } constantly in even basic examples), and in terms of performance, since terrain tiles don't start loading until all the vector tiles finished loading and rendering.

We should investigate whether it's possible to improve the style mechanism so that:

  • sources and layers could be added lazily, without waiting for load, so that their incorporation into the style would be deferred until it's loaded (if loading is in progress) instead of throwing and error
  • lazily loaded sources eagerly initialize the source cache and start loading tiles before the map has finished loading.
@mourner mourner added feature 🍏 performance ⚡ Speed, stability, CPU usage, memory usage, or power usage api 📝 labels Dec 11, 2020
@rsnipes
Copy link

rsnipes commented Dec 11, 2020

On a related note, loving the 3D terrain features... Trying to add those (example code works well), but then struggling when switching styles. Basically, using map.on('load', () => { ... } works fine initially, but then when setting a new style the terrain source is lost and attempts to re-add get lost amongst waiting for new style to fully load (which has always been a tricky endeavor). Any idea on how to handle this better? Or... Possible to include the terrain source in Mapbox Studio defined styles?

@karimnaaji
Copy link
Contributor

karimnaaji commented Dec 12, 2020

@rsnipes yes you can directly add terrain in your style as such to prevent this type of issue:

var map = window.map = new mapboxgl.Map({
    container: 'map',
    style: {
        ...
        'sources': {
            'mapbox-dem': {
                'type': 'raster-dem',
                'url': 'mapbox://mapbox.mapbox-terrain-dem-v1',
                'tileSize': 512,
                'maxzoom': 14
             }
         },
        'layers': [
             ...
        ],
        'terrain': {
            'source': 'mapbox-dem',
            'exaggeration': 1.5
        }
    },
    hash: true,
    center: [0, 0],
    pitch: 0,
    bearing: 0,
    zoom: 0
});

Support for Studio is incoming, once this is done you will be able to directly edit your style to add the new features there.

@stevage
Copy link
Contributor

stevage commented Dec 15, 2020

sources and layers could be added lazily, without waiting for load, so that their incorporation into the style would be deferred until it's loaded (if loading is in progress) instead of throwing and error

Yes, please. Anything would be better than "Style is not done loading". 🙏

Linking to the growing back catalog of discussion: #9779 #8691 #8765

@djibarian
Copy link

Added some comments in #2268 related to this issue, for the record.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api 📝 feature 🍏 performance ⚡ Speed, stability, CPU usage, memory usage, or power usage
5 participants