如何在传单中以 GeoJSON 或折线中点的形式检索 mapquest 提供的所有可能的路径方向请回复

如何解决如何在传单中以 GeoJSON 或折线中点的形式检索 mapquest 提供的所有可能的路径方向请回复

我已经尝试了所有方法,但找不到任何解决方案。我使用了 mapquest 并且能够显示带有源和目的地之间所有可能路线的地图。请回复

`#index.html

<!DOCTYPE html>
<html lang="en">
<head>
<Meta charset="UTF-8">
<Meta http-equiv="X-UA-Compatible" content="IE=edge">
<Meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Map Routes</title>
<link rel="stylesheet" 
href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/leaflet.css">
<link rel="stylesheet" href="CSS/style.css">
<!--<link href="/favicon.ico" type="image/x-icon" rel="icon" />-->
<script src="./lib/leaflet-measure.css"></script>
<script src="./lib/leaflet-measure.js"></script>
</head>
<body style="border:0;margin:0">
<div id="map"></div>
<div class="formBlock">
<form id="form">
    <input type="text" name="start" class="input" id="start"  
placeholder="Choose starting point"/>
    <input type="text" name="end" class="input" id="destination"   
placeholder="Choose destination point"/><br><br>
<button type="submit"> Get Deractions</button>
</form>
</div>
<script 
src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/leaflet.js"> 
</script>
<script src="https://www.mapquestapi.com/sdk/leaflet/v2.2/mq-map.js? 
key=mapquest key"></script>
<script src="https://www.mapquestapi.com/sdk/leaflet/v2.2/mq-routing.js? 
key=mapquest key"></script>
<script src="app.js"></script>    
</body>
</html>
<script>
</script>

#app.js

let map = L.map('map',{
layers: MQ.mapLayer(),center: [35.791188,-78.636755],zoom: 12
});


function runDirection(start,end) {
  
  // recreating new map layer after removal
  map = L.map('map',{
      
      layers: MQ.mapLayer(),zoom: 12
  });
  
  var dir = MQ.routing.directions();

 

  dir.route({
    maxRoutes: 5,timeOverage: 25,locations: [
        
          start,end
      ]
  });


  CustomrouteLayer = MQ.Routing.RouteLayer.extend({
      createStartMarker: (location) => {
          var custom_icon;
          var marker;

          custom_icon = L.icon({
              iconUrl: 'img/red.png',iconSize: [40,35],iconAnchor: [20,29],popupAnchor: [0,-29]
          });

          marker = L.marker(location.latLng,{icon: 
custom_icon}).addTo(map);

          L.control.scale(
          ).addTo(map);
         
          


          return marker;
      },createEndMarker: (location) => {
          var custom_icon;
          var marker;

          custom_icon = L.icon({
              iconUrl: 'img/blue2.png',iconSize: [25,{icon: 
custom_icon}).addTo(map);

          return marker;
      }
  });
  
  map.addLayer(new CustomrouteLayer({
      directions: dir,fitBounds: true
  })); 
}


// function that runs when form submitted
function submitForm(event) {
event.preventDefault();

// delete current map layer
map.remove();

// getting form data
start = document.getElementById("start").value;
end = document.getElementById("destination").value;

// run directions function
runDirection(start,end);

// reset form



//document.getElementById("form").reset();



//leaflet measure

L.control.measure({
primaryLengthUnit: 'kilometers',secondaryLengthUnit: 'meter',primaryAreaUnit: undefined
}).addTo(map);


}

// asign the form to form variable
const form = document.getElementById('form');

// call the submitForm() function when submitting the form
form.addEventListener('submit',submitForm);`

现在我想要进入 GeoJson 点或折线形式的方向。如果有什么办法请回复

这是示例输出

解决方法

最简单的方法是从路线请求中获取折线,而不是在放置后从地图中获取形状。 MapQuest.js L.mapquest.directions.route 函数具有可用于此目的的回调。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?