pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    1. <tfoot id='VTVJv'></tfoot>
    2. <i id='VTVJv'><tr id='VTVJv'><dt id='VTVJv'><q id='VTVJv'><span id='VTVJv'><b id='VTVJv'><form id='VTVJv'><ins id='VTVJv'></ins><ul id='VTVJv'></ul><sub id='VTVJv'></sub></form><legend id='VTVJv'></legend><bdo id='VTVJv'><pre id='VTVJv'><center id='VTVJv'></center></pre></bdo></b><th id='VTVJv'></th></span></q></dt></tr></i><div class="0ke2yoq" id='VTVJv'><tfoot id='VTVJv'></tfoot><dl id='VTVJv'><fieldset id='VTVJv'></fieldset></dl></div>

      1. <small id='VTVJv'></small><noframes id='VTVJv'>

          <bdo id='VTVJv'></bdo><ul id='VTVJv'></ul>
        <legend id='VTVJv'><style id='VTVJv'><dir id='VTVJv'><q id='VTVJv'></q></dir></style></legend>

        何時使用 L.TileLayer 與 L.tileLayer

        when to use L.TileLayer vs L.tileLayer(何時使用 L.TileLayer 與 L.tileLayer)
          <bdo id='WT7vJ'></bdo><ul id='WT7vJ'></ul>

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

            • <tfoot id='WT7vJ'></tfoot>

              • <legend id='WT7vJ'><style id='WT7vJ'><dir id='WT7vJ'><q id='WT7vJ'></q></dir></style></legend>

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

                    <tbody id='WT7vJ'></tbody>
                  本文介紹了何時使用 L.TileLayer 與 L.tileLayer的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我剛剛使用 Leaflet 為網站構建地圖,并注意到添加 Tile Layer 至少可以使用兩種方法,L.TileLayer()L.tileLayer(),名稱的區別僅在于單個字符的大小寫.

                  但是,雖然這兩種方法返回的對象都可以添加到 L.map() 返回的地圖對象中,但 L.TileLayer() 似乎沒有 addTo() 方法,而 L.tileLayer() 返回的對象.例如.兩者都有

                  var map = L.map('map');var tiles = new L.TileLayer(<tileUrl>, {attribution: <tileAttrib>});map.addLayer(tiles);

                  var map = L.map('map');var tiles = new L.tileLayer(<tileUrl>, {attribution: <tileAttrib>});map.addLayer(tiles);

                  還有

                  var map = L.map('map');L.tileLayer(<tileUrl>, {attribution: <tileAttrib>}).addTo(map);

                  同時

                  var map = L.map('map');L.TileLayer(<tileUrl>, {attribution: <tileAttrib>}).addTo(map);

                  失敗.瀏覽 Leaflet 的文檔,似乎使用正確的方法是 L.tileLayer() 那么問題是 L.TileLayer() 的用途是什么?p>

                  到目前為止,這是我的代碼的完整示例,要嘗試不同的替代方案,只需取消注釋要測試的代碼并確保其他代碼已被注釋

                  解決方案

                  TL;DR:

                  這兩個都是有效且等價的:

                  var foo = L.tileLayer(arguments);var foo = new L.TileLayer(參數);

                  這兩個在語法上是有效的(因為 Javascript 的歷史包袱)但最終會導致錯誤:

                  var foo = new L.tileLayer(arguments);var foo = L.TileLayer(參數);


                  <塊引用>

                  要添加一個 tilelayer,至少可以使用兩種方法,L.TileLayer()L.tileLayer()

                  嗯,它們并不是真正的兩個方法.技術上L.TileLayerObject的實例,L.tileLayerFunction的實例,繼承Object 的原型.并且 L 充當命名空間而不是類實例.

                  你看,Javascript 中的面向對象編程是奇怪.您可以使用 new關鍵字 幾乎包含任何具有原型的對象.而 基于原型的繼承 讓大多數人難以理解精通適當";哎呀.

                  如今,對于 ES2015 標準和花哨的 class 關鍵字,這并不是真正的問題(我會說這是一個問題,但隱藏在語法糖層之下).但在過去,開發人員不得不求助于,比如說,類繼承的創造性解決方案 有時涉及弄亂原型鏈.

                  Leaflet 使用了這些方法的組合 - 作為一種不希望的副作用L.TileLayer 變成了一個 Function 并且可以調用 L.TileLayer() 直接,這很混亂.

                  Leaflet 還使用了工廠函數的概念:返回類實例的函數.引用 傳單教程之一:

                  <塊引用>

                  大多數 Leaflet 類都有相應的工廠函數.工廠函數與類同名,但使用 lowerCamelCase 而不是 UpperCamelCase:

                  function myBoxClass(name, options) {返回新的 MyBoxClass(名稱,選項);}

                  這只是為了方便:它使用戶免于輸入 new 關鍵字回到 害怕 關鍵字的時代>.

                  但這會產生另一個不受歡迎的副作用,因為在 Javascript 中,所有 Function 都有一個原型,這意味著您可以執行類似的操作

                   函數 myFunction() { ... }var wtf = new myFunction();

                  因此,new L.tileLayer() 也是有效的語法(但在運行時失敗).


                  <塊引用>

                  那么L.TileLayer()有什么用呢?

                  再一次,L.TileLayer() 作為函數調用是一個不受歡迎的副作用.但是 L.TileLayer 代表一個類,因此引用它很重要,因為:

                   if (layer instanceof L.TileLayer)

                  I have just been using Leaflet to build a map for a website and noticed that to add a Tile Layer at least two methods can be used, L.TileLayer() and L.tileLayer(), differing in their name only by the case of a single character.

                  However, while the object returned by both of these methods can be added to a map object returned by L.map() the object returned by L.TileLayer() does not seem to have the addTo() method whilst the object returned byL.tileLayer(). E.g. both

                  var map = L.map('map');
                  var tiles = new L.TileLayer(<tileUrl>, {attribution: <tileAttrib>});
                  map.addLayer(tiles);
                  

                  and

                  var map = L.map('map');
                  var tiles = new L.tileLayer(<tileUrl>, {attribution: <tileAttrib>});
                  map.addLayer(tiles);
                  

                  as well as

                  var map = L.map('map');
                  L.tileLayer(<tileUrl>, {attribution: <tileAttrib>}).addTo(map);
                  

                  whilst

                  var map = L.map('map');
                  L.TileLayer(<tileUrl>, {attribution: <tileAttrib>}).addTo(map);
                  

                  fails. Browsing the documentation of Leaflet it seems the proper method to use is L.tileLayer() so the question then is what is the use of L.TileLayer()?

                  Here's a full example of my code so far, to try the different alternatives simply uncomment the one to test and make sure the others are commented

                  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                          "http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd">
                          
                  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
                     <head>
                        <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"/>
                        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
                        
                        <link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.3/dist/leaflet.css"
                              integrity="sha512-Rksm5RenBEKSKFjgI3a41vrjkw4EVPlJ3+OiI65vTjIdo9brlAacEuKOiQ5OFh7cOI1bkDwLqdLw3Zg0cRJAAQ=="
                              crossorigin=""/>
                        <script src="https://unpkg.com/leaflet@1.3.3/dist/leaflet.js"
                              integrity="sha512-tAGcCfR4Sc5ZP5ZoVz0quoZDYX5aCtEm/eu1KhSLj2c9eFrylXZknQYmxUssFaVJKvvc0dJQixhGjG2yXWiV9Q=="
                              crossorigin=""> </script>
                     </head>
                     <body onload="makeMap()">
                        <script type="text/javascript">
                           function makeMap() {
                              var tileUrl = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
                              var tileAttrib = 'Map data &copy <a href="https://openstreetmap.org">OpenStreetMap</a> contributors'; 
                              var map = L.map('map').setView([63,15],9);
                              
                              // using tileLayer and addLayer - this works
                              var tiles = new L.tileLayer(tileUrl, {attribution: tileAttrib});
                              map.addLayer(tiles);
                              
                              // using tileLayer and addTo - this works
                  //             L.tileLayer(tileUrl, {attribution: tileAttrib}).addTo(map);
                              
                              // using TileLayer and addLayer - this works
                  //             var tiles = new L.TileLayer(tileUrl, {attribution: tileAttrib});
                  //             map.addLayer(tiles);
                              
                              // using TileLayer and addTo - this fails
                  //             L.TileLayer(tileUrl, {attribution: tileAttrib}).addTo(map);
                           }
                           
                        </script>
                        <table border=1 style="position: absolute; top: 0; bottom: 0; left: 0; right: 0; width: 100%; height: 100%;">
                           <tr style="height: 100%;">
                              <td>
                                 <div id="map" style="width: 100%; height: 100%;"></div>
                              </td>
                           </tr>
                        </table>
                     </body>
                  </html>
                  

                  解決方案

                  TL;DR:

                  These two are both valid and equivalent:

                  var foo = L.tileLayer(arguments);
                  var foo = new L.TileLayer(arguments);
                  

                  These two are syntactically valid (because of Javascript's historical baggage) but will ultimately result in errors:

                  var foo = new L.tileLayer(arguments);
                  var foo = L.TileLayer(arguments);
                  


                  to add a tilelayer at least two methods can be used, L.TileLayer() and L.tileLayer()

                  Well, they're not really two methods. Technically L.TileLayer is an instance of Object, and L.tileLayer is an instance of Function, which inherits the prototype of Object. And L acts as a namespace rather than a class instance.

                  You see, Object-Oriented Programming in Javascript is weird. You can use the new keyword with pretty much any object which has a prototype. And prototype-based inheritance is confusing to grasp to most people versed in "proper" OOP.

                  Nowadays, with the ES2015 standards and the fancy class keywords this is not really a problem (I'd say it's a problem, but hidden under layers of syntactic sugar). But back in the day, developers had to resort to, let's say, creative solutions for class inheritance which sometimes involves messing with the prototype chain.

                  Leaflet uses a combination of such methods - and as an undesired side effect, L.TileLayer becomes a Function and one can call L.TileLayer() directly and that's quite confusing.

                  Leaflet also uses the concept of factory functions: A function that returns an instance of a class. Quoting from one of the Leaflet tutorials:

                  Most Leaflet classes have a corresponding factory function. A factory function has the same name as the class, but in lowerCamelCase instead of UpperCamelCase:

                  function myBoxClass(name, options) {
                      return new MyBoxClass(name, options);
                  }
                  

                  This is meant just as a convenience: it saves the user from typing the new keyword back in an era where the new keyword was feared.

                  But this creates another undesired side effect, because in Javascript all Functions have a prototype, which means that you can do stuff like

                   function myFunction() { ... }
                   var wtf = new myFunction();
                  

                  Therefore, new L.tileLayer() is also valid syntax (but fails at runtime).


                  then what is the use of L.TileLayer()?

                  Once again, L.TileLayer() as a function call is an undesired side effect. But L.TileLayer represents a class and it's important to have a reference to that, because of things like:

                   if (layer instanceof L.TileLayer)
                  

                  這篇關于何時使用 L.TileLayer 與 L.tileLayer的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Check if a polygon point is inside another in leaflet(檢查一個多邊形點是否在傳單中的另一個內部)
                  Changing leaflet markercluster icon color, inheriting the rest of the default CSS properties(更改傳單標記群集圖標顏色,繼承其余默認 CSS 屬性)
                  Trigger click on leaflet marker(觸發點擊傳單標記)
                  How can I change the default loading tile color in LeafletJS?(如何更改 LeafletJS 中的默認加載磁貼顏色?)
                  Add external geojson to leaflet layer(將外部geojson添加到傳單層)
                  Adding Leaflet layer control to sidebar(將 Leaflet 圖層控件添加到側邊欄)

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

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

                          <tfoot id='LR4Gr'></tfoot><legend id='LR4Gr'><style id='LR4Gr'><dir id='LR4Gr'><q id='LR4Gr'></q></dir></style></legend>

                          <i id='LR4Gr'><tr id='LR4Gr'><dt id='LR4Gr'><q id='LR4Gr'><span id='LR4Gr'><b id='LR4Gr'><form id='LR4Gr'><ins id='LR4Gr'></ins><ul id='LR4Gr'></ul><sub id='LR4Gr'></sub></form><legend id='LR4Gr'></legend><bdo id='LR4Gr'><pre id='LR4Gr'><center id='LR4Gr'></center></pre></bdo></b><th id='LR4Gr'></th></span></q></dt></tr></i><div class="22yiwk2" id='LR4Gr'><tfoot id='LR4Gr'></tfoot><dl id='LR4Gr'><fieldset id='LR4Gr'></fieldset></dl></div>
                            <tbody id='LR4Gr'></tbody>
                          • 主站蜘蛛池模板: 六维力传感器_三维力传感器_二维力传感器-南京神源生智能科技有限公司 | 阳光模拟试验箱_高低温试验箱_高低温冲击试验箱_快速温变试验箱|东莞市赛思检测设备有限公司 | 金属波纹补偿器厂家_不锈钢膨胀节价格_非金属伸缩节定制-庆达补偿器 | 铝合金线槽_铝型材加工_空调挡水板厂家-江阴炜福金属制品有限公司 | 楼承板设备-楼承板成型机-免浇筑楼承板机器厂家-捡来 | 冷油器,取样冷却器,热力除氧器-连云港振辉机械设备有限公司 | 圆形振动筛_圆筛_旋振筛_三次元振动筛-河南新乡德诚生产厂家 | 304不锈钢无缝管_不锈钢管厂家 - 隆达钢业集团有限公司 | 闪电优家-卫生间防水补漏_酒店漏水渗水维修_防水堵漏公司 | 双齿辊破碎机-大型狼牙破碎机视频-对辊破碎机价格/型号图片-金联机械设备生产厂家 | 北京企业宣传片拍摄_公司宣传片制作-广告短视频制作_北京宣传片拍摄公司 | 河南中整光饰机械有限公司-抛光机,去毛刺抛光机,精密镜面抛光机,全自动抛光机械设备 | 深圳装修_店面装修设计_餐厅设计_装修全包价格-尚泰装饰设计 | 贵阳用友软件,贵州财务软件,贵阳ERP软件_贵州优智信息技术有限公司 | Copeland/谷轮压缩机,谷轮半封闭压缩机,谷轮涡旋压缩机,型号规格,技术参数,尺寸图片,价格经销商 CTP磁天平|小电容测量仪|阴阳极极化_双液系沸点测定仪|dsj电渗实验装置-南京桑力电子设备厂 | 杭州火蝠电商_京东代运营_拼多多全托管代运营【天猫代运营】 | 扬尘在线监测系统_工地噪声扬尘检测仪_扬尘监测系统_贝塔射线扬尘监测设备「风途物联网科技」 | 压缩空气检测_气体_水质找上海京工-服务专业、价格合理 | 爱佩恒温恒湿测试箱|高低温实验箱|高低温冲击试验箱|冷热冲击试验箱-您身边的模拟环境试验设备技术专家-合作热线:400-6727-800-广东爱佩试验设备有限公司 | 骨灰存放架|骨灰盒寄存架|骨灰架厂家|智慧殡葬|公墓陵园管理系统|网上祭奠|告别厅智能化-厦门慈愿科技 | 湖南自考_湖南自学考试网| 流量检测仪-气密性检测装置-密封性试验仪-东莞市奥图自动化科技有限公司 | 上海物流公司,上海货运公司,上海物流专线-优骐物流公司 | 视觉检测设备_自动化检测设备_CCD视觉检测机_外观缺陷检测-瑞智光电 | 南京办公用品网-办公文具用品批发-打印机耗材采购 | 净化板-洁净板-净化板价格-净化板生产厂家-山东鸿星新材料科技股份有限公司 | 衬塑设备,衬四氟设备,衬氟设备-淄博鲲鹏防腐设备有限公司 | 北京软件开发_软件开发公司_北京软件公司-北京宜天信达软件开发公司 | 世界箱包品牌十大排名,女包小众轻奢品牌推荐200元左右,男包十大奢侈品牌排行榜双肩,学生拉杆箱什么品牌好质量好 - Gouwu3.com | 运动木地板厂家_体育木地板安装_篮球木地板选购_实木运动地板价格 | 水冷式工业冷水机组_风冷式工业冷水机_水冷螺杆冷冻机组-深圳市普威机械设备有限公司 | 高光谱相机-近红外高光谱相机厂家-高光谱成像仪-SINESPEC 赛斯拜克 | 东莞韩创-专业绝缘骨架|马达塑胶零件|塑胶电机配件|塑封电机骨架厂家 | 石膏基自流平砂浆厂家-高强石膏基保温隔声自流平-轻质抹灰石膏粉砂浆批发-永康市汇利建设有限公司 | GEDORE扭力螺丝刀-GORDON防静电刷-CHEMTRONICS吸锡线-上海卓君电子有限公司 | 一体化污水处理设备,一体化污水设备厂家-宜兴市福源水处理设备有限公司 | 有机肥设备生产制造厂家,BB掺混肥搅拌机、复合肥设备生产线,有机肥料全部加工设备多少钱,对辊挤压造粒机,有机肥造粒设备 -- 郑州程翔重工机械有限公司 | 桁架楼承板-钢筋桁架楼承板-江苏众力达钢筋楼承板厂 | 浙江栓钉_焊钉_剪力钉厂家批发_杭州八建五金制造有限公司 | 三轴曲线机-端子插拔力试验机|华杰仪器 | 济南ISO9000认证咨询代理公司,ISO9001认证,CMA实验室认证,ISO/TS16949认证,服务体系认证,资产管理体系认证,SC食品生产许可证- 济南创远企业管理咨询有限公司 郑州电线电缆厂家-防火|低压|低烟无卤电缆-河南明星电缆 |