-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
264 lines (232 loc) · 8.11 KB
/
Copy pathapp.js
File metadata and controls
264 lines (232 loc) · 8.11 KB
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
require([
"esri/SpatialReference",
"esri/map",
"esri/dijit/Search",
"esri/layers/FeatureLayer",
"esri/InfoTemplate",
"dojo/domReady!",
"dojo/on",
"esri/basemaps",
"esri/tasks/PrintTask",
"esri/tasks/PrintParameters",
"esri/tasks/DataFile",
"esri/layers/ArcGISDynamicMapServiceLayer",
"esri/geometry/Polygon",
"esri/symbols/SimpleFillSymbol",
"esri/symbols/SimpleLineSymbol",
"esri/Color",
"esri/graphic",
"esri/tasks/PrintTemplate",
"esri/geometry/Point",
// Custom modules
"config.js",
"PrintDialog.js"
],
function (
SpatialReference,
Map,
Search,
FeatureLayer,
InfoTemplate,
domReady,
on,
esriBasemaps,
PrintTask,
PrintParameters,
DataFile,
ArcGISDynamicMapServiceLayer,
Polygon,
SimpleFillSymbol,
SimpleLineSymbol,
Color,
Graphic,
PrintTemplate,
Point,
// Custom modules
Config,
PrintDialog
) {
var map = new Map("map");
map.addLayer(ArcGISDynamicMapServiceLayer(
Config.baseMap,{
useMapImage: true
}
))
on(map, 'layers-add-result', function() {
map.zoom(12);
map.centerAt(new Point([102236, 6214000],new SpatialReference({ wkid:3008 })));
});
var printBoundsLayer = new esri.layers.GraphicsLayer();
map.addLayer(printBoundsLayer)
// Used to store searches, active property, jobs and more while the user navigates
window.state = {
jobs: {}
}
var search = new Search({
sources: [
{
featureLayer: new FeatureLayer(Config.fastighetFeatureServer, {
infoTemplate: new InfoTemplate("${fastighet}", PrintDialog.html())}),
outFields: ["fastighet"],
displayField: "fastighet",
suggestionTemplate: "${fastighet}",
name: "Fastighet",
placeholder: "Sök fastighet eller adress...",
minCharacters: 2,
enableSuggestions: true,
autoNavigate: false
},
{
featureLayer: new FeatureLayer(Config.adressFeatureServer, {
infoTemplate: new InfoTemplate("${RealEstateName}", PrintDialog.html())}),
outFields: ["Name", "RealEstateName"],
displayField: "Name",
suggestionTemplate: "${RealEstateName} - ${Name}",
name: "Adress",
placeholder: "Sök fastighet eller adress...",
minCharacters: 2,
enableSuggestions: true,
autoNavigate: false
}
],
allPlaceholder: "Sök fastighet eller adress ...",
map: map,
enableSourcesMenu: false
}, "search");
search.startup();
window.submitPrintJob = function() {
var selectedProperty = window.state.selectedProperty;
var printTask = new PrintTask(Config.printingService + "/GPServer/Export%20Web%20Map");
//$('#print-result').append('<div id="loader" class="lds-dual-ring"></div>')
$('#print-form').hide();
$('#print-result').hide();
$('#print-loading').show();
var template = new PrintTemplate();
template.exportOptions = {};
template.format = "PDF";
template.layout = $("#template").val() ;
template.preserveScale = false;
var params = new PrintParameters();
params.map = map;
params.extraParameters = {}
params.extraParameters.Web_Map_as_JSON = webMapAsJSON()
params.template = template
printTask.execute(params, function(result) {
$('#print-loading').hide();
$('#print-result').show();
PrintDialog.showResult(result)
}, function(error) {
$('#print-loading').hide();
$('#print-error').show();
console.log("Fail", error)
});
}
function webMapAsJSON() {
return JSON.stringify(
{
"mapOptions":{
"showAttribution":false,
"extent": map.extent,
"spatialReference":{
"wkid":3008
},
"scale": parseInt($("#scale").val())
},
"operationalLayers":[
{
"id":"defaultBasemap",
"title":"Topografisk världskarta",
"opacity":1,
"minScale":0,
"maxScale":0,
"url": Config.mapToPrint
}
],
"exportOptions":{
"dpi":240
},
"layoutOptions":{
"titleText":"",
"authorText":"",
"copyrightText":"",
"customTextElements":[
{"fastighet": window.state.selectedProperty}
],
"scaleBarOptions":{
},
"legendOptions":{
"operationalLayers":[
]
}
},
"layout": $("#template").val()
}
)
}
// As soon as user selects adress/fastighet
on(search,'select-result', function(e) {
// After a result is selected, subsequent imidiate searches ignores the searchstring and fetches OBJECTID=0. 3.25 bug? Tried the following:
//$("#search_input").val(''); // no effect but prompts the user to write something new UPDATE: BREAKS IE11
//search.set('value',''); // closes current selection
//search.hide(); // no effect
//search.show(); // no effect
// Override normal
map.setScale(500)
map.centerAt(
new Point(
(e.result.extent.xmin+e.result.extent.xmax)/2,
(e.result.extent.ymin+e.result.extent.ymax)/2,
new SpatialReference({ wkid:3008 })
)
)
setInterval(function() {
window.updatePrintExtent()
}, 500);
// Case Adress - use RealEstateName
if(e.result.feature.attributes.RealEstateName) {
window.state.selectedProperty = e.result.feature.attributes.RealEstateName;
return
}
// Case Fastighet use fastighet
window.state.selectedProperty = e.result.feature.attributes.fastighet;
});
// Hide help on search focus
on(search,'focus', function(e) {
window.closeModal()
});
window.closeModal = function() {
$.modal.close()
}
window.updatePrintExtent = function() {
printBoundsLayer.clear()
var poly = new Polygon({
"rings": [ printBounds() ],
"spatialReference":{"wkid":3008 }
});
var fs = new SimpleFillSymbol(
SimpleFillSymbol.STYLE_SOLID,
new SimpleLineSymbol(
SimpleLineSymbol.STYLE_DASH,
new Color([255,0,0]),
2
),
new Color([255,255,0,0.01])
);
printBoundsLayer.add(new Graphic(poly, fs));
}
function printBounds() {
var scale = parseInt($("#scale").val())
var format = $("#template").val()
var xmin = map.extent.getCenter().x-scale*Config.paperSpace[format].width/2
var ymin = map.extent.getCenter().y-scale*Config.paperSpace[format].height/2
var xmax = map.extent.getCenter().x+scale*Config.paperSpace[format].width/2
var ymax = map.extent.getCenter().y+scale*Config.paperSpace[format].height/2
return [
[xmin, ymin],
[xmax, ymin],
[xmax, ymax],
[xmin, ymax],
[xmin, ymin]
]
}
});