Leaflet并排总是在右侧显示图层。

huangapple go评论93阅读模式
英文:

Leaflet side by side always displays layers on the right

问题

我正在使用leaflet-sbs来比较不同的图层。

<l-map @ready="onMapReady">
  <l-tile-layer v-bind="tilesOpts" />
</l-map>

地图使用一个单一的瓷砖图层,基于 https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png

然后,我创建了sbs元素并添加了一些GEOjson图层(GEODATAx = JSON.parse(geojson)):

const sbs = L.control.sideBySide([], []).addTo(map);
const layer1 = L.geoJSON(GEODATA1, { style: { color: 'red', weight: 2, opacity: 1 } }).addTo(map);
const layer2 = L.geoJSON(GEODATA2, { style: { color: 'green', weight: 2, opacity: 1 } }).addTo(map);
const layer3 = L.geoJSON(GEODATA3, { style: { color: 'blue', weight: 2, opacity: 1 } }).addTo(map);
const layer4 = L.geoJSON(GEODATA4, { style: { color: 'yellow', weight: 2, opacity: 1 } }).addTo(map);

然后,我将图层推送到一个面板:

sbs.setLeftLayers([layer1, layer2]);

这样做是有效的,我在左侧面板上得到了我的两个图层。如果需要,我可以使用 sbs.setRightLayers 将它们添加到右侧面板。

但是,当我想要在两个面板上添加图层时存在问题:

sbs.setLeftLayers([layer1, layer2]);
sbs.setRightLayers([layer3, layer4]);

只有右侧面板上的图层被显示出来。

我查看了GitHub上的问题,并用 getPane 替换了 getContainer,以使该库与leaflet 1.9兼容。

我尝试直接在L.control.sideBySide方法内设置图层,但没有成功。

英文:

I'm working with leaflet-sbs to compare different layers.

    &lt;l-map @ready=&quot;onMapReady&quot;&gt;
      &lt;l-tile-layer v-bind=&quot;tilesOpts&quot; /&gt;
    &lt;/l-map&gt;

The map uses one single tile layer based on https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png

Then I create the sbs element and add a few GEOjson layers (GEODATAx = JSON.parse(geojson)):

const sbs = L.control.sideBySide([], []).addTo(map);
const layer1 = L.geoJSON(GEODATA1, { style: { color: &#39;red&#39;, weight: 2, opacity: 1 } }).addTo(map);
const layer2 = L.geoJSON(GEODATA2, { style: { color: &#39;green&#39;, weight: 2, opacity: 1 } }).addTo(map);
const layer3 = L.geoJSON(GEODATA3, { style: { color: &#39;blue&#39;, weight: 2, opacity: 1 } }).addTo(map);
const layer4 = L.geoJSON(GEODATA4, { style: { color: &#39;yellow&#39;, weight: 2, opacity: 1 } }).addTo(map);

Then I push the layers to a pane:

sbs.setLeftLayers([layer1, layer2]);

This works, I get my 2 layers on the left pane. I could use sbs.setRightLayers to add them to the right pane instead.

The problem is when I want to add layers on both panes:

sbs.setLeftLayers([layer1, layer2]);
sbs.setRightLayers([layer3, layer4]);

Only the layers in the right pane are displayed.

I've looked at the github issues and replaced getContainer with getPane so that the lib works with leaflet 1.9

I've tried setting the layers directly inside L.control.sideBySide method to no avail.

答案1

得分: 0

我终于找到了这个GIS Stack Exchange帖子:
https://gis.stackexchange.com/questions/345096/leaflet-compare-two-side-by-side-geojson-layers

我不得不创建2个窗格:

this.map.createPane('left');
this.map.createPane('right');

然后为每个GEOjson分配正确的窗格:

const layer = L.geoJSON(map, { style: { color, weight: 2, opacity: 1 }, pane: 'left' }).addTo(this.map);

感谢上述GIS Stack Exchange帖子。我简直快要发疯了。

英文:

I've finally found this SE post
https://gis.stackexchange.com/questions/345096/leaflet-compare-two-side-by-side-geojson-layers

I had to create 2 panes:

this.map.createPane(&#39;left&#39;);
this.map.createPane(&#39;right&#39;);

And then for each GEOjson assign the correct pane:

const layer = L.geoJSON(map, { style: { color, weight: 2, opacity: 1 }, pane: &#39;left&#39; }).addTo(this.map);

Thank god for this SE post. I was going crazy.

huangapple
  • 本文由 发表于 2023年7月7日 00:43:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76630949.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定