样式: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()]
}
);
区别在于第一个变量中使用 Vector ,第二个变量中使用 GML
我仍然是这方面的初学者,任何帮助将不胜感激。
I tried some ways but cant seem to find the proper one,
How can I ad a style to this layer:
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
})
})
});
Just like in the layer below:
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()]
}
);
The differences are that in the first variable Im using Vector and in the second GML
Im still a beginner in this stuff, any help would be really appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以这样定义样式:
然后在创建矢量图层时将其传递到选项中:
You can define style like this:
And then pass it in the options when you create Vector layer: