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 に答える