1
|
|
|
/** |
2
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
3
|
|
|
* |
4
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
5
|
|
|
* |
6
|
|
|
* @license GNU General Public License version 3 or later. |
7
|
|
|
* For the full copyright and license information, please read the |
8
|
|
|
* LICENSE.txt file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @TODO Trigger resize map event after fullscreen is toggled |
13
|
|
|
* @param {Object} settings |
14
|
|
|
* {string=} div |
15
|
|
|
* {Array.<?>} images |
16
|
|
|
* {Array.<?>} fulltexts |
17
|
|
|
* {Array.<?>} controls |
18
|
|
|
* @constructor |
19
|
|
|
*/ |
20
|
|
|
var dlfViewer = function(settings){ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* The element id of the map container |
24
|
|
|
* @type {string} |
25
|
|
|
* @private |
26
|
|
|
*/ |
27
|
|
|
this.div = dlfUtils.exists(settings.div) ? settings.div : "tx-dlf-map"; |
|
|
|
|
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Openlayers map object |
31
|
|
|
* @type {ol.Map|null} |
32
|
|
|
* @private |
33
|
|
|
*/ |
34
|
|
|
this.map = null; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Contains image information (e.g. URL, width, height) |
38
|
|
|
* @type {Array.<string>} |
39
|
|
|
* @private |
40
|
|
|
*/ |
41
|
|
|
this.imageUrls = dlfUtils.exists(settings.images) ? settings.images : []; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Contains image information (e.g. URL, width, height) |
45
|
|
|
* @type {Array.<{src: *, width: *, height: *}>} |
46
|
|
|
* @private |
47
|
|
|
*/ |
48
|
|
|
this.images = []; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Fulltext information (e.g. URL) |
52
|
|
|
* @type {Array.<string|?>} |
53
|
|
|
* @private |
54
|
|
|
*/ |
55
|
|
|
this.fulltexts = dlfUtils.exists(settings.fulltexts) ? settings.fulltexts : []; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @type {Array.<number>} |
59
|
|
|
* @private |
60
|
|
|
*/ |
61
|
|
|
this.highlightFields = []; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @type {Object|undefined} |
65
|
|
|
* @private |
66
|
|
|
*/ |
67
|
|
|
this.highlightFieldParams = undefined; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @type {Object|undefined} |
71
|
|
|
* @private |
72
|
|
|
*/ |
73
|
|
|
this.imageManipulationControl = undefined; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @type {Object|undefined} |
77
|
|
|
* @private |
78
|
|
|
*/ |
79
|
|
|
this.selection = undefined; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @type {Object|undefined} |
83
|
|
|
* @private |
84
|
|
|
*/ |
85
|
|
|
this.source = undefined; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @type {Object|undefined} |
89
|
|
|
* @private |
90
|
|
|
*/ |
91
|
|
|
this.selectionLayer = undefined; |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @type {Object|undefined} |
95
|
|
|
* @private |
96
|
|
|
*/ |
97
|
|
|
this.draw = undefined; |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @type {Object|null} |
101
|
|
|
* @private |
102
|
|
|
*/ |
103
|
|
|
this.source = null; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @type {Object|null} |
107
|
|
|
* @private |
108
|
|
|
*/ |
109
|
|
|
this.view = null; |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @type {Object|null} |
113
|
|
|
* @private |
114
|
|
|
*/ |
115
|
|
|
this.ov_view = null; |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @type {Boolean|false} |
119
|
|
|
* @private |
120
|
|
|
*/ |
121
|
|
|
this.magnifierEnabled = false; |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @type {Boolean|false} |
125
|
|
|
* @private |
126
|
|
|
*/ |
127
|
|
|
this.initMagnifier = false; |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* use internal proxy setting |
131
|
|
|
* @type {boolean} |
132
|
|
|
* @private |
133
|
|
|
*/ |
134
|
|
|
this.useInternalProxy = dlfUtils.exists(settings.useInternalProxy) ? settings.useInternalProxy : false; |
135
|
|
|
|
136
|
|
|
this.init(dlfUtils.exists(settings.controls) ? settings.controls : []); |
137
|
|
|
}; |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Methods inits and binds the custom controls to the dlfViewer. Right now that are the |
141
|
|
|
* fulltext and the image manipulation control |
142
|
|
|
* |
143
|
|
|
* @param {Array.<string>} controlNames |
144
|
|
|
*/ |
145
|
|
|
dlfViewer.prototype.addCustomControls = function(controlNames) { |
|
|
|
|
146
|
|
|
var fulltextControl = undefined, |
|
|
|
|
147
|
|
|
imageManipulationControl = undefined, |
|
|
|
|
148
|
|
|
images = this.images; |
149
|
|
|
|
150
|
|
|
// Adds fulltext behavior only if there is fulltext available and no double page |
151
|
|
|
// behavior is active |
152
|
|
|
if (this.fulltexts[0] !== undefined && this.fulltexts[0].url !== '' && this.images.length == 1) { |
153
|
|
|
fulltextControl = new dlfViewerFullTextControl(this.map, this.images[0], this.fulltexts[0].url); |
|
|
|
|
154
|
|
|
} else { |
155
|
|
|
$('#tx-dlf-tools-fulltext').remove(); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
|
159
|
|
|
// |
160
|
|
|
// Add image manipulation tool if container is added. |
161
|
|
|
// |
162
|
|
|
// It is important to know that the image manipulation tool uses a webgl renderer as basis. Therefor the |
163
|
|
|
// application has as first to check if the renderer is active. Further it has to check if cors supported through |
164
|
|
|
// image. |
165
|
|
|
// |
166
|
|
|
if ($('#tx-dlf-tools-imagetools').length > 0 && dlfUtils.isWebGLEnabled() && this.isCorsEnabled) { |
|
|
|
|
167
|
|
|
|
168
|
|
|
// should be called if cors is enabled |
169
|
|
|
imageManipulationControl = new dlfViewerImageManipulationControl({ |
|
|
|
|
170
|
|
|
controlTarget: $('.tx-dlf-tools-imagetools')[0], |
171
|
|
|
layers: dlfUtils.createOl3Layers(images, '*'), |
172
|
|
|
map: this.map, |
173
|
|
|
view: dlfUtils.createOl3View(images) |
174
|
|
|
}); |
175
|
|
|
|
176
|
|
|
// bind behavior of both together |
177
|
|
|
if (imageManipulationControl !== undefined && fulltextControl !== undefined) { |
178
|
|
|
$(imageManipulationControl).on("activate-imagemanipulation", $.proxy(fulltextControl.deactivate, fulltextControl)); |
179
|
|
|
$(fulltextControl).on("activate-fulltext", $.proxy(imageManipulationControl.deactivate, imageManipulationControl)); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
// set on object scope |
183
|
|
|
this.imageManipulationControl = imageManipulationControl; |
184
|
|
|
|
185
|
|
|
} else if ($('#tx-dlf-tools-imagetools').length > 0) { |
186
|
|
|
|
187
|
|
|
// hide the element because the functionality is not supported through missing webgl or cors support. |
188
|
|
|
$('#tx-dlf-tools-imagetools').addClass('deactivate'); |
189
|
|
|
|
190
|
|
|
} |
191
|
|
|
}; |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* Add highlight field |
195
|
|
|
* |
196
|
|
|
* @param {Array.<number>} highlightField |
197
|
|
|
* @param {number} imageIndex |
198
|
|
|
* @param {number} width |
199
|
|
|
* @param {number} height |
200
|
|
|
* |
201
|
|
|
* @return void |
202
|
|
|
*/ |
203
|
|
|
dlfViewer.prototype.addHighlightField = function(highlightField, imageIndex, width, height) { |
204
|
|
|
|
205
|
|
|
this.highlightFields.push(highlightField); |
206
|
|
|
|
207
|
|
|
this.highlightFieldParams = { |
208
|
|
|
index: imageIndex, |
209
|
|
|
width: width, |
210
|
|
|
height: height |
211
|
|
|
}; |
212
|
|
|
|
213
|
|
|
if (this.map) |
214
|
|
|
this.displayHighlightWord(); |
|
|
|
|
215
|
|
|
}; |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* Creates OL3 controls |
219
|
|
|
* @param {Array.<string>} controlNames |
220
|
|
|
* @param {Array.<ol.layer.Layer> layers |
|
|
|
|
221
|
|
|
* @return {Array.<ol.control.Control>} |
222
|
|
|
* @private |
223
|
|
|
*/ |
224
|
|
|
dlfViewer.prototype.createControls_ = function(controlNames, layers) { |
225
|
|
|
|
226
|
|
|
var controls = []; |
227
|
|
|
|
228
|
|
|
for (var i in controlNames) { |
|
|
|
|
229
|
|
|
|
230
|
|
|
if (controlNames[i] !== "") { |
231
|
|
|
|
232
|
|
|
switch(controlNames[i]) { |
233
|
|
|
|
234
|
|
|
case "OverviewMap": |
235
|
|
|
|
236
|
|
|
controls.push(new ol.control.OverviewMap({ |
|
|
|
|
237
|
|
|
layers: layers |
238
|
|
|
})); |
239
|
|
|
break; |
240
|
|
|
|
241
|
|
|
case "ZoomPanel": |
242
|
|
|
|
243
|
|
|
controls.push(new ol.control.Zoom()); |
244
|
|
|
break; |
245
|
|
|
|
246
|
|
|
default: |
247
|
|
|
|
248
|
|
|
break; |
249
|
|
|
|
250
|
|
|
} |
251
|
|
|
} |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
return controls; |
255
|
|
|
}; |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* Displayes highlight words |
259
|
|
|
*/ |
260
|
|
|
dlfViewer.prototype.displayHighlightWord = function() { |
261
|
|
|
|
262
|
|
|
if (!dlfUtils.exists(this.highlightLayer)) { |
|
|
|
|
263
|
|
|
|
264
|
|
|
this.highlightLayer = new ol.layer.Vector({ |
|
|
|
|
265
|
|
|
'source': new ol.source.Vector(), |
266
|
|
|
'style': dlfViewerOL3Styles.wordStyle |
|
|
|
|
267
|
|
|
}); |
268
|
|
|
|
269
|
|
|
this.map.addLayer(this.highlightLayer); |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
// check if highlight by coords should be activate |
273
|
|
|
if (this.highlightFields.length > 0) { |
274
|
|
|
// clear in case of old displays |
275
|
|
|
this.highlightLayer.getSource().clear(); |
276
|
|
|
|
277
|
|
|
// create features and scale it down |
278
|
|
|
for (var i = 0; i < this.highlightFields.length; i++) { |
279
|
|
|
|
280
|
|
|
var field = this.highlightFields[i], |
281
|
|
|
coordinates = [[ |
282
|
|
|
[field[0], field[1]], |
283
|
|
|
[field[2], field[1]], |
284
|
|
|
[field[2], field[3]], |
285
|
|
|
[field[0], field[3]], |
286
|
|
|
[field[0], field[1]], |
287
|
|
|
]], |
288
|
|
|
offset = this.highlightFieldParams.index === 1 ? this.images[0].width : 0; |
289
|
|
|
var feature = dlfUtils.scaleToImageSize([new ol.Feature(new ol.geom.Polygon(coordinates))], |
290
|
|
|
this.images[this.highlightFieldParams.index], |
291
|
|
|
this.highlightFieldParams.width, |
292
|
|
|
this.highlightFieldParams.height, |
293
|
|
|
offset); |
294
|
|
|
|
295
|
|
|
// add feature to layer and map |
296
|
|
|
this.highlightLayer.getSource().addFeatures(feature); |
297
|
|
|
} |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
// check if highlight by words is set |
301
|
|
|
var key = 'tx_dlf[highlight_word]', |
302
|
|
|
urlParams = dlfUtils.getUrlParams(); |
303
|
|
|
|
304
|
|
|
if (urlParams != undefined && urlParams.hasOwnProperty(key) && this.fulltexts[0] !== undefined && this.fulltexts[0].url !== '' && this.images.length > 0) { |
305
|
|
|
var value = urlParams[key], |
306
|
|
|
values = value.split(';'), |
307
|
|
|
fulltextData = dlfViewerFullTextControl.fetchFulltextDataFromServer(this.fulltexts[0].url, this.images[0]), |
|
|
|
|
308
|
|
|
fulltextDataImageTwo = undefined; |
|
|
|
|
309
|
|
|
|
310
|
|
|
// check if there is another image / fulltext to look for |
311
|
|
|
if (this.images.length == 2 & this.fulltexts[1] !== undefined && this.fulltexts[1].url !== '') { |
|
|
|
|
312
|
|
|
var image = $.extend({}, this.images[1]); |
313
|
|
|
image.width = image.width + this.images[0].width; |
314
|
|
|
fulltextDataImageTwo = dlfViewerFullTextControl.fetchFulltextDataFromServer(this.fulltexts[1].url, this.images[1], this.images[0].width) |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
var stringFeatures = fulltextDataImageTwo === undefined ? fulltextData.getStringFeatures() : |
318
|
|
|
fulltextData.getStringFeatures().concat(fulltextDataImageTwo.getStringFeatures()); |
319
|
|
|
values.forEach($.proxy(function(value) { |
320
|
|
|
var features = dlfUtils.searchFeatureCollectionForText(stringFeatures, value); |
|
|
|
|
321
|
|
|
if (features !== undefined) { |
322
|
|
|
for (var i = 0; i < features.length; i++) { |
323
|
|
|
this.highlightLayer.getSource().addFeatures([features[i]]); |
324
|
|
|
} |
325
|
|
|
}; |
326
|
|
|
}, this)); |
327
|
|
|
}; |
328
|
|
|
}; |
329
|
|
|
|
330
|
|
|
/** |
331
|
|
|
* Start the init process of loading the map, etc. |
332
|
|
|
* |
333
|
|
|
* @param {Array.<string>} controlNames |
334
|
|
|
* @private |
335
|
|
|
*/ |
336
|
|
|
dlfViewer.prototype.init = function(controlNames) { |
337
|
|
|
|
338
|
|
|
if (this.imageUrls.length <= 0) |
339
|
|
|
throw new Error('Missing image source objects.'); |
|
|
|
|
340
|
|
|
|
341
|
|
|
/** |
342
|
|
|
* Is cors enabled. Important information for correct renderer and layer initialization |
343
|
|
|
* @type {boolean} |
344
|
|
|
*/ |
345
|
|
|
if (this.useInternalProxy) { |
346
|
|
|
this.isCorsEnabled = true; |
347
|
|
|
} else { |
348
|
|
|
this.isCorsEnabled = dlfUtils.isCorsEnabled(this.imageUrls); |
|
|
|
|
349
|
|
|
} |
350
|
|
|
|
351
|
|
|
this.initLayer(this.imageUrls, this.isCorsEnabled) |
352
|
|
|
.done($.proxy(function(layers){ |
353
|
|
|
|
354
|
|
|
var controls = controlNames.length > 0 || controlNames[0] === "" |
355
|
|
|
? this.createControls_(controlNames, layers) |
356
|
|
|
: []; |
357
|
|
|
//: [ new ol.control.MousePosition({ |
358
|
|
|
// coordinateFormat: ol.coordinate.createStringXY(4), |
359
|
|
|
// undefinedHTML: ' ' |
360
|
|
|
// })]; |
361
|
|
|
|
362
|
|
|
// create map |
363
|
|
|
this.map = new ol.Map({ |
|
|
|
|
364
|
|
|
layers: layers, |
365
|
|
|
target: this.div, |
366
|
|
|
controls: controls, |
367
|
|
|
interactions: [ |
368
|
|
|
new ol.interaction.DragRotate(), |
369
|
|
|
new ol.interaction.DragPan(), |
370
|
|
|
new ol.interaction.DragZoom(), |
371
|
|
|
new ol.interaction.PinchRotate(), |
372
|
|
|
new ol.interaction.PinchZoom(), |
373
|
|
|
new ol.interaction.MouseWheelZoom(), |
374
|
|
|
new ol.interaction.KeyboardPan(), |
375
|
|
|
new ol.interaction.KeyboardZoom, |
376
|
|
|
new ol.interaction.DragRotateAndZoom() |
377
|
|
|
], |
378
|
|
|
// necessary for proper working of the keyboard events |
379
|
|
|
keyboardEventTarget: document, |
380
|
|
|
view: dlfUtils.createOl3View(this.images), |
|
|
|
|
381
|
|
|
renderer: 'canvas' |
382
|
|
|
}); |
383
|
|
|
|
384
|
|
|
// Position image according to user preferences |
385
|
|
|
var lon = dlfUtils.getCookie("tx-dlf-pageview-centerLon"), |
386
|
|
|
lat = dlfUtils.getCookie("tx-dlf-pageview-centerLat"), |
387
|
|
|
zoom = dlfUtils.getCookie("tx-dlf-pageview-zoomLevel"); |
388
|
|
|
if (!dlfUtils.isNullEmptyUndefinedOrNoNumber(lon) && !dlfUtils.isNullEmptyUndefinedOrNoNumber(lat) && !dlfUtils.isNullEmptyUndefinedOrNoNumber(zoom)) { |
389
|
|
|
// make sure, zoom center is on viewport |
390
|
|
|
var center = this.map.getView().getCenter(); |
391
|
|
|
if ((lon < (2.2 * center[0])) && (lat < (2.2 * center[1]))) { |
392
|
|
|
this.map.zoomTo([lon, lat], zoom); |
393
|
|
|
} |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
// highlight word in case a highlight field is registered |
397
|
|
|
this.displayHighlightWord(); |
398
|
|
|
|
399
|
|
|
this.addCustomControls(controls); |
400
|
|
|
|
401
|
|
|
// trigger event after all has been initialize |
402
|
|
|
$(window).trigger("map-loadend", window); |
403
|
|
|
|
404
|
|
|
// append listener for saving view params in case of flipping pages |
405
|
|
|
$(window).unload($.proxy(function() { |
406
|
|
|
// check if image manipulation control exists and if yes deactivate it first for proper recognition of |
407
|
|
|
// the actual map view |
408
|
|
|
if (this.imageManipulationControl !== undefined && this.imageManipulationControl.isActive()) { |
409
|
|
|
this.imageManipulationControl.deactivate(); |
410
|
|
|
} |
411
|
|
|
|
412
|
|
|
var zoom = this.map.getZoom() !== undefined ? this.map.getZoom() : '', |
413
|
|
|
center = this.map.getView().getCenter() !== undefined ? this.map.getView().getCenter() : ['', '']; |
414
|
|
|
|
415
|
|
|
// save actual map view parameters to cookie |
416
|
|
|
dlfUtils.setCookie('tx-dlf-pageview-zoomLevel', zoom); |
|
|
|
|
417
|
|
|
dlfUtils.setCookie('tx-dlf-pageview-centerLon', center[0]); |
418
|
|
|
dlfUtils.setCookie('tx-dlf-pageview-centerLat', center[1]); |
419
|
|
|
}, this)); |
420
|
|
|
}, this)); |
421
|
|
|
this.source = new ol.source.Vector(); |
|
|
|
|
422
|
|
|
// crop selection style |
423
|
|
|
this.selection = new ol.interaction.DragBox({ |
424
|
|
|
condition: ol.events.condition.noModifierKeys, |
425
|
|
|
style: new ol.style.Style({ |
426
|
|
|
stroke: new ol.style.Stroke({ |
427
|
|
|
color: [0, 0, 255, 1] |
428
|
|
|
}) |
429
|
|
|
}) |
430
|
|
|
}); |
431
|
|
|
|
432
|
|
|
this.initCropping(); |
433
|
|
|
}; |
434
|
|
|
|
435
|
|
|
/** |
436
|
|
|
* Function generate the ol3 layer objects for given image sources. Returns a promise. |
437
|
|
|
* |
438
|
|
|
* @param {Array.<{url: *, mimetype: *}>} imageSourceObjs |
439
|
|
|
* @param {boolean} isCorsEnabled |
440
|
|
|
* @return {jQuery.Deferred.<function(Array.<ol.layer.Layer>)>} |
441
|
|
|
* @private |
442
|
|
|
*/ |
443
|
|
|
dlfViewer.prototype.initLayer = function(imageSourceObjs, isCorsEnabled) { |
444
|
|
|
|
445
|
|
|
// use deferred for async behavior |
446
|
|
|
var deferredResponse = new $.Deferred(), |
447
|
|
|
/** |
448
|
|
|
* @param {Array.<{src: *, width: *, height: *}>} imageSourceData |
449
|
|
|
* @param {Array.<ol.layer.Layer>} layers |
450
|
|
|
*/ |
451
|
|
|
resolveCallback = $.proxy(function(imageSourceData, layers) { |
452
|
|
|
this.images = imageSourceData; |
453
|
|
|
deferredResponse.resolve(layers); |
454
|
|
|
}, this), |
455
|
|
|
origin = isCorsEnabled ? '*' : undefined; |
456
|
|
|
|
457
|
|
|
dlfUtils.fetchImageData(imageSourceObjs) |
|
|
|
|
458
|
|
|
.done(function(imageSourceData) { |
459
|
|
|
resolveCallback(imageSourceData, dlfUtils.createOl3Layers(imageSourceData, origin)); |
|
|
|
|
460
|
|
|
}); |
461
|
|
|
|
462
|
|
|
return deferredResponse; |
463
|
|
|
}; |
464
|
|
|
|
465
|
|
|
dlfViewer.prototype.degreeToRadian = function (degree) { |
466
|
|
|
return degree * (Math.PI / 180); |
467
|
|
|
}; |
468
|
|
|
|
469
|
|
|
dlfViewer.prototype.radianToDegree = function (radian) { |
470
|
|
|
return radian * (180 / Math.PI); |
471
|
|
|
}; |
472
|
|
|
|
473
|
|
|
/** |
474
|
|
|
* activates the crop selection |
475
|
|
|
*/ |
476
|
|
|
dlfViewer.prototype.activateSelection = function () { |
477
|
|
|
var viewerObject = this; |
478
|
|
|
|
479
|
|
|
// remove all features |
480
|
|
|
viewerObject.resetCropSelection(); |
481
|
|
|
|
482
|
|
|
// add selection layer and crop interaction |
483
|
|
|
this.map.addLayer(this.selectionLayer); |
484
|
|
|
this.map.addInteraction(this.draw); |
485
|
|
|
}; |
486
|
|
|
|
487
|
|
|
/** |
488
|
|
|
* reset the crop selection |
489
|
|
|
*/ |
490
|
|
|
dlfViewer.prototype.resetCropSelection = function () { |
491
|
|
|
this.map.removeLayer(this.selectionLayer); |
492
|
|
|
this.source.clear(); |
493
|
|
|
this.setNewCropDrawer(this.source); |
494
|
|
|
}; |
495
|
|
|
|
496
|
|
|
/** |
497
|
|
|
* initialise crop selection |
498
|
|
|
*/ |
499
|
|
|
dlfViewer.prototype.initCropping = function () { |
500
|
|
|
var viewerObject = this; |
501
|
|
|
|
502
|
|
|
var source = new ol.source.Vector({wrapX: false}); |
|
|
|
|
503
|
|
|
|
504
|
|
|
this.selectionLayer = new ol.layer.Vector({ |
505
|
|
|
source: source |
506
|
|
|
}); |
507
|
|
|
|
508
|
|
|
value = 'LineString'; |
|
|
|
|
509
|
|
|
maxPoints = 2; |
|
|
|
|
510
|
|
|
geometryFunction = function(coordinates, geometry) { |
|
|
|
|
511
|
|
|
if (!geometry) { |
512
|
|
|
geometry = new ol.geom.Polygon(null); |
|
|
|
|
513
|
|
|
} |
514
|
|
|
var start = coordinates[0]; |
515
|
|
|
var end = coordinates[1]; |
516
|
|
|
geometry.setCoordinates([ |
517
|
|
|
[start, [start[0], end[1]], end, [end[0], start[1]], start] |
518
|
|
|
]); |
519
|
|
|
|
520
|
|
|
// add to basket button |
521
|
|
|
var extent = geometry.getExtent(); |
522
|
|
|
var imageExtent = viewerObject.map.getLayers().item(0).getSource().getProjection().getExtent(); |
523
|
|
|
|
524
|
|
|
var pixel = ol.extent.getIntersection(imageExtent, extent); |
525
|
|
|
var rotation = viewerObject.map.getView().getRotation(); |
526
|
|
|
|
527
|
|
|
// fill form with coordinates |
528
|
|
|
$('#addToBasketForm #startX').val(Math.round(pixel[0])); |
529
|
|
|
$('#addToBasketForm #startY').val(Math.round(pixel[1])); |
530
|
|
|
$('#addToBasketForm #endX').val(Math.round(pixel[2])); |
531
|
|
|
$('#addToBasketForm #endY').val(Math.round(pixel[3])); |
532
|
|
|
$('#addToBasketForm #rotation').val(Math.round(viewerObject.radianToDegree(rotation))); |
533
|
|
|
|
534
|
|
|
return geometry; |
535
|
|
|
}; |
536
|
|
|
|
537
|
|
|
this.setNewCropDrawer(source); |
538
|
|
|
}; |
539
|
|
|
|
540
|
|
|
/** |
541
|
|
|
* set the draw interaction for crop selection |
542
|
|
|
*/ |
543
|
|
|
dlfViewer.prototype.setNewCropDrawer = function (source) { |
544
|
|
|
viewerObject = this; |
|
|
|
|
545
|
|
|
this.draw = new ol.interaction.Draw({ |
|
|
|
|
546
|
|
|
source: source, |
547
|
|
|
type: /** @type {ol.geom.GeometryType} */ (value), |
|
|
|
|
548
|
|
|
geometryFunction: geometryFunction, |
|
|
|
|
549
|
|
|
maxPoints: maxPoints |
|
|
|
|
550
|
|
|
}); |
551
|
|
|
|
552
|
|
|
// reset crop interaction |
553
|
|
|
this.draw.on('drawend', function (event) { |
|
|
|
|
554
|
|
|
viewerObject.map.removeInteraction(viewerObject.draw); |
555
|
|
|
}); |
556
|
|
|
|
557
|
|
|
this.selectionLayer = new ol.layer.Vector({ |
|
|
|
|
558
|
|
|
source: source |
559
|
|
|
}); |
560
|
|
|
}; |
561
|
|
|
|
562
|
|
|
/** |
563
|
|
|
* add magnifier map |
564
|
|
|
*/ |
565
|
|
|
dlfViewer.prototype.addMagnifier = function (rotation) { |
566
|
|
|
|
567
|
|
|
//magnifier map |
568
|
|
|
var extent = [0, 0, 1000, 1000]; |
569
|
|
|
|
570
|
|
|
layerProj = new ol.proj.Projection({ |
|
|
|
|
571
|
|
|
code: 'goobi-image', |
572
|
|
|
units: 'pixels', |
573
|
|
|
extent: extent |
574
|
|
|
}); |
575
|
|
|
|
576
|
|
|
this.ov_view = new ol.View({ |
577
|
|
|
projection: layerProj, |
578
|
|
|
center: ol.extent.getCenter(extent), |
579
|
|
|
zoom: 3, |
580
|
|
|
rotation: rotation, |
581
|
|
|
}); |
582
|
|
|
|
583
|
|
|
this.ov_map = new ol.Map({ |
584
|
|
|
target: 'ov_map', |
585
|
|
|
view: this.ov_view, |
586
|
|
|
controls: [], |
587
|
|
|
interactions: [] |
588
|
|
|
}); |
589
|
|
|
|
590
|
|
|
this.ov_map.addLayer(this.map.getLayers().getArray()[0]); |
591
|
|
|
|
592
|
|
|
var mousePosition = null; |
593
|
|
|
var dlfViewer = this; |
594
|
|
|
var ov_map = this.ov_map; |
595
|
|
|
|
596
|
|
|
this.map.on('pointermove', function (evt) { |
597
|
|
|
mousePosition = dlfViewer.map.getEventCoordinate(evt.originalEvent); |
598
|
|
|
dlfViewer.ov_view.setCenter(mousePosition); |
599
|
|
|
}); |
600
|
|
|
|
601
|
|
|
var adjustViews = function(sourceView, destMap) { |
602
|
|
|
var rotateDiff = sourceView.getRotation() !== destMap.getView().getRotation(); |
603
|
|
|
var centerDiff = sourceView.getCenter() !== destMap.getView().getCenter(); |
604
|
|
|
|
605
|
|
|
if (rotateDiff || centerDiff) { |
606
|
|
|
destMap.getView().rotate(sourceView.getRotation()); |
607
|
|
|
} |
608
|
|
|
}, |
609
|
|
|
adjustViewHandler = function(event) { |
610
|
|
|
adjustViews(event.target, ov_map); |
611
|
|
|
}; |
612
|
|
|
|
613
|
|
|
this.map.getView().on('change:rotation', adjustViewHandler, this.map); |
614
|
|
|
adjustViews(this.map.getView(), this.ov_map); |
615
|
|
|
|
616
|
|
|
this.initMagnifier = true; |
617
|
|
|
}; |
618
|
|
|
|
619
|
|
|
/** |
620
|
|
|
* activates the magnifier map |
621
|
|
|
*/ |
622
|
|
|
dlfViewer.prototype.activateMagnifier = function () { |
623
|
|
|
if (!this.initMagnifier) { |
624
|
|
|
var rotation = this.map.getView().getRotation(); |
625
|
|
|
this.addMagnifier(rotation); |
626
|
|
|
} |
627
|
|
|
|
628
|
|
|
if (!this.magnifierEnabled) { |
629
|
|
|
$('#ov_map').show(); |
630
|
|
|
this.magnifierEnabled = true; |
631
|
|
|
} else { |
632
|
|
|
$('#ov_map').hide(); |
633
|
|
|
this.magnifierEnabled = false; |
634
|
|
|
} |
635
|
|
|
}; |
636
|
|
|
|
637
|
|
|
/** |
638
|
|
|
* @constructor |
639
|
|
|
* @extends {ol.interaction.Pointer} |
640
|
|
|
*/ |
641
|
|
|
function Drag() { |
642
|
|
|
|
643
|
|
|
ol.interaction.Pointer.call(this, { |
|
|
|
|
644
|
|
|
handleDownEvent: Drag.prototype.handleDownEvent, |
645
|
|
|
handleDragEvent: Drag.prototype.handleDragEvent, |
646
|
|
|
handleMoveEvent: Drag.prototype.handleMoveEvent, |
647
|
|
|
handleUpEvent: Drag.prototype.handleUpEvent |
648
|
|
|
}); |
649
|
|
|
|
650
|
|
|
/** |
651
|
|
|
* @type {ol.Pixel} |
652
|
|
|
* @private |
653
|
|
|
*/ |
654
|
|
|
this.coordinate_ = null; |
655
|
|
|
|
656
|
|
|
/** |
657
|
|
|
* @type {string|undefined} |
658
|
|
|
* @private |
659
|
|
|
*/ |
660
|
|
|
this.cursor_ = 'pointer'; |
661
|
|
|
|
662
|
|
|
/** |
663
|
|
|
* @type {ol.Feature} |
664
|
|
|
* @private |
665
|
|
|
*/ |
666
|
|
|
this.feature_ = null; |
667
|
|
|
|
668
|
|
|
/** |
669
|
|
|
* @type {string|undefined} |
670
|
|
|
* @private |
671
|
|
|
*/ |
672
|
|
|
this.previousCursor_ = undefined; |
673
|
|
|
|
674
|
|
|
}; |
675
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.