Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MikeM's avatar
Level 1

MapBox Layer not loading when imported into Laravel

I have built a PHP file which uses mapbox and then overlays a GeoJSON file over it. The script is working outside Laravel.

When I create a blade view with it, the Layer is not loading however it will load outside Laravel, I can see in the network section however it is pulling the GeoJSON file yet it will not display it. Is there a setting I need to adjust in order to let it load?

<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.51.0/mapbox-gl.js'></script>
    <link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.51.0/mapbox-gl.css' rel='stylesheet' />
  <link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Roboto+Slab:400,700|Material+Icons" />
  <style>
      body { margin:0; padding:0; }
      #map {
    height:100rem;
    min-height: 100%;
    min-width: 100%;
    display: block; }
    .fill
{
    min-height: 100%;
    height: 100%;
    width: 100%;
    min-width: 100%;
}
   </style>
  <!-- CSS Files -->
  </head>

<body class="">
  <div class="wrapper ">
    <div class="main-panel bg-white">
            <div id='map'></div>
            <script>
                mapboxgl.accessToken = 'access-token-here';
                var map = new mapboxgl.Map({
                    style: 'mapbox-style-goes-here',
                    center: [-0.12801, 51.50731],
                    zoom: 17,
                    pitch: 60,
                    bearing: -17.6,
                    container: 'map'
                });
                // The 'building' layer in the mapbox-streets vector source contains building-height
                // data from OpenStreetMap.
                map.on('load', function() {
                    map.addSource("sample", {
                    type: "geojson",
                    data: "URLtoGeoJSONHere"
                  });

                    // Insert the layer beneath any symbol layer.
                    var layers = map.getStyle().layers;

                    var labelLayerId;
                    for (var i = 0; i < layers.length; i++) {
                        if (layers[i].type === 'symbol' && layers[i].layout['text-field']) {
                            labelLayerId = layers[i].id;
                            break;
                        }
                    }

                    map.addLayer({
                        "id": "route",
                        "type": "line",
                        "source": "sample",
                        "layout": {
                            "line-join": "round",
                            "line-cap": "round"
                        },
                        "paint": {
                            "line-color": "#8b0000",
                            "line-width": 8
                        }
                    });
                    map.addLayer({
                        'id': '3d-buildings',
                        'source': 'composite',
                        'source-layer': 'building',
                        'filter': ['==', 'extrude', 'true'],
                        'type': 'fill-extrusion',
                        'minzoom': 15,
                        'paint': {
                            'fill-extrusion-color': '#aaa',

                            // use an 'interpolate' expression to add a smooth transition effect to the
                            // buildings as the user zooms in
                            'fill-extrusion-height': [
                                "interpolate", ["linear"], ["zoom"],
                                15, 0,
                                15.05, ["get", "height"]
                            ],
                            'fill-extrusion-base': [
                                "interpolate", ["linear"], ["zoom"],
                                15, 0,
                                15.05, ["get", "min_height"]
                            ],
                            'fill-extrusion-opacity': .6
                        }
                    }, labelLayerId);
                });
                </script>
        </div>
      </div>
    </div>
  </div>
</html>

I've removed my GeoJSON file, My Style and Access Token from this code snippet

0 likes
1 reply
hdnote's avatar

This happened to me and i tested mapbox in html file not blade it works fine and i don't need it in html i want it to work in blade! What is going on with it???

Please or to participate in this conversation.