使用Jquery我正在初始化代码,该代码读取我的XML文件。
我的问题是它在一个长的传单路由中读取我的所有节点(点),并且我想将它分成两个路由,因为我在我的XML文件中有两次旅行。
var map = L.map('map');
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(map);
var waypoints = [];
$(xml).find("Trip").each(function () {
$(xml).find("point").each(function () {
var lat = $(this).find("lat").text();
var lng = $(this).find("long").text();
waypoints.push(L.latLng(lat, lng));
L.Routing.control({
plan: L.Routing.plan(waypoints, {
geocoder: L.Control.Geocoder.nominatim(),
draggableWaypoints: false
}),
addWaypoints: false,
useZoomParameter: false,
lineOptions: {
styles: [{ color: "lightgreen", opacity: 1, weight: 5 }]
}
}).addTo(map)
});
});
L.Routing.errorControl(control).addTo(map);
带路线目的地的MY XML:
<?xml version="1.0" encoding="utf-8" ?>
<destinations>
<Trip>
<LineColor>blue</LineColor>
<point DriverNumber="11" name="Trip 1 start">
<lat>56.260919</lat>
<long>10.057587</long>
<type>Start</type>
</point>
<point DriverNumber="11" name="Trip 1 Destination">
<lat>56.269234</lat>
<long>10.00925</long>
<type>Destination</type>
</point>
</Trip>
<Trip>
<LineColor>blue</LineColor>
<point DriverNumber="22" name="Trip 2 Sabro">
<lat>56.211349</lat>
<long>10.022631</long>
<type>Start</type>
</point>
<point DriverNumber="22" name="Trip 2 Lyngballevej">
<lat>56.222799</lat>
<long>9.957336</long>
<type>Start</type>
</point>
<point DriverNumber="22" name="Trip 2 Anbæk">
<lat>56.234538</lat>
<long>9.859930</long>
<type>Destination</type>
</point>
</Trip>
</destinations>