首页 > 解决方案 > 如何修复错误:无法读取未定义的属性“mapmatching”

问题描述

我在本地使用 mapbox-match.js 而不使用 http 请求来匹配 map 上的路线。但我在匹配和错误消息中有问题

“无法读取'mapmatching'未定义的属性”

显示。如何解决这个问题?

这是用于本地主机地图的地图可视化。运行 http 服务器、html 和 javascript。我使用 d3-js 和 mapbox 将一组坐标呈现为地图上的 geojson 数据以可视化路线

<head>
  <meta charset='utf-8' />
  <script src='MAPBOX/mapbox-gl.js'></script>
  <link href='MAPBOX/mapbox-gl.css' rel='stylesheet' />
  <script src='mapbox.js-publisher-production/src/mapbox.js'></script>
  <script src='mapbox-match.js-master/src/match.js'></script>
</head>

<body>
  <script>
    function updateRoute(newCoords) {
      // Set the profile
      var profile = "driving";
      L.mapbox.mapmatching(Coords, profile);
    }

    L.mapbox.mapmatching(Coords, profile, function(error, layer) {

      layer.addTo(map);
      layer.setStyle({
        color: '#9a0202',
        weight: 4,
        opacity: 0.8
      });

      layer.addLayer({
        "id": "route",
        "type": "line",
        "source": {
          "type": "geojson",
          "data": {
            "type": "Feature",
            "properties": {},
            "geometry": coords
          }
        },
        "layout": {
          "line-join": "round",
          "line-cap": "round"
        },
        "paint": {
          "line-color": "#33C9EB",
          "line-width": 3
        }

      });
    });
    }
  </script>
</body>

调试代码后显示错误“TypeError:无法读取未定义的属性'mapmatching'”

标签: javascriptmapbox

解决方案


推荐阅读