使用Firebase数据库加载mapbox

使用Firebase数据库加载mapbox,firebase,firebase-realtime-database,mapbox,geojson,Firebase,Firebase Realtime Database,Mapbox,Geojson,我正在尝试学习Firebase和Mapbox,并希望将两者结合起来。Firebase以以下格式存储我的一些数据: { "messages" : { "-KUE2EwfvbI48Azw01Hv" : { "geometry" : { "coordinates" : [ 28.6618976, 77.22739580000007 ], "type" : "Point" }, "properties" : {

我正在尝试学习Firebase和Mapbox,并希望将两者结合起来。Firebase以以下格式存储我的一些数据:

{
  "messages" : {
    "-KUE2EwfvbI48Azw01Hv" : {
      "geometry" : {
        "coordinates" : [ 28.6618976, 77.22739580000007 ],
        "type" : "Point"
      },
      "properties" : {
        "description" : "xyz",
        "hashtag" : "#xyz",
        "imageUrl" : "xyz.jpg",
        "name" : "Xyz Xyz",
        "photoUrl" : "xyz.jpg",
        "title" : "XYZ"
      },
      "type" : "Issue"
    },
    "-KUD2EwfvbI48Azw01Hv" : {
      "geometry" : {
        "coordinates" : [ 12.9715987, 77.59456269999998 ],
        "type" : "Point"
      },
      "properties" : {
        "description" : "xyz",
        "hashtag" : "#xyz",
        "imageUrl" : "xyz.jpg",
        "name" : "Xyz Xyz",
        "photoUrl" : "xyz.jpg",
        "title" : "XYZ"
      },
      "type" : "Issue"
    }
  }
}
是否有方法加载数据并将其打印到Mapbox中?这些示例需要一个托管在某个地方的GeoJSON文件,该文件可用于绘制它们。我们如何使用Firebase数据库在Mapbox上实时绘图

对不起,如果我的问题模棱两可。如果需要,我愿意提供更多信息:D


谢谢

您可以加载数据,但首先必须将其转换为有效的GeoJSON对象

下面是一个使用您提供的数据的JSFIDLE:

var firebaseGeojsonFeatures = [];
for (var key in firebaseData.messages) {
  var f = firebaseData.messages[key];
  f.type = "Feature";
  firebaseGeojsonFeatures.push(f);
}