具有baseLayers的地图控制功能的传单问题

时间:2019-04-11 19:23:18

标签: leaflet

显示地图多次后,活页中的baselayers-control不会被激活。

我编写了一个测试程序来显示问题:

<head>
  <script>
    'use strict';
    var BING_KEY = "AplTrT4uzwlmfcERFFQu_NqDycERC_Er0qGYzZhIqrDfq-naYCsUr1kbbKRUqhq1";
    var osmUrl = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';

    function show_karte(div_id, mittelpunkt, zoom){
        var bingLayer = L.tileLayer.bing({bingMapsKey: BING_KEY, maxZoom: 20, imagerySet: 'Aerial', attribution: '&copy; 2019 Microsoft Corporation, Earthstar Geographics SIO'});
        var bingLabelLayer = L.tileLayer.bing({bingMapsKey: BING_KEY, maxZoom: 20, imagerySet: 'AerialWithLabels', attribution: '&copy; 2019 Microsoft Corporation, Earthstar Geographics SIO'});
        var osmLayer = L.tileLayer(osmUrl, {maxZoom: 20, attribution: 'Map data &copy; <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 map = L.map(div_id,{layers: [bingLabelLayer]}).setView(mittelpunkt, zoom);
        var baseLayers = {"Stra&szlig;enkarte": osmLayer, "Luftbild mit Stra&szlig;ennamen": bingLabelLayer,"Luftbild": bingLayer}; 
        var control = L.control.layers(baseLayers).addTo(map);
    };  
  </script>
</head>

<body>
    <div id="map" style="width:450px; height: 450px;">
        <script  type="text/javascript"> show_karte("map",[6.026173,50.816022],13); </script>
    </div>

    <div id="map1" style="width:550px; height: 450px;">
        <script  type="text/javascript"> show_karte("map1",[6.10428,50.76079],11); </script>
    </div>

    <div id="map2" style="width:650px; height:450px">  
        <script  type="text/javascript">show_karte("map2",[6.10428,50.76079],12); </script>
    </div>
</body>

您可以在此处查看该程序: https://aachen-hat-energie.de/test_ww/test_zukunft.htm 该控件仅在第三张地图上被激活。错误在哪里?

0 个答案:

没有答案