如果它不是一个问题,那就是另一个问题。 我整天都在看这个,不知道这里出了什么问题。 我又有一张包含两层的地图,一个县图层和一个 msa 图层。 我在页面上有两个链接,一个说县,另一个说msa。 单击任一链接时,我想关闭地图的一个图层并显示在正确的图层上。 以下是点击事件:
$('.map-type-link').live('click', function () {
params.display_region_type = parseInt($(this).attr('region_type'));
if (params.display_region_type == 1) {
app.currentFl = app.featureLayers[0];
}
else {
app.currentFl = app.MSAfl;
app.flVis.setVisibility(false);
app.MSAfl.setVisibility(true);
app.currentFl.redraw();
}
});
不仅单击县,app.flvis仍然可见。
创建要素图层的位置:
dojo.forEach(app.layersUrls, function (info, idx) {
app.featureLayers[idx] = new esri.layers.FeatureLayer(
app.layersUrls[idx], {
mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
outFields: app.outFields[idx],
opacity: 0.80
}
);
app.featureLayers[idx].setRenderer(br);
//create min and max scales when layers load
dojo.connect(app.featureLayers[idx], 'onLoad', function () {
app.featureLayers[idx].minScale = app.layerScales[idx].min;
app.featureLayers[idx].maxScale = app.layerScales[idx].max;
});//ends connections
//add THIS feature layer to the map
app.map.addLayer(app.featureLayers[idx]);
(
我假设你所有的变量是什么意思。
若要打开 MSA 层,您需要四行代码(在 else 语句中):
app.currentFl = app.MSAfl;
app.flVis.setVisibility(false);
app.MSAfl.setVisibility(true);
app.currentFl.redraw();
在 if 语句中,您只有一行代码,一行不会打开或关闭任何层:
app.currentFl = app.featureLayers[0];
相反,我认为您需要遵循您在 else 语句中所做的示例:
app.currentFl = app.flVis;
app.MSAfl.setVisibility(false);
app.flVis.setVisibility(true);
app.currentFl.redraw();
这假设 app.flVis 是您的县图层,情况可能是这样,也可能不是这样。