簡體   English   中英

如何使用ui-angiular獲取到Pan的地圖?

[英]How do you get the map to Pan using ui-angiular?

我正在使用ui-angular,但我無法弄清楚如何將地圖平移到新位置。 我了解它是如何工作的,因為我只是使用Leaflet.js,但是因為這是一條指令,所以我不明白應該使用哪個對象與頁面上的map進行交互。

Here is my map directive
<leaflet id="owmMap" center="center" markers="markers" layers="layers"></leaflet>

 Here is my code so far.

  $scope.moveTo = function(obj){
        console.log(obj);

      //map.panTo((new L.LatLng(40.737, -73.923));); <--- This is what I need to replicate
 }

好的,就像大多數事情一樣,答案被埋藏在文檔中。 由於某種原因,此插件實際上有3個不同的站點,具有不同的文檔集,但我在git repo上找到了答案。

https://github.com/tombatossals/angular-leaflet-directive

如果還有其他人有這個問題。

有一個名為“ leafletData”的數據對象,您可以將其傳遞到“控制器”中,並用於直接在頁面上訪問地圖對象。 這是一些示例代碼:

 $scope.moveTo = function(obj){
      leafletData.getMap('myMap').then(function(map) {
         map.panTo({lat: obj.lat, lng: obj.lng});
       });   
 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM