0

我正在尝试设置 LineString 的样式,但它似乎不起作用。这是我的代码:

function connectStationFeatures(feat1, feat2){
    var lineLayer = getLinesLayer();
    var point1 = feat1.geometry;
    var point2 = feat2.geometry;
    var style = new OpenLayers.StyleMap({
        'fillColor':"#FF8C00",
        'strokeWidth':10,
        'strokeDashstyle':"dashdot"
    });
    var line = new OpenLayers.Geometry.LineString([point1, point2]);

    lineLayer.addFeatures([new OpenLayers.Feature.Vector(line, {styleMap:style})]);
}

或者我试过:

function connectStationFeatures(feat1, feat2){
    var lineLayer = getLinesLayer();
    var point1 = feat1.geometry;
    var point2 = feat2.geometry;
    var style = new OpenLayers.StyleMap({
        'fillColor':"#FF8C00",
        'strokeWidth':10,
        'strokeDashstyle':"dashdot"
    });
    var line = new OpenLayers.Geometry.LineString([point1, point2]);
    var lineFeat = new OpenLayers.Feature.Vector(line);
    lineFeat.styleMap = style;
    lineLayer.addFeatures([lineFeat]);
 }

非常感谢任何帮助!谢谢

4

1 回答 1

1

您必须将 StyleMap 添加到图层,而不是功能

vectorLayer = new OpenLayers.Layer.Vector('Foo', {styleMap: style});

http://jsfiddle.net/HqQ6V/

有几种不同的方式来定义样式 - 使用 hash、Style 或 StyleMap 对象;您可以将它们附加到要素或图层。这是很好的解释:http ://docs.openlayers.org/library/feature_styling.html

于 2012-12-11T08:51:33.550 回答