我的地图是通过以下代码生成的(建议后编辑):
var BING_KEY = "My Bing Maps Key";
var osmUrl = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
function show_karte(div_id, mittelpunkt, zoom, overlay, typ){
var bingLayer = L.tileLayer.bing({bingMapsKey: BING_KEY, maxZoom: 20, imagerySet: 'Aerial', attribution: '© 2019 Microsoft Corporation, Earthstar Geographics SIO'});
var bingLabelLayer = L.tileLayer.bing({bingMapsKey: BING_KEY, maxZoom: 20, imagerySet: 'AerialWithLabels', attribution: '© 2019 Microsoft Corporation, Earthstar Geographics SIO'});
var osmLayer = L.tileLayer(osmUrl, {maxZoom: 20, attribution: 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>'});
var mittelpunkt = [mittelpunkt[1], mittelpunkt[0]]
var aktuellerLayer;
switch (typ) {
case 'A' : aktuellerLayer = bingLayer; break;
case 'L' : aktuellerLayer = bingLabelLayer; break;
case 'R' : aktuellerLayer = osmLayer;
};
var map = L.map(div_id,{fullscreenControl: true, layers: [aktuellerLayer]}).setView(mittelpunkt, zoom);
var overlayLayers = null;
var baseLayers = {"Straßenkarte": osmLayer, "Luftbild mit Straßennamen": bingLabelLayer,"Luftbild": bingLayer};
var controls = L.control.layers(baseLayers, overlayLayers).addTo(map);
$.ajax(overlay).done(function(data) {
var data = JSON.parse(data);
L.geoJson(data,
{
});
});
};
每次在Webist上调用“ show_karte”三次,每次使用另一个div-id和第一个函数参数,分别为:
<div class="bild_rechts" id="map" style="width:450px; height: 700px;">
<script type="text/javascript"> show_karte("map",[6.026173,50.816022],13,"neueFlaechen.geojson","L"); </script>
</div>
<div id="map1" style="width:450px; height: 700px;">
<script type="text/javascript"> show_karte("map1",[6.10428,50.76079],11,"konzentrationsflaechen.geojson","A"); </script>
</div>
<div id="map2" style="width:795px; height:1000px">
<script type="text/javascript">show_karte("map2",[6.10428,50.76079],12,"moeglicheFlaechen.geojson","R"); </script>
</div>
在所有三种情况下,我都可以看到地图控件,但是仅在第三张地图上,激活了一个选项。有人可以告诉错误吗? -感谢您阅读代码!
粗鲁,眨眼
答案 0 :(得分:0)
您不能同时在不同地图上重复使用图层。只有最后一层会保留该层。
您只需要为每张地图复制图层,例如通过在show_carte函数中移动其创建代码。