<small id='xJYfG'></small><noframes id='xJYfG'>

    1. <tfoot id='xJYfG'></tfoot>
    2. <i id='xJYfG'><tr id='xJYfG'><dt id='xJYfG'><q id='xJYfG'><span id='xJYfG'><b id='xJYfG'><form id='xJYfG'><ins id='xJYfG'></ins><ul id='xJYfG'></ul><sub id='xJYfG'></sub></form><legend id='xJYfG'></legend><bdo id='xJYfG'><pre id='xJYfG'><center id='xJYfG'></center></pre></bdo></b><th id='xJYfG'></th></span></q></dt></tr></i><div id='xJYfG'><tfoot id='xJYfG'></tfoot><dl id='xJYfG'><fieldset id='xJYfG'></fieldset></dl></div>
      <legend id='xJYfG'><style id='xJYfG'><dir id='xJYfG'><q id='xJYfG'></q></dir></style></legend>
          <bdo id='xJYfG'></bdo><ul id='xJYfG'></ul>

        Leaflet maxBounds - 边界不起作用

        时间:2023-08-09

          <tfoot id='dbsir'></tfoot>
        1. <small id='dbsir'></small><noframes id='dbsir'>

          • <bdo id='dbsir'></bdo><ul id='dbsir'></ul>

                <i id='dbsir'><tr id='dbsir'><dt id='dbsir'><q id='dbsir'><span id='dbsir'><b id='dbsir'><form id='dbsir'><ins id='dbsir'></ins><ul id='dbsir'></ul><sub id='dbsir'></sub></form><legend id='dbsir'></legend><bdo id='dbsir'><pre id='dbsir'><center id='dbsir'></center></pre></bdo></b><th id='dbsir'></th></span></q></dt></tr></i><div id='dbsir'><tfoot id='dbsir'></tfoot><dl id='dbsir'><fieldset id='dbsir'></fieldset></dl></div>
                <legend id='dbsir'><style id='dbsir'><dir id='dbsir'><q id='dbsir'></q></dir></style></legend>
                  <tbody id='dbsir'></tbody>

                  本文介绍了Leaflet maxBounds - 边界不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我用 我在 Mapbox 找到的示例代码尝试了 Leafletjs maxBounds.

                  您可以在下面找到我的完整代码,也在 jsfiddle here 中.

                  Below you find my complete code, also in a jsfiddle here.

                  <!DOCTYPE HTML>
                  <html>
                  <head>
                      <title>map - leaflet test bounds</title>
                          <meta charset="UTF-8">
                          <meta name="viewport" content="width=device-width, initial-scale=1, minimal-ui" />
                          <meta http-equiv="X-UA-Compatible" content="IE=edge">
                  
                          <!-- leafletjs -->
                          <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />
                          <script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
                  
                          <style>
                              body {
                                  margin: 0;
                                  padding: 0;
                              }
                              html, body, #map {
                                  height: 100%;
                                  width: 100%;
                              }
                          </style>
                  </head>
                  
                  <body>
                      <div id="map">
                          <script>
                  
                              var southWest = L.latLng(40.712, -74.227),
                                  northEast = L.latLng(40.774, -74.125),
                                  mybounds = L.latLngBounds(southWest, northEast);
                  
                              var map = L.map('map').setView([40.743, -74.176], 17);
                              L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png' , {
                                  maxBounds: mybounds,
                                  maxZoom: 18,
                                  minZoom: 16,
                                  attribution: '&copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors'
                              }) .addTo(map);
                  
                              L.marker([40.743, -74.176]) .addTo(map);
                  
                          </script>
                      </div>        
                  </body>
                  

                  jsfiddle 结果看起来很奇怪,我不知道为什么.

                  The jsfiddle result looks odd, I don't know why.

                  为什么上面的代码不像 Mapbox 的例子那样工作?

                  Why doesn't the upper code work like the Mapbox example?

                  推荐答案

                  你必须使用 bounds 作为 L.tileLayer 的选项,而不是 maxBounds.

                  You must use bounds as an option of L.tileLayer, and not maxBounds.

                  边界参考

                  另外,您似乎在 JSFiddle 中为 leaflet.css 加载了错误的文件,正确的来源是:http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css

                  Also, it seems you've loaded a wrong file for the leaflet.css in JSFiddle, the correct source is this: http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css

                  最后,避免在 JSFiddle 中使用百分比大小,而是使用像素大小.这是一个有效的 JSFiddle:http://jsfiddle.net/1zyL4q4a/4/

                  Finally, avoid to use percent sizes in JSFiddle, use pixel ones instead. Here's a working JSFiddle: http://jsfiddle.net/1zyL4q4a/4/

                   L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png' , {
                              bounds: mybounds,
                              maxZoom: 18,
                              minZoom: 16,
                              attribution: '&copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors'
                    }).addTo(map);
                  

                  这篇关于Leaflet maxBounds - 边界不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:隐藏“显示:无"时如何渲染传单地图父母 下一篇:Leaflet Draw Plugin:如何按图层类型动态隐藏/显示绘

                  相关文章

                  最新文章

                    <small id='y7rhe'></small><noframes id='y7rhe'>

                    <legend id='y7rhe'><style id='y7rhe'><dir id='y7rhe'><q id='y7rhe'></q></dir></style></legend>
                  1. <tfoot id='y7rhe'></tfoot>
                      • <bdo id='y7rhe'></bdo><ul id='y7rhe'></ul>

                      <i id='y7rhe'><tr id='y7rhe'><dt id='y7rhe'><q id='y7rhe'><span id='y7rhe'><b id='y7rhe'><form id='y7rhe'><ins id='y7rhe'></ins><ul id='y7rhe'></ul><sub id='y7rhe'></sub></form><legend id='y7rhe'></legend><bdo id='y7rhe'><pre id='y7rhe'><center id='y7rhe'></center></pre></bdo></b><th id='y7rhe'></th></span></q></dt></tr></i><div id='y7rhe'><tfoot id='y7rhe'></tfoot><dl id='y7rhe'><fieldset id='y7rhe'></fieldset></dl></div>