亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

不理解傳單中 latLngBounds 的語法

不理解傳單中 latLngBounds 的語法

絕地無雙 2022-08-27 10:57:51
傳單latLngBounds()函數有一個getCenter()方法,但我不明白返回該值的語法。var mk5 = L.latLngBounds.getCenter(); returns an errorvar mk5 = L.latLngBounds().getCenter(); returns an errorvar mk5 = L.latLngBounds({getCenter()}); returns an error找到其使用的例子是不可能的。有人請告訴我使用此方法的語法。
查看完整描述

1 回答

?
三國紛爭

TA貢獻1804條經驗 獲得超7個贊

文檔所示:

  1. 創建第一個角:var corner1 = L.latLng(40.712, -74.227);

  2. 創建第二個角:var corner2 = L.latLng(40.774, -74.125);

  3. 創建邊界:bounds = L.latLngBounds(corner1, corner2);

  4. 從實例調用方法:getCenterboundsbounds.getCenter()

下面是一個示例:

<!DOCTYPE html>

<html>


  <head>


    <title>Quick Start - Leaflet</title>


    <meta charset="utf-8" />

    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <link rel="shortcut icon" type="image/x-icon" href="docs/images/favicon.ico" />


    <link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ==" crossorigin="" />

    <script src="https://unpkg.com/[email protected]/dist/leaflet.js" integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew==" crossorigin=""></script>




  </head>


  <body>




    <div id="mapid" style="width: 600px; height: 400px;"></div>

    <script>

      var mymap = L.map('mapid').setView([51.505, -0.09], 2);


      L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', {

        maxZoom: 18,

        attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, ' +

          '<a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +

          'Imagery ? <a href="https://www.mapbox.com/">Mapbox</a>',

        id: 'mapbox/streets-v11',

        tileSize: 512,

        zoomOffset: -1

      }).addTo(mymap);


      var corner1 = L.latLng(40.712, -74.227),

        corner2 = L.latLng(40.774, -74.125),

        bounds = L.latLngBounds(corner1, corner2)


      var rect = L.rectangle(bounds, {

        color: 'blue',

        weight: 1

      }).addTo(mymap);


      mymap.fitBounds(bounds)



      const markerCoords = bounds.getCenter()


      L.marker(markerCoords).addTo(mymap)


    </script>




  </body>


</html>


查看完整回答
反對 回復 2022-08-27
  • 1 回答
  • 0 關注
  • 190 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號