我正在使用 KineticJS 在 HTML5 画布上创建交互式地图,问题是我的地图数据在 geoJSON 中,所以我有多边形坐标而不是多边形点。
这就是我对多边形点的处理方式(根据本教程)
//Javascript object with map data
var myMap = {
'Russia': {
points: [44,1,397,1,518,2,518,151,515,..............6,43,4,43,4]
},
'Azerbaijan': {
points: [198, 242, 201, 245, 203,..............197, 242]
},
'UAE': {
points: [224,406,225,410,...............225,407]
}
};
//Function to return map data
function getData() {
return myMap;
}
然后使用 KineticJS 多边形对象在 HTML5 画布上绘制地图。
//store map data in a variable
var areas = getData();
//Loop through the map
for (var key in areas) {
(function () {
var k = key;
var area = areas[key];
var points = area.points;
var shape = new Kinetic.Polygon({
points: points,
fill: '#fff',
stroke: '#555',
strokeWidth: .5,
alpha: 0.1
});
} ());
}
有人知道我如何使用 geoJSON 坐标实现相同的目标吗?这是 geoJSON 的示例。坐标嵌套在几何对象内。
{
"type": "FeatureCollection",
"features": [{ "type": "Feature", "id": 0,
"properties": { "OBJECTID_1": 29, "OBJECTID": 29, "COUNTY_NAM": "BARINGO", "COUNTY_COD": 30, "Shape_Leng": 5.81571392065, "Shape_Area": 0.88451236881 },
"geometry": { "type": "Polygon", "coordinates": [ [ [ 36.028686523000033, 1.276123047000056 ], [ 36.036499023000033, 1.263916016000053 ], [ 36.039306641000053, 1.259887695000032 ],............[ 36.028686523000033, 1.276123047000056 ] ] ] } }
]
}