我正在使用leaflet.js和OSMtiles创建map,但我只希望美国大陆可见,而不是整个世界。这可能吗?我正在这样加载map:varmap=L.map('map').setView([39.82,-98.58],5);L.tileLayer('http://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png',{attribution:'...',maxZoom:18}).addTo(map); 最佳答案 这是可能的,也很容易做到。首先,您需要美国大陆边界框(最外边缘)的坐标。
我用examplecodeIfoundatMapbox试用了LeafletjsmaxBounds|.下面是我的完整代码,也在jsfiddlehere中.map-leaflettestboundsbody{margin:0;padding:0;}html,body,#map{height:100%;width:100%;}varsouthWest=L.latLng(40.712,-74.227),northEast=L.latLng(40.774,-74.125),mybounds=L.latLngBounds(southWest,northEast);varmap=L.map('map
我用examplecodeIfoundatMapbox试用了LeafletjsmaxBounds|.下面是我的完整代码,也在jsfiddlehere中.map-leaflettestboundsbody{margin:0;padding:0;}html,body,#map{height:100%;width:100%;}varsouthWest=L.latLng(40.712,-74.227),northEast=L.latLng(40.774,-74.125),mybounds=L.latLngBounds(southWest,northEast);varmap=L.map('map