MAPBOX如何绘制多条线条并改变颜色

时间:2014-05-16 01:16:27

标签: javascript mapbox

我想使用MapBox地图(javascript API)在地图上绘制多种颜色的路线, 每种颜色都意味着不同的运输方式,例如: 1)公共汽车 2)车 3)火车

我发现此代码为例: https://www.mapbox.com/mapbox.js/example/v1.0.0/leaflet-draw/

希望有人可以提供建议。

感谢J.Rico

1 个答案:

答案 0 :(得分:0)

我建议使用mapbox api中的折线功能,你需要提供一组构成你的路线的(纬度,经度),这里有一些片段您可以在地图框中帮助您的代码,您可以在 mapbox api网站中see reference

  1. 路线的点数组

    // Create array of lat,lon points
    var line_points = [
       [38.893596444352134, -77.0381498336792],
       [38.89337933372204, -77.03792452812195],
       [38.89316222242831, -77.03761339187622],
       [38.893028615148424, -77.03731298446655],
       [38.892920059048464, -77.03691601753235],
       [38.892903358095296, -77.03637957572937],
       [38.89301191422077, -77.03592896461487],
       [38.89316222242831, -77.03549981117249],
       [38.89340438498248, -77.03514575958252],
       [38.893596444352134, -77.0349633693695]
    ];
    
  2. 选择您想要的颜色

    // Define polyline options
    // http://leafletjs.com/reference.html#polyline
    var polyline_options = {
       color: '#000'
    };
    
  3. 绘制路线

    // Defining a polygon here instead of a polyline will connect the
    // endpoints and fill the path.
    // http://leafletjs.com/reference.html#polygon
    var polyline = L.polyline(line_points, polyline_options).addTo(map);
    
  4. 祝你好运。

相关问题