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

map.preloadOnly does not work (exception fired) #12696

Closed
fvisticot opened this issue May 6, 2023 · 3 comments · Fixed by #12699
Closed

map.preloadOnly does not work (exception fired) #12696

fvisticot opened this issue May 6, 2023 · 3 comments · Fixed by #12699
Labels

Comments

@fvisticot
Copy link

fvisticot commented May 6, 2023

mapbox-gl-js version: 2.14.1

browser: chrome

Steps to Trigger Behavior

map.flyTo({ ...end, duration: 6500, essential: true, preloadOnly: true })

Actual Behavior

urce_cache.js:1025 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'tileZoom') at source_cache.js:1025:108 at util.js:277:9 at Array.forEach (<anonymous>) at M (util.js:276:11) at sy._preloadTiles (source_cache.js:1024:9) at map.js:3596:52 at util.js:277:9 at Array.forEach (<anonymous>) at Object.M [as asyncAll] (util.js:276:11) at Map._preloadTiles (map.js:3596:9) (

Source code:

mapboxgl.accessToken =
    <API_KEY>;

const start = {
    center: [80, 36],
    zoom: 1,
    pitch: 0,
    bearing: 0
};

const map = new mapboxgl.Map({
    container: "map",
    projection: "globe",
    style: 'mapbox://styles/mapbox/satellite-streets-v12?optimize=true',
    ...start
});

window.map = map

map.on("load", async () => {

    map.addSource("mapbox-dem", {
        type: "raster-dem",
        url: "mapbox://mapbox.terrain-rgb",
        tileSize: 512,
        maxzoom: 14,
    });
    map.setTerrain({source: "mapbox-dem", exaggeration: 1.5});

    map.flyTo({
        center: [-3.45344, 48.70047],
        zoom: 14.5,
        bearing: 130,
        pitch: 75,
        duration: 6500,
        essential: true,
        preloadOnly: true
    })

});

index.html:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>Sequential Camera Animations</title>
    <meta name="description" content="" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <script src='https://api.mapbox.com/mapbox-gl-js/v2.14.1/mapbox-gl.js'></script>
    <link href='https://api.mapbox.com/mapbox-gl-js/v2.14.1/mapbox-gl.css' rel='stylesheet' />
    <script src="https://unpkg.com/@turf/turf/turf.min.js"></script>
  </head>

  <style>
    #map {
      width: 1280px;
      height: 720px;
      margin: 0 auto;
    }
  </style>

  <body>
    <div class="viewport-full relative scroll-hidden">
      <div id="map"></div>
    </div>
  </body>
  <script src="js/d3-ease.min.js" type="module"></script>
  <script src="js/test.js" type="module"></script>
</html>

@mourner
Copy link
Member

mourner commented May 6, 2023

Can you please provide a minimal live example reproducing the error, as prompted in the issue template?

@fvisticot
Copy link
Author

Can you please provide a minimal live example reproducing the error, as prompted in the issue template?

issue details updated

@stepankuzmin
Copy link
Contributor

stepankuzmin commented May 8, 2023

I can confirm this issue. It appears when you try preloading tiles right after adding a source until it's loaded. Started the fix here #12699.

@fvisticot In the meantime, you can wait until the source is loaded before preloading tiles

map.on("load", async () => {
    map.addSource("mapbox-dem", {
        type: "raster-dem",
        url: "mapbox://mapbox.terrain-rgb",
        tileSize: 512,
        maxzoom: 14,
    });

    map.setTerrain({source: "mapbox-dem", exaggeration: 1.5});

    await map.once('idle');

    map.flyTo({
        center: [-3.45344, 48.70047],
        zoom: 14.5,
        bearing: 130,
        pitch: 75,
        duration: 6500,
        essential: true,
        preloadOnly: true
    });
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants