2

我试图弄清楚如何将 lon/lat 坐标上的 GeoJSON 列表加载到MapBox地图中。我想我已经接近了,我似乎无法让它真正发挥作用。

我在这里设置了一个演示页面:http: //sandbox.charliehield.com/mapbox/

这是 GeoJSON 文件:

{
  "type": "MultiPoint",
  "coordinates": [
    [
      "-105.277803",
      "40.006977"
    ],
    [
      "-93.304988",
      "44.947198"
    ],
    [
      "151.206990",
      "-33.867487"
    ]
  ]
}

HTML 很简单:

<div id="map"></div>

和 JS:

var map = mapbox.map('map');
map.addLayer(mapbox.layer().id('examples.map-zr0njcqy'));
map.ui.zoomer.add();

// example.geojson is a well-formed GeoJSON document. For this
// style, the file must be on the same domain name as the map,
// or loading will not work due to cross-domain request restrictions

var markers = mapbox.markers.layer().url('markers.geojson');
mapbox.markers.interaction(markers);
map.addLayer(markers);

// Zoom and center the map
map.zoom(2).center({ lat: 39.74739, lon: -105 });
4

2 回答 2

2

geometry看起来您需要使用对象和键值对更明确地格式化您的 geojson 。请参阅http://mapbox.com/mapbox.js/example/custom-marker-tooltip作为示例。

于 2013-02-26T05:06:20.020 回答
0

我在将 geojson 加载到我的 mapbox 地图时遇到了同样的问题。JS中的注释其实指出了原因:存在跨域请求限制。

您可以检查相同的来源策略,并希望在其他地方运行应用程序。

于 2014-10-20T02:56:58.307 回答