Leaflet tileLayer和控件的传单js问题

Leaflet tileLayer和控件的传单js问题,leaflet,Leaflet,我有一个带有openstreetmap和googlemap控件的传单地图,当我加载我的页面时,我看到一个openstreetmap的距离,然后切换到googlemap,但我想显示openstreetmap作为默认值 这是我的代码: <script> var openStreetMap = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: '&copy; &l

我有一个带有openstreetmap和googlemap控件的传单地图,当我加载我的页面时,我看到一个openstreetmap的距离,然后切换到googlemap,但我想显示openstreetmap作为默认值

这是我的代码:

<script>
var openStreetMap = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
    attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
    });

    var googleMap = L.tileLayer('http://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}', {
        maxZoom: 20,
        subdomains: ['mt0', 'mt1', 'mt2', 'mt3']
    });


    var map = L.map('map', {
        center: [43.44084,11.8602],
        zoom: 13,
        layers: [openStreetMap, googleMap]
    });
    



    var baseMaps = {
        'openStreetMap': openStreetMap,
        'googleMap': googleMap
    };

    L.control.layers(baseMaps).addTo(map);

    map.spin(true);

$.getJSON("http://localhost/fit-file-analysis-2/geojson.php",function(data){
   
    

    L.geoJson(data).addTo(map);
    map.spin(false);
});

var openStreetMap=L.tileLayer('https://{s}.tile.openStreetMap.org/{z}/{x}/{y}.png'{
属性:“©;贡献者”
});
var googleMap=L.tileLayer('http://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}'{
maxZoom:20,
子域:['mt0','mt1','mt2','mt3']
});
var map=L.map('map'{
中间:[43.44084,11.8602],
缩放:13,
图层:[openStreetMap,谷歌地图]
});
变量基本映射={
“openStreetMap”:openStreetMap,
“谷歌地图”:谷歌地图
};
L.控制。图层(底图)。添加到(地图);
map.spin(真);
$.getJSON(“http://localhost/fit-file-analysis-2/geojson.php,函数(数据){
L.geoJson(数据).addTo(地图);
map.spin(假);
});

基本贴图的对象添加到
贴图中,但不会影响平铺层

正如@IvanSanchez所说,您必须将平铺层添加到地图中:

openStreetMap.addTo(map);


将所需的瓷砖层添加到地图,即
.addTo(地图)