/
getWMSFeatureComponent.js
151 lines (127 loc) · 3.69 KB
/
getWMSFeatureComponent.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import angular from 'angular';
import gmfObjecteditingQuery from 'gmf/objectediting/Query.js';
import * as olEvents from 'ol/events.js';
/**
* @type {!angular.IModule}
* @hidden
*/
const module = angular.module('gmfObjecteditingGetWMSFeatureComponent', [
gmfObjecteditingQuery.name,
]);
/**
* When activated, this directive registers clicks on an OL3 map and use the
* clicked coordinate to fetch a feature using the ObjectEditing query service.
* A feature returned is pushed to a collection.
*
* Example:
*
* <gmf-objecteditinggetwmsfeature
* gmf-objecteditinggetwmsfeature-active="ctrl.active"
* gmf-objecteditinggetwmsfeature-features="ctrl.features"
* gmf-objecteditinggetwmsfeature-layerinfo="ctrl.layerInfo"
* gmf-objecteditinggetwmsfeature-map="::ctrl.map">
* </gmf-objecteditinggetwmsfeature>
*
* @htmlAttribute {boolean} gmf-objecteditinggetwmsfeature-active Whether the
* directive is active or not.
* @htmlAttribute {import("ol/Collection.js").default} gmf-objecteditinggetwmsfeature-features
* The collection of features where to add those created by this directive.
* @htmlAttribute {import('gmf/objectediting/toolsComponent.js').ObjectEditingQueryableLayerInfo}
* gmf-objecteditinggetwmsfeature-layerinfo Queryable layer info.
* @htmlAttribute {import("ol/Map.js").default} gmf-objecteditinggetwmsfeature-map The map.
* @return {angular.IDirective} The directive specs.
* @ngInject
* @ngdoc directive
* @ngname gmfObjecteditinggetwmsfeature
*/
function objectEditingGetWMSFeatureComponent() {
return {
controller: 'gmfObjecteditinggetwmsfeatureController',
scope: {
'active': '=gmfObjecteditinggetwmsfeatureActive',
'features': '<gmfObjecteditinggetwmsfeatureFeatures',
'layerInfo': '=gmfObjecteditinggetwmsfeatureLayerinfo',
'map': '<gmfObjecteditinggetwmsfeatureMap'
},
bindToController: true
};
}
module.directive('gmfObjecteditinggetwmsfeature', objectEditingGetWMSFeatureComponent);
/**
* @param {!angular.IScope} $scope Scope.
* @param {import("gmf/objectediting/Query.js").ObjectEditingQuery} gmfObjectEditingQuery GMF ObjectEditing
* query service.
* @constructor
* @private
* @hidden
* @ngInject
* @ngdoc controller
* @ngname GmfObjecteditinggetwmsfeatureController
*/
function Controller($scope, gmfObjectEditingQuery) {
// Scope properties
/**
* @type {boolean}
*/
this.active;
$scope.$watch(
() => this.active,
this.handleActiveChange_.bind(this)
);
/**
* @type {import("ol/Collection.js").default}
*/
this.features;
/**
* @type {import('gmf/objectediting/toolsComponent.js').ObjectEditingQueryableLayerInfo}
*/
this.layerInfo;
/**
* @type {import("ol/Map.js").default}
*/
this.map;
// Injected properties
/**
* @type {import("gmf/objectediting/Query.js").ObjectEditingQuery}
* @private
*/
this.gmfObjectEditingQuery_ = gmfObjectEditingQuery;
}
/**
* @param {boolean} active Active.
* @private
*/
Controller.prototype.handleActiveChange_ = function(active) {
if (active) {
olEvents.listen(
this.map,
'click',
this.handleMapClick_,
this
);
} else {
olEvents.unlisten(
this.map,
'click',
this.handleMapClick_,
this
);
}
};
/**
* @param {import("ol/MapBrowserEvent.js").default} evt Event.
* @private
*/
Controller.prototype.handleMapClick_ = function(evt) {
this.gmfObjectEditingQuery_.getFeatureInfo(
this.layerInfo,
evt.coordinate,
this.map
).then((feature) => {
if (feature) {
this.features.push(feature);
}
});
};
module.controller('gmfObjecteditinggetwmsfeatureController', Controller);
export default module;