いくつかの情報:メインレイヤー(マップ)を取得し、ラインストリングを使用してJSON結果から受け取ったポイント間に線を描画します。
(問題) 追加するポイントをカスタマイズする方法について、オンラインの例に従いました。しかし、これはうまくいきません。(一番下の関数を見てください。)
コード:
//'listOfPoints' is an array containing all the point objects.
var pointmap = new OpenLayers.Geometry.LineString(listOfPoints);
var lastpoint = listOfPoints[listOfPoints.length -1];
var vesselLayer = new OpenLayers.Layer.Vector(data.bridge_name);
if (lastpoint != null) {
var markerLayer = getPOI(lastpoint);
vesselLayer.addFeatures([pointmap,markerLayer]);
} else {
vesselLayer.addFeatures([new OpenLayers.Feature.Vector(pointmap)]);
}
// Function for creating a marker and returning it to the caller.
function getPOI(point) {
//This was also tried without the "Style" property. (Only the externalGraphic line)
var temp_feature = new OpenLayers.Feature.Vector(
point,
style: { externalGraphic: '/assets/img/marker.png', graphicHeight: 16, graphicWidth: 16, graphicXOffset:8, graphicYOffset:8 }
);
return temp_feature;
}