首页 > 解决方案 > 传单地图不显示 GeoJSON 数据

问题描述

我正在尝试在嵌入 Power Bi 网络的传单地图上渲染一些点。提交给 Leaflet 的数据是 GeoJSON 格式。当我输入此数据时,一切正常并且该点正确显示:

var someFeatures = {
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "Point",
        "coordinates": [-75, 34]
      },
      "properties": {
        "name": "Location A"
      }
    }
  ]
}

然后我尝试插入我的数据,这只是一对纬度和经度。这是我正在运行的代码片段:

function onEachFeature(feature, layer) {
        var popupContent = "<p>I started out as a GeoJSON " +
            feature.geometry.type + ", but now I'm a Leaflet vector!</p>";

        if (feature.properties && feature.properties.popupContent) {
          popupContent += feature.properties.popupContent;
        }

        layer.bindPopup(popupContent);
      }


      var dat = Visual.converter(options.dataViews[0].table.rows); //just converts the data to lat lon format

      var test = GeoJSON.parse(dat, {Point: ['lat', 'lon']}) 
        L.geoJSON([test], {
        style: function(feature) {
          return feature.properties && feature.properties.style;
        },
        onEachFeature: onEachFeature,
        pointToLayer: function(feature, latlng) {
          return L.circleMarker(latlng, {
            radius: 8,
            fillColor: "#ff7800",
            color: "#000",
            weight: 1,
            opacity: 1,
            fillOpacity: 0.8
          });
        }
      }).addTo(this.map);

我很确定数据以正确的格式转换,如开发人员控制台所示:

开发者控制台截图

任何帮助都非常感谢,因为我不知道如何解决这个问题。

编辑:浏览器控制台输出是变量“test”的内容,其中填充了以下输出:GeoJSON.parse(dat, {Point: ['lat', 'lon']}) 其中“dat”是原始数据包含纬度和经度。

标签: typescriptleafletpowerbigeojson

解决方案


推荐阅读