我已经在这个问题上挣扎了一段时间,所以我有两个问题要问。
第一个问题:我无法更改开放路由服务的配置文件。当我在下面的代码中输入api-key时,我的代码就可以工作了。
var control;
function tests() {
var control = L.Routing.control({
waypoints: [
L.latLng(coords),
L.latLng(coords2)
],
router: new L.Routing.openrouteservice('Api-Key'),
}).addTo(map);
document.getElementById("RouteButton").onclick = tests;
};但是,当我尝试更改配置文件时,它要么不更改,要么得到错误消息。
到目前为止我试过的东西是。
router: new L.Routing.openrouteservice({api_key:'HIDDEN', profile:'footwalking'),和
router: new L.Routing.openrouteservice('https:// api.openrouteservice.org /directions? & api_key = Hidden& profile = foot-walking'), 第一个可以工作,但是配置文件没有改变,它仍然使用驾驶汽车的默认配置文件。
第二个给出了两条错误消息,
第一条错误消息是|访问'https://api.openrouteservice.org/directions?‘上的XMLHttpRequestCORS策略已阻止来自源的'http://localhost:8000‘:请求的资源上不存在'Access-Control-Allow- origin’标头。|
第二条错误信息| corslite.js:87 GET https://api.openrouteservice.org/directions?403 (禁止)
这两个错误消息都给出了一个很长的url,该url被缩短为https://api.openrouteservice.org/directions?
我得到的另一个问题是,如何清除地图,以便之前绘制的路线在绘制新路线时被删除。在下面的图片中,您可以看到当我请求第二个路由时发生了什么,包括我显示的旧路由和新路由。
希望你们能帮上忙。
发布于 2020-04-03 11:44:20
打开L.Routing.OpenRouteService.js
https://stackoverflow.com/questions/53223979
复制相似问题