-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathtoolExportMapService.js
106 lines (97 loc) · 5.09 KB
/
toolExportMapService.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
(function (angular) {
'use strict';
/**
* @memberof spApp
* @ngdoc service
* @name ToolExportMapService
* @description
* Client side tool to export the map as an image
*/
angular.module('tool-export-map-service', [])
.factory("ToolExportMapService", ["$http", "$q", "MapService", "LayersService", "LayoutService",
function ($http, $q, MapService, LayersService, LayoutService) {
return {
// Override text with view-config.json
spec: {
"input": [
{
"name": "caption",
"description": $i18n(530),
"type": "text",
"constraints": {
"optional": true
}
},
{
"name": "format",
"description": $i18n(529),
"type": "list",
"constraints": {
"default": "png",
"selection": "single",
"content": [
"png",
"jpg",
"pdf"
],
"optional": false
}
}],
"description": $i18n(425)
},
execute: function (inputs) {
var leafletmap = $('.angular-leaflet-map');
var outputType = inputs[1];
var resolution = "0.01";
var bbox = MapService.getExtents();
var windowSize = [leafletmap.width(), leafletmap.height()];
var comment = inputs[0];
var baseMap = $SH.baseLayers[MapService.leafletScope.baseMap].exportType;
var mapLayers = [];
for (var k in MapService.leafletLayers) {
if (MapService.leafletLayers.hasOwnProperty(k)) {
if (k !== 'draw' && k.match(/highlight.*/) == null && k !== 'images') {
var group = MapService.leafletLayers[k].layerOptions.layers;
for (var j in group) {
var i = group[j];
var url = i.url;
if (url.indexOf('?') < 0) url += '?';
//Adding a quick fix for the issue that exporting map without areas
//Todo Mapservice may be a better place to put this fix
url += "&bbox=" + bbox.join();
url += "&width=" + windowSize[0] + "&height=" + windowSize[1]
url += "&service=WMS&request=GetMap"
//end fix
for (var j in i.layerParams) {
if (i.layerParams.hasOwnProperty(j) && i.layerParams[j] !== undefined) {
url += '&' + j + '=' + i.layerParams[j]
}
}
//Check if opacity has been defined
if (url.indexOf("opacity") == -1)
url += "&opacity=" + (i.opacity);
mapLayers.push(url)
}
}
}
}
var data = {processName: 'MapImage'};
data.overrideValues = {
MapImage: {
input: {
outputType: {constraints: {'default': outputType}},
resolution: {constraints: {'default': resolution}},
bbox: {constraints: {'default': bbox}},
windowSize: {constraints: {'default': windowSize}},
comment: {constraints: {'default': comment}},
baseMap: {constraints: {'default': baseMap}},
mapLayers: {constraints: {'default': mapLayers}}
}
},
'stage': 'execute'
};
LayoutService.openModal('tool', data, false);
}
};
}])
}(angular));