在openlayers代码中添加可见性:false的位置?

时间:2011-10-08 23:33:54

标签: javascript openlayers openstreetmap

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

1 个答案:

答案 0 :(得分:4)

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