2011-10-14 100 views
1

我嘗試了一些方法,但不能似乎找到合適的一個,
哪有我的廣告樣式到這一層:風格:Openlayers中的顏色和strokewidth?

 var line_1 = new OpenLayers.Layer.Vector("Line nr 1", { 
      projection: map.displayProjection, 
      strategies: [new OpenLayers.Strategy.Fixed()], 
      protocol: new OpenLayers.Protocol.HTTP({ 
       url: "lines/line_1.kml", 
       format: newOpenLayers.Format.KML({ 
        extractStyles: true, 
        extractAttributes: true 
       }) 
      }) 
     }); 

就像在下面的層:

  var line_1 = new OpenLayers.Layer.GML('Line nr - 1', 
        "lines/line_1.kml", 
        { 
          visibility: true, 
          format: OpenLayers.Format.KML, 
          style: {strokeWidth: 4, strokeColor: "#ff0000", strokeOpacity: 1 }, 
          projection: map.displayProjection, 
          strategies: [new OpenLayers.Strategy.Fixed()] 
        } 
      ); 

的不同的是,在第一個變量我使用矢量和在第二GML
我仍然是這個東西的初學者,一個倪的幫助將非常感激。

回答

3

可以定義風格是這樣的:

var style = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']); 
style.fillOpacity = 0.2; 
style.graphicOpacity = 1; 
style.strokeWidth = 4; 
style.strokeColor = "#ff0000"; 
style.strokeOpacity = 1; 

然後當你創建矢量層傳遞的選項:

var line_1 = new OpenLayers.Layer.Vector("Line nr 1", { 
      style : style, 
      projection: map.displayProjection, 
      strategies: [new OpenLayers.Strategy.Fixed()], 
      protocol: new OpenLayers.Protocol.HTTP({ 
       url: "lines/line_1.kml", 
       format: newOpenLayers.Format.KML({ 
        extractStyles: true, 
        extractAttributes: true 
       }) 
      }) 
     });