在 openlayers 代码中添加visibility: false 的位置?

发布于 2024-12-09 00:24:57 字数 784 浏览 0 评论 0原文

我想知道在下面的代码中哪里可以添加 visibility: false : 就像第二个代码一样?

var line_10 = new OpenLayers.Layer.GML("Line nr-10", 
    "lines/line_10.kml",
    {
        format: OpenLayers.Format.KML,
        style: {strokeWidth: 4, strokeColor: "#f08080", fillOpacity: 1 },
        projection: map.displayProjection
    }
);

第二个代码:

var linja4_2 = new OpenLayers.Layer.Vector("Line nr-4 stations", {
    projection: map.displayProjection,
    strategies: [new OpenLayers.Strategy.Fixed()],
    protocol: new OpenLayers.Protocol.HTTP({
        url: "/data/linja-nr4.kml",
        format: new OpenLayers.Format.KML({
            extractStyles: true,
            extractAttributes: true
        })
    }),
    visibility: false
});

I wanted to know where can I add visibility: false in the code below:
Just like in second code ?

var line_10 = new OpenLayers.Layer.GML("Line nr-10", 
    "lines/line_10.kml",
    {
        format: OpenLayers.Format.KML,
        style: {strokeWidth: 4, strokeColor: "#f08080", fillOpacity: 1 },
        projection: map.displayProjection
    }
);

Second Code:

var linja4_2 = new OpenLayers.Layer.Vector("Line nr-4 stations", {
    projection: map.displayProjection,
    strategies: [new OpenLayers.Strategy.Fixed()],
    protocol: new OpenLayers.Protocol.HTTP({
        url: "/data/linja-nr4.kml",
        format: new OpenLayers.Format.KML({
            extractStyles: true,
            extractAttributes: true
        })
    }),
    visibility: false
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

千秋岁 2024-12-16 00:24:57

如果我没记错的话,我会将 visibility 放在这里:

var line_10 = new OpenLayers.Layer.GML("Line nr-10", 
    "lines/line_10.kml",
    {
        format: OpenLayers.Format.KML,
        style: {strokeWidth: 4, strokeColor: "#f08080", fillOpacity: 1 },
        projection: map.displayProjection
    }, {
        visibility: false
    }
);

或者按照评论中的建议:

var line_10 = new OpenLayers.Layer.GML("Line nr-10", 
    "lines/line_10.kml",
    {
        format: OpenLayers.Format.KML,
        style: {strokeWidth: 4, strokeColor: "#f08080", fillOpacity: 1 },
        projection: map.displayProjection
    }
);
line_10.setVisibility(false);

If I remember correctly I would put the visibility here:

var line_10 = new OpenLayers.Layer.GML("Line nr-10", 
    "lines/line_10.kml",
    {
        format: OpenLayers.Format.KML,
        style: {strokeWidth: 4, strokeColor: "#f08080", fillOpacity: 1 },
        projection: map.displayProjection
    }, {
        visibility: false
    }
);

Or as suggested in the comments:

var line_10 = new OpenLayers.Layer.GML("Line nr-10", 
    "lines/line_10.kml",
    {
        format: OpenLayers.Format.KML,
        style: {strokeWidth: 4, strokeColor: "#f08080", fillOpacity: 1 },
        projection: map.displayProjection
    }
);
line_10.setVisibility(false);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文