[英]style: color and strokewidth in Openlayers?
我試過一些方法,但似乎找不到合適的方法,
如何為此圖層添加樣式:
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()]
}
);
差異在於第一個變量Im使用Vector和第二個GML
我仍然是這個東西的初學者,任何幫助將非常感激。
您可以像這樣定義樣式:
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;
然后在創建Vector圖層時將其傳遞給選項:
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
})
})
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.