使用Leaflet.Graticule with angular-leaflet-directive

时间:2016-03-10 08:17:55

标签: leaflet angular-leaflet-directive ui-leaflet

我无法理解如何将Leaflet.Graticule集成到ui-leaflet / angular-leaflet-directive应用程序中。关于如何做到这一点的任何指示都将非常感激。

编辑:为了扩展iH8的答案,我还必须在我的bower.json中的覆盖部分添加一个条目:

 "overrides": {
"leaflet.Graticule": {
  "main": [
    "src/L.Graticule.js"
  ]
}

}

1 个答案:

答案 0 :(得分:1)

leafletData注入您的控制器并使用它的getMap承诺来获取L.Map实例并添加刻度:

angular.module('App', [
  'ui-leaflet'
]);

angular.module('App').controller('Controller', [
             'leafletData',
    function (leafletData) {
      leafletData.getMap().then(function (map) {
        L.graticule().addTo(map);
      });
    }
]);
body {
    margin: 0;
}

html, body, .leaflet-container {
    height: 100%;
}
<!DOCTYPE html>
<html ng-app="App">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script>document.write('<base href="' + document.location + '" />');</script>
    <link type="text/css" rel="stylesheet" href="//cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css" />
    <script type="application/javascript" src="//cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script>
    <script type="application/javascript" src="//rawgit.com/turban/Leaflet.Graticule/master/L.Graticule.js"></script>
    <script type="application/javascript" src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0/angular.js"></script>
    <script type="application/javascript" src="//rawgit.com/nmccready/angular-simple-logger/master/dist/angular-simple-logger.js"></script>
    <script type="application/javascript" src="//rawgit.com/angular-ui/ui-leaflet/master/dist/ui-leaflet.js"></script>
  </head>
  <body ng-controller="Controller">
    <leaflet></leaflet>
  </body>
</html>