Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/472.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用传单maxbounds设置边界,但不使用';行不通_Javascript_Html_Leaflet - Fatal编程技术网

Javascript 使用传单maxbounds设置边界,但不使用';行不通

Javascript 使用传单maxbounds设置边界,但不使用';行不通,javascript,html,leaflet,Javascript,Html,Leaflet,嗨,我试着在传单地图中设置maxbaounds,但它不起作用。我的第一个问题是在我设定的边界之外停下来平移?我遵循下面的示例,但代码中有一些错误 我的代码 <html> <head> <title>A Leaflet map!</title> <link rel="stylesheet" href="https://unpkg.com/leaflet@1.4.0/dist/leaflet.css"

嗨,我试着在传单地图中设置maxbaounds,但它不起作用。我的第一个问题是在我设定的边界之外停下来平移?我遵循下面的示例,但代码中有一些错误

我的代码

<html>
    <head>
        <title>A Leaflet map!</title>
        <link rel="stylesheet" href="https://unpkg.com/leaflet@1.4.0/dist/leaflet.css" />
        <script src="https://maps.api.2gis.ru/2.0/loader.js?pkg=full"></script>
        <style>
            #map{ height: 100% }
        </style>
    </head>
    <body>

        <div id="map"></div>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <script src="https://unpkg.com/leaflet@1.4.0/dist/leaflet.js"></script>
        <script>

            var southWest = L.latLng(34.072711,31.758391),
                northEast = L.latLng(36.113055, 35.124228),
                bounds = L.latLngBounds(southWest, northEast);

            var counties = $.ajax({
                url: "https://gist.githubusercontent.com/vassilaros/3791204ca226d5b236b4cd3106ef23cf/raw/PicnicSites.geojson",
                dataType: "json",
                success: console.log("County data successfully loaded."),
                error: function(xhr) {
                    alert(xhr.statusText)
                }
            })
            $.when(counties).done(function() {
                var map = L.map('map')
                .setView([35.126411,33.429859], 9);

                //tiles - http://{s}.basemaps.cartocdn.com/light_nolabels/{z}/{x}/{y}.png
                var basemap = L.tileLayer('http://tile1.maps.2gis.com/tiles?x={x}&y={y}&z={z}', {
                    attribution: '&copy; <a href="http://info.2gis.com/">2GIS</a> &copy; <a href="https://www.opencartography.com">Open Cartography</a>',
                    subdomains: 'abcd',
                    maxBounds: bounds,
                    maxZoom: 19,
                    minZoom: 9
                }).addTo(map);

                // Add requested external GeoJSON to map
                var kyCounties = L.geoJSON(counties.responseJSON).addTo(map);
                var scale = L.control.scale()
                scale.addTo(map)   
            });
        </script>
    </body>
</html>

单张地图!
#地图{高度:100%}
西南风=L.latLng(34.072711,31.758391),
东北=拉特林(36.113055,35.124228),
边界=L.latLngBounds(西南、东北);
var=$.ajax({
url:“https://gist.githubusercontent.com/vassilaros/3791204ca226d5b236b4cd3106ef23cf/raw/PicnicSites.geojson",
数据类型:“json”,
success:console.log(“成功加载县数据”),
错误:函数(xhr){
警报(xhr.statusText)
}
})
$.when(countries).done(function()函数){
var map=L.map('map'))
.setView([35.126411,33.429859],9);
//tiles-http://{s}.basemaps.cartocdn.com/light_nolabels/{z}/{x}/{y}.png
var basemap=L.tileLayer('http://tile1.maps.2gis.com/tiles?x={x} &y={y}&z={z}'{
属性:“©;©;”,
子域:“abcd”,
maxBounds:bounds,
maxZoom:19,
最小缩放:9
}).addTo(地图);
//将请求的外部GeoJSON添加到映射
var kycountries=L.geoJSON(countries.responseJSON).addTo(map);
var scale=L.control.scale()
比例。添加到(地图)
});

使用
L.map
上的
maxBounds
设置边界限制

var map = L.map('map')
                .setView([35.126411,33.429859], 9)
                .setMaxBounds(bounds);

另外-不要将
mapbox.js
lapper.js
混淆-它们是不同的。

使用
L.map
上的
maxBounds
设置边界限制

var map = L.map('map')
                .setView([35.126411,33.429859], 9)
                .setMaxBounds(bounds);

另外-不要将
mapbox.js
mobile.js
混淆-它们是不同的。

谢谢你的回答,我更改了代码并尝试了你的解决方案,但显示了一个空白页。谢谢你的回答,我更改了代码并尝试了你的解决方案,但显示了一个空白页。