样式:Openlayers 中的颜色和描边宽度?

发布于 2024-12-10 01:23:58 字数 1172 浏览 1 评论 0原文

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

        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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧人 2024-12-17 01:23:58

您可以这样定义样式:

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

You can define style like this:

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;

And then pass it in the options when you create Vector layer:

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
                })
            })
        });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文