一些信息:我有一个主层(地图),我在点之间画线,这些点是从带有 Linestring 的 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;
}