2011-10-08 14 views
0

我想知道我在哪裏可以添加知名度:假在下面的代碼: 就像在第二個代碼?在openlayers代碼中增加可見性: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 
}); 
+0

嘗試使用GML上的'setVisibility()'。 http://dev.openlayers.org/docs/files/OpenLayers/Layer/GML-js.html#OpenLayers.Layer.GML.setVisibility – Smamatti

+0

對不起,但我不知道應該放在哪一行。 !? –

+0

在你的變量line_10聲明後面的代碼之外。我不能在這裏測試它,但我想這應該工作:'line_10.setVisibility(false);' – Smamatti

回答

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); 
+0

你救了我!添加 .setVisibility(false);到我的每個基層對加載有巨大的性能影響。 – luca76