【问题标题】:L.GPX is not a constructorL.GPX 不是构造函数
【发布时间】:2021-01-11 23:08:36
【问题描述】:

我正在我的传单地图中寻找导入 GPX 文件 但是当我尝试使用 L.GPX 响应的站点时,它不是构造函数 我脑子里只有这个

    <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>

【问题讨论】:

    标签: leaflet gpx


    【解决方案1】:

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

    用法
    首先,在 HTML 中包含 Leaflet.js 和 Leaflet-GPX 脚本 页面:

    如上所述,在标题中或脚本之前添加以下行

    <script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet-gpx/1.4.0/gpx.min.js"></script>
    

    【讨论】:

      猜你喜欢
      • 2013-12-25
      • 2015-12-04
      • 2018-11-29
      • 2016-12-04
      • 2020-12-27
      • 2021-04-05
      • 2021-06-21
      • 2017-01-27
      • 2011-08-18
      相关资源
      最近更新 更多