gpt4 book ai didi

javascript - leaflet展开控制和autoZindex

转载 作者:行者123 更新时间:2023-12-03 10:04:56 25 4
gpt4 key购买 nike

我试图保持我的传单控件展开并反转它使我的基础层的顺序。目前,控件仅在悬停时打开,并且它会自动对我的图层进行排序 2009-2015。我希望他们能够参加 2015-2009 年。

我在这里阅读了文档,http://leafletjs.com/reference.html#control-layers-l.control.layers

我知道这应该很容易通过将“collapse”和“autoZIndex”更改为 false 来完成,我做错了什么?我觉得有一个简单的解决方法......

谢谢!

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Leaflet layers control</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script type="text/javascript" src='https://api.tiles.mapbox.com/mapbox.js/v2.1.9/mapbox.js'></script>

<script type="text/javascript" src='http://code.jquery.com/jquery-2.1.4.min.js'></script>

<link href='https://api.tiles.mapbox.com/mapbox.js/v2.1.9/mapbox.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }

.legend label,
.legend span {
display:block;
float:left;
height:15px;
width:20%;
text-align:center;
font-size:9px;
color:#808080;
}
</style>
</head>
<body>
<div id='legend' style='display:none;'>
<h1 class="year"><span>Title</span></h1>
<nav class='legend clearfix'>
<span style='background:#ecfa00 ;'></span>
<span style='background:#fdda1d ;'></span>
<span style='background:#f2a80e;'></span>
<span style='background:#ff0000 ;'></span>
<span style='background:#c70606 ;'></span>
<label>#</label>
<label>#</label>
<label>#</label>
<label>#</label>
<label>#</label>
<small><a href="#">Source</a></small>
</div>
<div id='map'></div>

<script>

L.mapbox.accessToken = 'apikey_here';
var map = L.mapbox.map('map').setView([40, -96.50], 4);



map.legendControl.addLegend(document.getElementById('legend').innerHTML);



L.control.layers({
'2015': L.mapbox.tileLayer('map.m885g0j9'),
'2014': L.mapbox.tileLayer('map.m885oklp'),
'2013': L.mapbox.tileLayer('map.m889lpb4'),
'2012': L.mapbox.tileLayer('map.m88a236n'),
'2011': L.mapbox.tileLayer('map.m88an5o9'),
'2010': L.mapbox.tileLayer('map.m88aj017'),
'2009': L.mapbox.tileLayer('map.m88aa5jm').addTo(map)

} )

.addTo(map);



var controls = L.control.layers(
baseLayers, overlayLayers,
{
collapsed: false,
autoZIndex: false
}
);
controls.addTo(map);

</script>

</body>
</html>

最佳答案

因为我相信 L.Control.Layers 中的图层排序仍然是 open issue ,您需要的功能仅存在于位于 https://github.com/elesdoar/leaflet-control-orderlayers 的插件中.

其次,放下你的

var controls = L.control.layers(
baseLayers, overlayLayers,
{
collapsed: false,
autoZIndex: false
}
);
controls.addTo(map);

没有必要。您需要做的就是将选项哈希复制到第一个控件 init,例如

L.control.layers({
'2015': L.mapbox.tileLayer('map.m885g0j9'),
'2014': L.mapbox.tileLayer('map.m885oklp'),
'2013': L.mapbox.tileLayer('map.m889lpb4'),
'2012': L.mapbox.tileLayer('map.m88a236n'),
'2011': L.mapbox.tileLayer('map.m88an5o9'),
'2010': L.mapbox.tileLayer('map.m88aj017'),
'2009': L.mapbox.tileLayer('map.m88aa5jm').addTo(map)

},null, {
collapsed: false,
autoZIndex: false
} )

关于javascript - leaflet展开控制和autoZindex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30400124/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com