如何使用GeoJSON将线串/折线添加到自定义MapBox模板

时间:2013-11-06 18:12:09

标签: jquery foursquare leaflet geojson mapbox

我目前正在修改MapBox中的商店定位器模板: https://github.com/mapbox/foursquare-store-locator https://www.mapbox.com/blog/foursquare-store-locator/

问题在于在这个修改后的框架中添加了一个线串/折线。

例如,我无法使用以下格式添加带有线串GeoJSON数据的新地图图层:

L.map('map').

我可以使用leafllet.js来处理线串:


http://jsfiddle.net/xpancom/hUy5g/16/


...但这会利用“L”。来自leaflet.js并且在修改后的MapBox模板中不起作用。

L.geoJson(myLine1, {style: myStyle}).addTo(map);

问题是来自MapBox的修改后的商店定位器应用程序似乎没有实现这个相同的界面。

这是我当前的代码,它尝试添加具有线串的图层:

foursquare.lines = function() {

  var lines = { 'type': 'FeatureCollection',
        'features': []
    };

lines.features.push({
            type: 'Feature',
           // id: venue.id,
            geometry: {
                type: 'LineString',
                coordinates: [[
            60.317769,
            24.929009
          ],
          [
            24.9292486208828,
            60.1681323558666
          ],
          [
            24.951764345169067,
            60.168932342858554
          ],
          [
            24.93321418762207,
            60.16911913731421
          ],
          [
            24.952929,
            60.167312
          ],
          [
            24.944114685058594,
            60.170111798603266
          ],
          [
            24.94499444961548,
            60.171435300334004
          ]]
            },
            properties: {}

        }); //push

//console.log(lines);

if (MM_map.lineLayer) {
        MM_map.lineLayer.geojson(lines);
        alert("hi");
    } else {
        MM_map.lineLayer = mmg().geojson(lines);
        //alert("hello");
        console.log(lines);
    }

 MM_map.addLayer(MM_map.lineLayer);

  }; //foursquare.lines

图层被添加为空div,但geojson和lines对象不会被处理,也不显示。

当我运行console.log(行)时,我正确获取了所有geojson数据,但是没有使用此行添加:

mmg().geojson(lines)

我真的对此有任何帮助。感谢

1 个答案:

答案 0 :(得分:1)

foursquare商店定位器示例基于MapBox.js v0.6.7,而您尝试使用v1.x及更高版本的代码。您需要查阅v0.6.7文档,或者从不同的起点开始,这是我建议的 - 例如,请参阅the MapBox.js examples