在哪里添加可见性:在openlayers代码中为false

where to add visibility: false in openlayers code?

本文关键字:代码 false openlayers 添加 可见性 在哪里      更新时间:2023-09-26

我想知道在下面的代码中我可以在哪里添加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
});

如果我没记错的话,我应该把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);