Skip to content

Commit ce28844

Browse files
committed
v1.19.0
2 parents 7a205ce + c3fd475 commit ce28844

File tree

6 files changed

+130
-43
lines changed

6 files changed

+130
-43
lines changed

dist/angular-openlayers-directive.js

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,8 @@ angular.module('openlayers-directive').directive('olView', ["$log", "$q", "olDat
663663
};
664664
}]);
665665

666-
angular.module('openlayers-directive').directive('olControl', ["$log", "$q", "olData", "olMapDefaults", "olHelpers", function($log, $q, olData, olMapDefaults, olHelpers) {
667-
666+
angular.module('openlayers-directive')
667+
.directive('olControl', ["$log", "$q", "olData", "olMapDefaults", "olHelpers", function($log, $q, olData, olMapDefaults, olHelpers) {
668668
return {
669669
restrict: 'E',
670670
scope: {
@@ -677,29 +677,58 @@ angular.module('openlayers-directive').directive('olControl', ["$log", "$q", "ol
677677
var olScope = controller.getOpenlayersScope();
678678
var olControl;
679679
var olControlOps;
680+
var getControlClasses = olHelpers.getControlClasses;
681+
var controlClasses = getControlClasses();
680682

681683
olScope.getMap().then(function(map) {
682-
var getControlClasses = olHelpers.getControlClasses;
683-
var controlClasses = getControlClasses();
684684

685685
scope.$on('$destroy', function() {
686686
map.removeControl(olControl);
687687
});
688688

689-
if (!isDefined(scope.properties) || !isDefined(scope.properties.control)) {
690-
if (attrs.name) {
691-
if (isDefined(scope.properties)) {
692-
olControlOps = scope.properties;
689+
scope.$watch('properties', function(properties) {
690+
if (!isDefined(properties)) {
691+
return;
692+
}
693+
694+
initCtrls(properties);
695+
});
696+
697+
function initCtrls(properties) {
698+
if (properties && properties.control) {
699+
// the control instance is already defined,
700+
// so simply use it and go ahead
701+
702+
// is there already a control, so destroy and recreate it?
703+
if (olControl) {
704+
map.removeControl(olControl);
693705
}
694-
olControl = new controlClasses[attrs.name](olControlOps);
706+
707+
olControl = properties.control;
695708
map.addControl(olControl);
709+
} else {
710+
711+
// the name is the key to instantiate an ol3 control
712+
if (attrs.name) {
713+
if (isDefined(properties)) {
714+
olControlOps = properties;
715+
}
716+
717+
// is there already a control, so destroy and recreate it?
718+
if (olControl) {
719+
map.removeControl(olControl);
720+
}
721+
722+
olControl = new controlClasses[attrs.name](olControlOps);
723+
map.addControl(olControl);
724+
}
696725
}
697-
return;
698726
}
699727

700-
olControl = scope.properties.control;
701-
map.addControl(olControl);
728+
initCtrls(scope.properties);
729+
702730
});
731+
703732
}
704733
};
705734
}]);

dist/angular-openlayers-directive.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/angular-openlayers-directive.min.no-header.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/angular-openlayers-directive.pre.js

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,8 @@ angular.module('openlayers-directive').directive('olView', function($log, $q, ol
663663
};
664664
});
665665

666-
angular.module('openlayers-directive').directive('olControl', function($log, $q, olData, olMapDefaults, olHelpers) {
667-
666+
angular.module('openlayers-directive')
667+
.directive('olControl', function($log, $q, olData, olMapDefaults, olHelpers) {
668668
return {
669669
restrict: 'E',
670670
scope: {
@@ -677,29 +677,58 @@ angular.module('openlayers-directive').directive('olControl', function($log, $q,
677677
var olScope = controller.getOpenlayersScope();
678678
var olControl;
679679
var olControlOps;
680+
var getControlClasses = olHelpers.getControlClasses;
681+
var controlClasses = getControlClasses();
680682

681683
olScope.getMap().then(function(map) {
682-
var getControlClasses = olHelpers.getControlClasses;
683-
var controlClasses = getControlClasses();
684684

685685
scope.$on('$destroy', function() {
686686
map.removeControl(olControl);
687687
});
688688

689-
if (!isDefined(scope.properties) || !isDefined(scope.properties.control)) {
690-
if (attrs.name) {
691-
if (isDefined(scope.properties)) {
692-
olControlOps = scope.properties;
689+
scope.$watch('properties', function(properties) {
690+
if (!isDefined(properties)) {
691+
return;
692+
}
693+
694+
initCtrls(properties);
695+
});
696+
697+
function initCtrls(properties) {
698+
if (properties && properties.control) {
699+
// the control instance is already defined,
700+
// so simply use it and go ahead
701+
702+
// is there already a control, so destroy and recreate it?
703+
if (olControl) {
704+
map.removeControl(olControl);
693705
}
694-
olControl = new controlClasses[attrs.name](olControlOps);
706+
707+
olControl = properties.control;
695708
map.addControl(olControl);
709+
} else {
710+
711+
// the name is the key to instantiate an ol3 control
712+
if (attrs.name) {
713+
if (isDefined(properties)) {
714+
olControlOps = properties;
715+
}
716+
717+
// is there already a control, so destroy and recreate it?
718+
if (olControl) {
719+
map.removeControl(olControl);
720+
}
721+
722+
olControl = new controlClasses[attrs.name](olControlOps);
723+
map.addControl(olControl);
724+
}
696725
}
697-
return;
698726
}
699727

700-
olControl = scope.properties.control;
701-
map.addControl(olControl);
728+
initCtrls(scope.properties);
729+
702730
});
731+
703732
}
704733
};
705734
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,5 @@
6565
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
6666
},
6767
"main": "dist/angular-openlayers-directive",
68-
"version": "1.18.1"
68+
"version": "1.19.0"
6969
}

src/directives/control.js

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
angular.module('openlayers-directive').directive('olControl', function($log, $q, olData, olMapDefaults, olHelpers) {
2-
1+
angular.module('openlayers-directive')
2+
.directive('olControl', function($log, $q, olData, olMapDefaults, olHelpers) {
33
return {
44
restrict: 'E',
55
scope: {
@@ -12,29 +12,58 @@ angular.module('openlayers-directive').directive('olControl', function($log, $q,
1212
var olScope = controller.getOpenlayersScope();
1313
var olControl;
1414
var olControlOps;
15+
var getControlClasses = olHelpers.getControlClasses;
16+
var controlClasses = getControlClasses();
1517

1618
olScope.getMap().then(function(map) {
17-
var getControlClasses = olHelpers.getControlClasses;
18-
var controlClasses = getControlClasses();
1919

2020
scope.$on('$destroy', function() {
2121
map.removeControl(olControl);
2222
});
2323

24-
if (!isDefined(scope.properties) || !isDefined(scope.properties.control)) {
25-
if (attrs.name) {
26-
if (isDefined(scope.properties)) {
27-
olControlOps = scope.properties;
24+
scope.$watch('properties', function(properties) {
25+
if (!isDefined(properties)) {
26+
return;
27+
}
28+
29+
initCtrls(properties);
30+
});
31+
32+
function initCtrls(properties) {
33+
if (properties && properties.control) {
34+
// the control instance is already defined,
35+
// so simply use it and go ahead
36+
37+
// is there already a control, so destroy and recreate it?
38+
if (olControl) {
39+
map.removeControl(olControl);
2840
}
29-
olControl = new controlClasses[attrs.name](olControlOps);
41+
42+
olControl = properties.control;
3043
map.addControl(olControl);
44+
} else {
45+
46+
// the name is the key to instantiate an ol3 control
47+
if (attrs.name) {
48+
if (isDefined(properties)) {
49+
olControlOps = properties;
50+
}
51+
52+
// is there already a control, so destroy and recreate it?
53+
if (olControl) {
54+
map.removeControl(olControl);
55+
}
56+
57+
olControl = new controlClasses[attrs.name](olControlOps);
58+
map.addControl(olControl);
59+
}
3160
}
32-
return;
3361
}
3462

35-
olControl = scope.properties.control;
36-
map.addControl(olControl);
63+
initCtrls(scope.properties);
64+
3765
});
66+
3867
}
3968
};
4069
});

0 commit comments

Comments
 (0)