【问题标题】:Mapbox - new L.markers on top of mapMapbox - 地图顶部的新 L.markers
【发布时间】:2018-07-08 03:00:35
【问题描述】:

我正在尝试绘制 USGS 地震数据,但遇到了一个非常奇怪的问题。我的查询获取所有结果并绘制第一个结果,但其余结果附加在地图顶部。

function getEarthquakes(){
    jQuery.ajax({
        type: "GET",
        dataType: "json",
        url: "data/earthquakes-today.json",
        error: function (err) { console.log(err)},
        success: function (results, status, xhr) {
            jQuery(results.features).each(function(index, i) {
                L.marker([i.geometry.coordinates[0], i.geometry.coordinates[1]]).bindPopup(i.geometry.coordinates[0]+", "+i.geometry.coordinates[1]).addTo(map);
            });
        }
    })
}

知道是什么原因造成的吗?没有控制台日志错误,当我 console.log 得到结果时:

【问题讨论】:

    标签: jquery json leaflet mapbox


    【解决方案1】:

    正如Plotting geojson points in html 中所述,您只是按错误的顺序使用坐标。

    鉴于您显示的数据,您似乎在results 中收到了一组 GeoJSON 功能。在这种情况下,您可以直接将其输入L.geoJSON factory,它会在内部为您反转坐标顺序:

    L.geoJSON(results).addTo(map)
    

    否则,请确保您自己反转它们:

    //        [latitude                 , longitude]
    L.marker(([i.geometry.coordinates[1], i.geometry.coordinates[0]])
    

    【讨论】:

      猜你喜欢
      • 2021-10-02
      • 2015-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多