我试图在地图中添加带有自定义图形的标记,但是我收到以下错误:
TypeError:' undefined'不是一个对象(评估' vectorLayer.addFeatures')
我添加标记的代码如下所示
function addMarker(id, lat, lon, orientation){
var ll = new OpenLayers.LonLat(Lon2Merc(lon), Lat2Merc(lat));
var point = new OpenLayers.Geometry.Point(ll.lon, ll.lat);
var style_mark = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']);
style_mark.graphicWidth = 24;
style_mark.externalGraphic = "/icons/myicon.png";
var feature = new OpenLayers.Feature.Vector(point, null, style_mark);
vectorLayer.addFeatures([ feature ]);
}
我初始化了'vectorLayer'像这样:
vectorLayer = new OpenLayers.Layer.Vector( 'Vector Layer', { styleMap: olStyleMap });
map.addLayer( vectorLayer );
对我而言,vectorLayer
看起来没有名为addFeatures的方法。我通过组合this和this(Openlayer示例代码)来组装我的代码。实际的exmaple代码确实有很多开销,但我不确定哪个部分可以省略。我很乐意帮助你。