using Leaflet.Graticule with angular-leaflet-directive

303 views Asked by At

I am at a loss to understand how to integrate Leaflet.Graticule into a ui-leaflet/angular-leaflet-directive application. Any pointers as to how this should be done would be much appreciated.

EDIT: To extend the answer from iH8 a little bit, I also had to add a entry to the overrides section in my bower.json:

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

}

1

There are 1 answers

1
iH8 On BEST ANSWER

Inject leafletData into your controller and use it's getMap promise to grab the L.Map instance and add the graticule:

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>