Skip to content

Commit fef3886

Browse files
committed
Add initial support for 3rd party controls, and Leaflet.draw
1 parent 082ab92 commit fef3886

File tree

12 files changed

+3166
-3
lines changed

12 files changed

+3166
-3
lines changed

Gruntfile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ module.exports = function(grunt) {
122122
'src/directives/bounds.js',
123123
'src/directives/markers.js',
124124
'src/directives/paths.js',
125+
'src/directives/controls.js',
125126
'src/directives/eventBroadcast.js',
126127
'src/directives/maxBounds.js',
127128
'src/services/leafletData.js'

dist/angular-leaflet-directive.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ angular.module("leaflet-directive", []).directive('leaflet', function ($log, $q,
249249
paths: '=paths',
250250
tiles: '=tiles',
251251
layers: '=layers',
252-
customControls: '=customControls',
252+
controls: '=controls',
253253
eventBroadcast: '=eventBroadcast'
254254
},
255255
template: '<div class="angular-leaflet-map" ng-transclude></div>',
@@ -1645,6 +1645,26 @@ angular.module("leaflet-directive").directive('paths', function ($log, leafletDa
16451645
};
16461646
});
16471647

1648+
angular.module("leaflet-directive").directive('controls', function ($log) {
1649+
return {
1650+
restrict: "A",
1651+
scope: false,
1652+
replace: false,
1653+
transclude: false,
1654+
require: 'leaflet',
1655+
1656+
link: function($scope, element, attrs, controller) {
1657+
var controls = $scope.controls;
1658+
controller.getMap().then(function(map) {
1659+
if (isDefined(controls.draw)) {
1660+
var drawControl = new L.Control.Draw();
1661+
map.addControl(drawControl);
1662+
}
1663+
});
1664+
}
1665+
};
1666+
});
1667+
16481668
angular.module("leaflet-directive").directive('eventBroadcast', function ($log, $rootScope) {
16491669
return {
16501670
restrict: "A",

dist/angular-leaflet-directive.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/control-draw-example.html

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!DOCTYPE html>
2+
<html ng-app="demoapp">
3+
<head>
4+
<script src="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script>
5+
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
6+
<script src="../dist/angular-leaflet-directive.min.js"></script>
7+
<script src="plugins/Leaflet.draw/leaflet.draw.js"></script>
8+
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.css" />
9+
<link rel="stylesheet" href="plugins/Leaflet.draw/leaflet.draw.css" />
10+
<!--[if lte IE 8]>
11+
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.ie.css" />
12+
<![endif]-->
13+
<script>
14+
var app = angular.module("demoapp", ["leaflet-directive"]);
15+
app.controller("DemoController", [ "$scope", function($scope) {
16+
angular.extend($scope, {
17+
london: {
18+
lat: 51.505,
19+
lng: -0.09,
20+
zoom: 4
21+
},
22+
controls: {
23+
draw: {
24+
}
25+
}
26+
});
27+
}]);
28+
</script>
29+
<style>
30+
input {
31+
width: 120px;
32+
margin-right: 10px;
33+
}
34+
</style>
35+
</head>
36+
<body ng-controller="DemoController">
37+
<h1>Center map example</h1>
38+
<leaflet center="london" controls="controls" width="640" height="400"></leaflet>
39+
</body>
40+
</html>
2.03 KB
Loading
1.03 KB
Loading

0 commit comments

Comments
 (0)