0

我不知道如何将Leaflet.Graticule集成到 ui-leaflet/angular-leaflet-directive 应用程序中。任何关于如何做到这一点的指针将不胜感激。

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

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

}

4

1 回答 1

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>

于 2016-03-10T14:45:06.010 回答