Reputation: 3963
I'm trying to style a LineString, but it doesn't seem to work. This is my code:
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})]);
}
Alternatively I tried:
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]);
}
Any help is greately appreciated! THX
Upvotes: 0
Views: 2761
Reputation: 1658
You have to add StyleMap to layer, not to feature
vectorLayer = new OpenLayers.Layer.Vector('Foo', {styleMap: style});
There are several different ways to define style - with hash, Style or StyleMap objects; you can attatch them to feature or to layer. This is quite good explanation: http://docs.openlayers.org/library/feature_styling.html
Upvotes: 1