Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Display a map on a webpage</title>
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
    <link href="https://api.mapbox.com/mapbox-gl-js/v3.10.0/mapbox-gl.css" rel="stylesheet">
    <script src="https://api.mapbox.com/mapbox-gl-js/v3.10.0/mapbox-gl.js"></script>
    <style>
        body {
            height: 100vh;
            width: 100vw;
            margin: 0;
            padding: 0;
            position: relative;
        }
        #map {
            position: absolute;
            top: 0;
            bottom: 0;
            width: 100%;
        }
    </style>
</head>
<body>
    <div id="map"></div>
    <script>
        mapboxgl.accessToken = 'pk.eyJ1Ijoiam9zaG5pY2U5OCIsImEiOiJjanlrMnYwd2IwOWMwM29vcnQ2aWIwamw2In0.RRsdQF3s2hQ6qK-7BH5cKg';
        const map = new mapboxgl.Map({
            container: 'map',
            center: [-74.5, 40],
            zoom: 20,
            pitch: 50,
            bearing: 45,
            style: "mapbox://styles/mapbox/light-v11"
        });
      
        const modelIdWebp = "webp-glb";
        const webpModel = "https://model-repo-488fcbb8-6cc3-4249-9acf-ea68bbdda2ee.s3.eu-west-2.amazonaws.com/model-with-image-webp.glb";
      
        const modelIdPng = "png-glb";
        const pngModel = "https://model-repo-488fcbb8-6cc3-4249-9acf-ea68bbdda2ee.s3.eu-west-2.amazonaws.com/model-with-image.glb";
        map.once('idle', () => {
            map.addModel(modelIdPng, pngModel)
            map.addSource("model-source-1", {
                type: "geojson",
                data: { type: "Feature", properties: {}, geometry: { coordinates: [-74.5001, 40], type: "Point" } },
            });
            map.addLayer({
                id: "model-layer-1",
                source: "model-source-1",
                type: 'model',
                layout: {
                    'model-id': modelIdPng
                }
            })
            
            map.addModel(modelIdWebp, webpModel)
            map.addSource("model-source-2", {
                type: "geojson",
                data: { type: "Feature", properties: {}, geometry: { coordinates: [-74.5000, 40], type: "Point" } },
            });
            map.addLayer({
                id: "model-layer-2",
                source: "model-source-2",
                type: 'model',
                layout: {
                    'model-id': modelIdWebp
                }
            })
        });
    </script>
</body>
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
 
</html>
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers