admin管理员组文章数量:1355026
I have a Leaflet.js map, with a base tile layer, a label tile layer, and some overlays. I need to put the label tile layer ABOVE the overlays. I tried bringing it to front using bringToFront()
- for no avail.
Here's the code:
map.addLayer( new L.StamenTileLayer("toner-lines") );
...// more code, loading the overlays, etc
var labels = L.tileLayer('http://{s}.www.toolserver/tiles/osm-labels-en/{z}/{x}/{y}.png', {
maxZoom: 17,
zIndex: 1000
});
labels.addTo(map);
labels.bringToFront();
I have a Leaflet.js map, with a base tile layer, a label tile layer, and some overlays. I need to put the label tile layer ABOVE the overlays. I tried bringing it to front using bringToFront()
- for no avail.
Here's the code:
map.addLayer( new L.StamenTileLayer("toner-lines") );
...// more code, loading the overlays, etc
var labels = L.tileLayer('http://{s}.www.toolserver/tiles/osm-labels-en/{z}/{x}/{y}.png', {
maxZoom: 17,
zIndex: 1000
});
labels.addTo(map);
labels.bringToFront();
Share
Improve this question
asked Nov 12, 2013 at 20:50
Michael Bar-SinaiMichael Bar-Sinai
2,73921 silver badges28 bronze badges
2
-
My guess is that the
bringToFront()
is bringing it to the front of the Tile Layer, which is still below the Overlay layer. Would you mind creating a jsFiddle replicating the problem so that could be confirmed and a workaround made? – Josh Commented Nov 13, 2013 at 4:43 - As per @Josh's advice, here's the JSFiddle: jsfiddle/michbarsinai/M29Dk/2 – Michael Bar-Sinai Commented Nov 13, 2013 at 15:17
2 Answers
Reset to default 5The problem is that the entire Tile Layer stack is drawn under the entire Overlay Layer stack and the bringToFront
and sendToBack
mands only affect layers within each respective stack. There is a bug report detailing this on Leaflet's github site. It might be fixed in 0.7, but it has already been pushed back a couple of times.
In that bug report, they reference a workaround by jfirebaugh. That should do what you want. It adds the, in your case, label layer as a separate DOM layer ontop of the map after everything else has been drawn, using this code:
var topPane = map._createPane('leaflet-top-pane', map.getPanes().mapPane);
var topLayer = L.mapbox.tileLayer('lxbarth.map-vtt23b1i').addTo(map);
topPane.appendChild(topLayer.getContainer());
topLayer.setZIndex(9);
For those searching nowaday with Leaflet 1.7.x/1.8.x, you can set the pane for the tilelayer.
Default is the tile pane but you can add this parameter pane: 'overlayPane'
to add the tilelayer to overlay pane. So the code above would look like this :
var labels = L.tileLayer('http://{s}.www.toolserver/tiles/osm-labels-en/{z}/{x}/{y}.png', {
maxZoom: 17,
zIndex: 1000,
pane: 'overlayPane'
});
本文标签: javascriptOverlay below tiles in LeafletjsStack Overflow
版权声明:本文标题:javascript - Overlay below tiles in Leaflet.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743987721a2571573.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论