我收到了这个Openlayer问题。
我试图从一些物体中获得一堆点数。我相信这不应该是困难的。
我正在将st_astext传递给WKT阅读器以创建一个Openlayers.Geometry.Point()
要素,以添加到将保存所有行的初始图层。但这似乎不起作用。谁能看到我做错了什么?
//Routes for each bridge?
vesselPosition = new OpenLayers.Layer.Vector('Vessels');
var wkt = new OpenLayers.Format.WKT();
$.ajax({
url: "/ajax/getPositions",
dataType: 'json',
success: function(result) {
for (var reportID in result) {
//Store the object at hand.
var data = result[reportID];
//Get all the positions and print them onto the vesselpoisition layer.
var positions = data.positions;
var listOfPoints = new Array();
for (var index in positions) {
var positionData = positions[index];
var point= wkt.read(positionData.st_astext);
listOfPoints.push(point.geometry);
}
var pointmap = new OpenLayers.Geometry.LineString({points:listOfPoints});
vesselPosition.addFeatures(pointmap);
};
}
});
答案 0 :(得分:0)
OpenLayers.Geometry.LineString需要参数的点数组,而不是对象: http://dev.openlayers.org/docs/files/OpenLayers/Geometry/LineString-js.html#OpenLayers.Geometry.LineString.OpenLayers.Geometry.LineString
答案:投影问题:
point.geometry.transform(
new OpenLayers.Projection("EPSG:4326"),
new OpenLayers.Projection("EPSG:900913")
);
所以试试
var pointmap = new OpenLayers.Geometry.LineString(listOfPoints);
也要注意
vesselPosition.addFeatures(pointmap);
addFeatures()需要特征,而不是参数的几何。使用:
vesselPosition.addFeatures(new OpenLayers.Feature.Vector(pointmap));
出于测试目的,您可以绘制单个点来映射:
var point= wkt.read(positionData.st_astext);
vesselPosition.addFeatures(point);
另外,检查vesselPosition.features.length以确定是否有任何功能。