0

我得到了这个 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);

};
}
});
4

1 回答 1

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 以确定是否有任何特征。

于 2012-12-06T17:43:34.097 回答