L.GPX 不是构造函数

L.GPX is not a constructor

我正在我的 Leaflet 地图中寻找导入 GPX 文件 但是当我尝试该网站时,它响应 L.GPX is not a constructor 我脑子里只有那个

    <script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>

还有体内的那个

<div id="map"></div>

<script>    
    var sites = {!! json_encode($markers) !!};

    var map = L.map('map').setView([{{ config('leaflet.map_center_latitude') }}, {{ config('leaflet.map_center_longitude') }}], {{ config('leaflet.zoom_level') }});
    
    L.tileLayer('https://api.maptiler.com/maps/streets/{z}/{x}/{y}@2x.png?key=2Qw6dd02HLfOXS3LDGMP', {
        attribution: '<a href="https://www.maptiler.com/copyright/" target="_blank">&copy; MapTiler</a> <a href="https://www.openstreetmap.org/copyright" target="_blank">&copy; OpenStreetMap contributors</a>'
    }).addTo(map);

    var marker;
    sites.forEach(element => {
        marker = L.marker([element[0], element[1]]).addTo(map);
    });

    var gpx = '/resources/gpx/pont.gpx'; // URL to your GPX file or the GPX itself
    
    new L.GPX(gpx, {
        async: true,
        polyline_options: {
              color: '#ff0000',
              }
        }
    ).on('loaded', function(e) {
        map.fitBounds(e.target.getBounds());
    }).addTo(map);

</script>

你必须load the plugin before you can use it:

Usage
First, include the Leaflet.js and Leaflet-GPX scripts in your HTML page:

如前所述,在您的 header 或您的脚本

之前添加以下行
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet-gpx/1.4.0/gpx.min.js"></script>