简体   繁体   English

Leaflet.js-在geojson图层上方可见的Tilelayer。 GeoJSON互动问题

[英]Leaflet.js - Tilelayer visible above geojson layer. GeoJSON interactivity issue

I have a leaflet.js project where I have a baselayer, a polygon geojson layer, and another tilelayer above the geojson layer which shows placenames. 我有一个leaflet.js项目,其中有一个基础层,一个多边形geojson层,以及位于geojson层上方的另一个显示地名的图块。 I've managed to get the placenames tilelayer to visualise above the geojson layer by adding it to a map pane. 我已经设法通过将地名tilelayer添加到地图窗格中,使其在geojson图层上方可视化。 However, this has disabled click and hover events on the geojson layer. 但是,这已禁用geojson图层上的单击和悬停事件。 I'm thinking I probably have to add the goejson layer to it's own pane, or possibly the same pane as the placenames tilelayer, but I'm not sure. 我想我可能必须将goejson图层添加到它自己的窗格中,或者可能与地名图块图层添加到同一窗格中,但是我不确定。

Here's my code which add my placenames layer to a pane: 这是将我的地名图层添加到窗格中的代码:

var topPane = map.createPane('leaflet-top-pane', map.getPanes().mapPane);
    topPane.appendChild(CartoDB_PositronOnlyLabels.getContainer());

Here's my CSS code for the pane: 这是我的窗格的CSS代码:

    .leaflet-top-pane {
    pointer-events: none;
}

I've tried adding my geojson layer to the same pane, and changing the pointer-events option, but either it won't work, or I haven't hit on the right combination. 我尝试将我的geojson图层添加到同一窗格中,并更改了指针事件选项,但是它要么行不通,要么我没有找到正确的组合。 Has anyone any ideas as to how I can resolve this so that I can have my tilelayer overlay above my geojson layer but still be able to interact with the geojson layer? 是否有人对如何解决此问题有任何想法,以便可以将我的tilelayer覆盖在geojson层上方,但仍然能够与geojson层进行交互?

You're not using the Leaflet library properly (eg manually appending a layer to a HTML container), assuming you will know the CSS class of the pane, etc). 您没有正确使用Leaflet库(例如,假设您知道窗格的CSS类等,则手动将图层添加到HTML容器)。

Use this instead: 使用此代替:

map.createPane('labels');    
map.getPane('labels').style.zIndex = 1000;
map.getPane('labels').style.pointerEvents = 'none';

var positron = L.tileLayer('http://{s}.basemaps.cartocdn.com/light_nolabels/{z}/{x}/{y}.png', {
    attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, &copy; <a href="http://cartodb.com/attributions">CartoDB</a>'
}).addTo(map);

var positronLabels = L.tileLayer('http://{s}.basemaps.cartocdn.com/light_only_labels/{z}/{x}/{y}.png', {
    attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, &copy; <a href="http://cartodb.com/attributions">CartoDB</a>',
    pane: 'labels'
}).addTo(map);

You can see a working example here . 您可以在此处看到一个有效的示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM