[英]How can i make so that when a layer is added to a map it is added as the bottom layer in OpenLayers 3?
我试图找出一种切换映射类型并将该层添加为底层的好方法。 其他层是应该始终位于最上面的信息层。 我尝试使用map.baseLayer属性,但是该层仍呈现在其他层之上。
这是我得到的:
var OSMLayer = new ol.layer.Tile({
source: new ol.source.OSM()
});
// Initial map
var currentMap = OSMLayer;
var mapQuestOSMLayer = new ol.layer.Tile({
source: new ol.source.MapQuest({layer: 'osm'})
});
var mapQuestSATLayer = new ol.layer.Tile({
source: new ol.source.MapQuest({layer: 'sat'})
});
var mapQuestHYBLayer = new ol.layer.Tile({
source: new ol.source.MapQuest({layer: 'hyb'})
});
var map = new ol.Map({
layers: [OSMLayer],
target: document.getElementById('map-canvas'),
view: new ol.View({
center: [0, 0],
zoom: 3
})
});
// How can i set the layer as the bottom layer?
$('#btnMapTypes ul.dropdown-menu li a').click(function (e) {
map.removeLayer(currentMap);
switch($(this).attr('data-type')){
case 'OSM':
map.addLayer(OSMLayer);
map.baseLayer = OSMLayer;
currentMap = OSMLayer;
break;
case 'mapQuestOSM':
map.addLayer(mapQuestOSMLayer);
map.baseLayer = mapQuestOSMLayer;
currentMap = mapQuestOSMLayer;
break;
case 'mapQuestSAT':
map.addLayer(mapQuestSATLayer);
map.baseLayer = mapQuestSATLayer;
currentMap = mapQuestSATLayer;
break;
case 'mapQuestHYB':
map.addLayer(mapQuestHYBLayer);
map.baseLayer = mapQuestHYBLayer;
currentMap = mapQuestHYBLayer;
break;
}
});
寻找所需结果的正确方法是什么? 谢谢!
如果您在地图上执行getLayers,则会得到一个集合,该集合具有操纵顺序的功能,例如insertAt(或setAt取决于您的需要): http ://openlayers.org/en/v3.8.2/apidoc/ol .Collection.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.