gpt4 book ai didi

javascript - 样式 : color and strokewidth in Openlayers?

转载 作者:行者123 更新时间:2023-11-30 13:28:13 25 4
gpt4 key购买 nike

我尝试了一些方法,但似乎找不到合适的方法,
我如何向这一层添加样式:

        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;

然后在创建矢量图层时将其传递到选项中:

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
})
})
});

关于javascript - 样式 : color and strokewidth in Openlayers?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7768644/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com