1

我有一个 geoJSON 文件,其中包括:

{
"type": "FeautureCollection",
"features": [
    {
        "type": "Feature",
        "id": "1",
        "geometry": {
            "type": "Point",
            "coordinates": [
                5.709531,
                50.855802
            ]
        }
    },
    {
        "type": "Feature",
        "id": "2",
        "geometry": {
            "type": "Point",
            "coordinates": [
                5.709426,
                50.855798
            ]
        }
    }
]
}

这个 JSON 文件是在一个 php 脚本中构建的:

$ret = array();
$ret['type'] = "FeautureCollection";
$ret['features'] = array();

$f = array();
$f['type'] = 'Feature';
$f['id'] = $p['id'];
$f['geometry'] = array();
$f['geometry']['type'] = 'Point';
$f['geometry']['coordinates'] = array(floatval($p['lat']), floatval($p['lon']));
  $ret['features'][] = $f;

echo json_encode($ret);

当我尝试通过 polymaps.org 框架加载它时,没有显示任何点。除了加载地图的标准内容外,我还使用此 javascript 来解析 geoJSON。

map.add(po.geoJson()
.url('geojson/c.geo.php')
.id('test')
);

CSS如下,所以点应该看起来像一个红圈:

#test {
      fill: lightcoral;
      fill-opacity: .5;
      stroke: brown;
    }

奇怪的是,当我将 geojson 文件指针更改为由 GIS 应用程序构建的文件时,它可以工作。所以我敢打赌我的 geoJSON 已损坏。但是当我通过http://jsonlint.com/运行它时,它会验证。

有谁知道这怎么可能?

4

1 回答 1

0

不确定,但我想我曾经在另一个框架中遇到过同样的问题:http://leaflet.cloudmade.com/

就我而言,这是一个视图位置问题(例如:您的功能在美国,但您的地图显示非洲)。同样在 cloudmade-leaflet 中,他们使用纬度-经度而不是经度-纬度。

您可以检查您的地图是否查看了正确的区域。

于 2012-06-04T00:13:35.563 回答