forked from camptocamp/ngeo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AbstractDesktopController.js
244 lines (212 loc) · 6.37 KB
/
AbstractDesktopController.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/**
* @module gmf.controllers.AbstractDesktopController
*/
import gmfControllersAbstractAppController from 'gmf/controllers/AbstractAppController.js';
import gmfContextualdataModule from 'gmf/contextualdata/module.js';
import gmfDrawingModule from 'gmf/drawing/module.js';
import gmfEditingModule from 'gmf/editing/module.js';
import gmfPermalinkShareComponent from 'gmf/permalink/shareComponent.js';
import gmfPrintComponent from 'gmf/print/component.js';
import gmfProfileModule from 'gmf/profile/module.js';
import gmfRasterComponent from 'gmf/raster/component.js';
import ngeoDrawFeatures from 'ngeo/draw/features.js';
import ngeoMapResizemap from 'ngeo/map/resizemap.js';
import ngeoMiscToolActivate from 'ngeo/misc/ToolActivate.js';
import ngeoQueryBboxQueryComponent from 'ngeo/query/bboxQueryComponent.js';
import gmfImportModule from 'gmf/import/module.js';
import * as olBase from 'ol/index.js';
import * as olProj from 'ol/proj.js';
import * as olObj from 'ol/obj.js';
import olCollection from 'ol/Collection.js';
import olMap from 'ol/Map.js';
import olView from 'ol/View.js';
import olControlScaleLine from 'ol/control/ScaleLine.js';
import olControlZoom from 'ol/control/Zoom.js';
import olControlRotate from 'ol/control/Rotate.js';
import * as olInteraction from 'ol/interaction.js';
import olLayerVector from 'ol/layer/Vector.js';
import olSourceVector from 'ol/source/Vector.js';
import olStyleFill from 'ol/style/Fill.js';
import olStyleStroke from 'ol/style/Stroke.js';
import olStyleStyle from 'ol/style/Style.js';
import olStyleText from 'ol/style/Text.js';
/**
* Desktop application abstract controller.
*
* This file includes `goog.require`'s for desktop components/directives used
* by the HTML page and the controller to provide the configuration.
*
* @param {gmfx.Config} config A part of the application config.
* @param {angular.Scope} $scope Scope.
* @param {angular.$injector} $injector Main injector.
* @constructor
* @extends {gmf.controllers.AbstractAppController}
* @ngdoc controller
* @ngInject
* @export
*/
const exports = function(config, $scope, $injector) {
const viewConfig = {
projection: olProj.get(`EPSG:${config.srid || 21781}`)
};
olObj.assign(viewConfig, config.mapViewConfig || {});
const arrow = gmfControllersAbstractAppController.prototype.getLocationIcon();
/**
* @type {ol.Map}
* @export
*/
this.map = new olMap({
pixelRatio: config.mapPixelRatio,
layers: [],
view: new olView(viewConfig),
controls: config.mapControls || [
new olControlScaleLine({
target: document.getElementById('scaleline')
}),
new olControlZoom({
zoomInTipLabel: '',
zoomOutTipLabel: ''
}),
new olControlRotate({
label: arrow,
tipLabel: ''
})
],
interactions: config.mapInteractions || olInteraction.defaults({
pinchRotate: true,
altShiftDragRotate: true
}),
loadTilesWhileAnimating: true,
loadTilesWhileInteracting: true
});
/**
* @type {boolean}
* @export
*/
this.loginActive = false;
/**
* @type {boolean}
* @export
*/
this.toolsActive = false;
/**
* @type {boolean}
* @export
*/
this.modalShareShown = false;
/**
* @type {boolean}
* @export
*/
this.editFeatureActive = false;
/**
* @type {boolean}
* @export
*/
this.routingfeatureActive = false;
/**
* @type {boolean}
* @export
*/
this.googleStreetViewActive = false;
/**
* @type {!ol.style.Style}
* @export
*/
this.googleStreetViewStyle = new olStyleStyle({
text: new olStyleText({
fill: new olStyleFill({color: '#279B61'}),
font: 'normal 30px FontAwesome',
offsetY: -15,
stroke: new olStyleStroke({color: '#ffffff', width: 3}),
text: '\uf041'
})
});
/**
* @type {boolean}
* @export
*/
this.importDataSourceActive = false;
const body = $('body');
// initialize tooltips
body.tooltip({
container: 'body',
trigger: 'hover',
selector: '[data-toggle="tooltip"]'
});
// deactivate tooltips on touch device
body.on('touchstart.detectTouch', () => {
body.tooltip('destroy');
body.off('touchstart.detectTouch');
});
const ngeoFeatureHelper = $injector.get('ngeoFeatureHelper');
/**
* @type {ol.layer.Vector}
* @export
*/
this.editFeatureVectorLayer = new olLayerVector({
source: new olSourceVector({
wrapX: false,
features: new olCollection()
}),
style: (feature, resolution) => ngeoFeatureHelper.createEditingStyles(feature)
// style: ngeoFeatureHelper.createEditingStyles.bind(ngeoFeatureHelper)
});
this.editFeatureVectorLayer.setMap(this.map);
/**
* The ngeo ToolActivate manager service.
* @type {ngeo.misc.ToolActivateMgr}
*/
const ngeoToolActivateMgr = $injector.get('ngeoToolActivateMgr');
const editFeatureActivate = new ngeoMiscToolActivate(this, 'editFeatureActive');
ngeoToolActivateMgr.registerTool('mapTools', editFeatureActivate, false);
const googleStreetViewActivate = new ngeoMiscToolActivate(
this,
'googleStreetViewActive'
);
ngeoToolActivateMgr.registerTool('mapTools', googleStreetViewActivate, false);
/**
* @type {ngeox.ScaleselectorOptions}
* @export
*/
this.scaleSelectorOptions = {
dropup: true
};
/**
* @type {ol.geom.LineString}
* @export
*/
this.profileLine = null;
gmfControllersAbstractAppController.call(this, config, $scope, $injector);
// Close the login panel on successful login.
$scope.$watch(() => this.gmfUser.username, (newVal) => {
if (newVal !== null && this.loginActive) {
this.loginActive = false;
}
});
};
olBase.inherits(exports, gmfControllersAbstractAppController);
exports.module = angular.module('GmfAbstractDesktopControllerModule', [
gmfControllersAbstractAppController.module.name,
gmfContextualdataModule.name,
gmfDrawingModule.name,
gmfEditingModule.name,
gmfPermalinkShareComponent.name,
gmfPrintComponent.name,
gmfProfileModule.name,
gmfRasterComponent.name,
ngeoDrawFeatures.name,
ngeoMapResizemap.name,
ngeoQueryBboxQueryComponent.name,
gmfImportModule.name,
]);
exports.module.controller(
'AbstractDesktopController',
exports);
exports.module.value('isDesktop', true);
exports.module.value('ngeoQueryOptions', {
'limit': 20
});
exports.module.value('ngeoMeasurePrecision', 3);
exports.module.value('ngeoMeasureDecimals', 0);
export default exports;