传单如何在满载时选择默认地图

时间:2018-08-23 08:08:32

标签: leaflet

因此,我一直在从传单地图提供者处收集地图图层,并且该网页未加载任何图层地图,因此必须手动选择它。 This is the webpage

这是代码:

// center of the map
var center = [14.240861626831018, 121.12966240455648];

// Create the map
var map = L.map('map', {attributionControl: false}).setView(center, 13);

//Layer Map
var osm = L.tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
{   
    maxZoom: 15,
    minZoom:13
}),
googleTerrain = L.tileLayer('http://{s}.google.com/vt/lyrs=p&x={x}&y={y}&z={z}',
{
    maxZoom: 15,
    minZoom:13,
    subdomains:['mt0','mt1','mt2','mt3']
}),
mlight = L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw',
{
    maxZoom: 15,
    minZoom:13,
    id: 'mapbox.light'
}),
darkmatter = L.tileLayer('https://cartodb-basemaps-{s}.global.ssl.fastly.net/dark_all/{z}/{x}/{y}{r}.png', 
{
    attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> &copy; <a href="http://cartodb.com/attributions">CartoDB</a>',
    subdomains: 'abcd',
    maxZoom: 19
}),
googleSat = L.tileLayer('http://{s}.google.com/vt/lyrs=s,h&x={x}&y={y}&z={z}',
{   
    maxZoom: 15,
    minZoom:13,
    subdomains:['mt0','mt1','mt2','mt3']
});

var baseMaps = {
    "Street": osm,
    "Terrain":googleTerrain,
    "Satellite": googleSat,
    "Dark": darkmatter,
    "MonoLight":mlight,
};

var overlays =  {
    };
L.control.layers(baseMaps,overlays, {position: 'bottomright'}).addTo(map);

我尝试搜索传单网站,我遗漏了什么吗?

1 个答案:

答案 0 :(得分:2)

您没有将这些L.TileLayer中的任何一个添加到地图中(例如foo = L.tileLayer(...).addTo(map))。只需添加您要默认启用的功能即可。

请记住,L.Control.Layers不会执行任何有关指定为底图的图层是否已经在地图上的初始检查。它已经suggested as a feature,但尚未进行任何工作(到目前为止)。