传单js中的多个航点

时间:2018-10-22 11:07:06

标签: javascript angularjs leaflet

这是我创建多个航点的代码。 我有一个纬度和经度为'n'的数组,我希望基于该纬度,经度的路线。我不想在航点中使用任何硬核数据。 在航点数组中,我想使用动态纬度和经度,该如何使用?

    var data = [

    {
        "title": 'Chennai',
        "lat": '13.0827',
        "lng": '80.2707',
        "description": '',
        "flag":'1'
    }
  ,
  {
    "title": 'Ramapuram',
    "lat": '13.0317',
    "lng": '80.1817',
    "description": ''

  }
  ,
    {
        "title": 'Kanchipuram',
        "lat": '12.8342',
        "lng": '79.7036',
        "description": '',
        "flag":'1'
    },

  ];
var map = L.map('map');

  L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
      attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
  }).addTo(map);

var routeControl = L.Routing.control({

}).addTo(map);
routeControl.setWaypoints(data);

我在这里附加了图像,这是我的输出,我的期望也是我要删除中心标记。我想在所需位置设置标记。  enter image description here

有人可以帮我吗?现在,我更新了删除航路点并使用setwaypoints函数设置航路点的代码。现在我想删除标记。

1 个答案:

答案 0 :(得分:0)

如果我理解正确,您想沿着一些航点绘制路线并仅显示起点和终点的标记。您还想阻止用户添加新的航点。创建这样的控件:

L.Routing.control({
  waypoints: yourWaypoints,
  plan: L.Routing.plan(yourWaypoints, {
    createMarker: function(i, wp, n) {
      if (i == 0 || i == n - 1) {
        return L.marker(wp.latlng, {
          draggable: false // prevent users from changing waypoint position
        });
      } else {
        return false;
      }
    }
  },
  addWaypoints: false // prevent users from adding new waypoints
});