英文:
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.
<l-map @ready="onMapReady">
<l-tile-layer v-bind="tilesOpts" />
</l-map>
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: '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);
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('left');
this.map.createPane('right');
And then for each GEOjson assign the correct pane:
const layer = L.geoJSON(map, { style: { color, weight: 2, opacity: 1 }, pane: 'left' }).addTo(this.map);
Thank god for this SE post. I was going crazy.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论