Openlayers自定义标记

Openlayers自定义标记,openlayers,marker,Openlayers,Marker,一些信息: 我得到了一个主图层(map),它和im用一个Linestring在从JSON结果接收到的点之间绘制线 (问题) 我在线学习了一个关于如何自定义我添加的点的示例。但这是行不通的。(查看底部的函数。) 代码: //'listOfPoints' is an array containing all the point objects. var pointmap = new OpenLayers.Geometry.LineString(listOfPoints); var las

一些信息: 我得到了一个主图层(map),它和im用一个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;
}

乍一看,临时功能定义中存在错误:

var temp_feature = new OpenLayers.Feature.Vector(
    point,
    null,
    {
        externalGraphic: '/assets/img/marker.png',
        graphicHeight: 16,
        graphicWidth: 16,
        graphicXOffset:8,
        graphicYOffset:8
    }
); 
阅读并遵循API文档非常有用:

OpenLayers.Feature.Vector接受三个参数:几何体、具有属性的对象(在您的示例中为空,因为您没有任何属性),以及具有样式的对象

我还没有测试该代码,可能还有其他问题

关于JavaScript的一般使用,从来没有

style: { externalGraphic: '/assets/img/marker.png', graphicHeight: 16,     graphicWidth: 16, graphicXOffset:8, graphicYOffset:8  }
对象始终在括号内定义:

{style: { externalGraphic: '/assets/img/marker.png', graphicHeight: 16,     graphicWidth: 16, graphicXOffset:8, graphicYOffset:8  }}

非常感谢你!我的脚本中确实有{style:{}}。但我在粘贴中出于某种原因更改了它。很抱歉所以null参数起了作用!非常感谢。