Mercurial > hg > orthanc-wsi
comparison ViewerPlugin/viewer.js @ 0:4a7a53257c7d
initial commit
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 22 Oct 2016 21:48:33 +0200 |
parents | |
children | ff0ef01c332c |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4a7a53257c7d |
---|---|
1 /** | |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * | |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU Affero General Public License | |
8 * as published by the Free Software Foundation, either version 3 of | |
9 * the License, or (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, but | |
12 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * Affero General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU Affero General Public License | |
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 **/ | |
19 | |
20 | |
21 // For IE compatibility | |
22 if (!window.console) window.console = {}; | |
23 if (!window.console.log) window.console.log = function () { }; | |
24 | |
25 | |
26 // http://stackoverflow.com/a/21903119/881731 | |
27 function GetUrlParameter(sParam) | |
28 { | |
29 var sPageURL = decodeURIComponent(window.location.search.substring(1)); | |
30 var sURLVariables = sPageURL.split('&'); | |
31 var sParameterName; | |
32 var i; | |
33 | |
34 for (i = 0; i < sURLVariables.length; i++) | |
35 { | |
36 sParameterName = sURLVariables[i].split('='); | |
37 | |
38 if (sParameterName[0] === sParam) | |
39 { | |
40 return sParameterName[1] === undefined ? '' : sParameterName[1]; | |
41 } | |
42 } | |
43 | |
44 return ''; | |
45 }; | |
46 | |
47 | |
48 | |
49 $(document).ready(function() { | |
50 var seriesId = GetUrlParameter('series'); | |
51 if (seriesId.length == 0) | |
52 { | |
53 alert('Error - No series ID specified!'); | |
54 } | |
55 else | |
56 { | |
57 $.ajax({ | |
58 url : '../pyramids/' + seriesId, | |
59 error: function() { | |
60 alert('Error - Cannot get the pyramid structure of series: ' + seriesId); | |
61 }, | |
62 success : function(series) { | |
63 var width = series['TotalWidth']; | |
64 var height = series['TotalHeight']; | |
65 var tileWidth = series['TileWidth']; | |
66 var tileHeight = series['TileHeight']; | |
67 var countLevels = series['Resolutions'].length; | |
68 | |
69 // Maps always need a projection, but Zoomify layers are not geo-referenced, and | |
70 // are only measured in pixels. So, we create a fake projection that the map | |
71 // can use to properly display the layer. | |
72 var proj = new ol.proj.Projection({ | |
73 code: 'pixel', | |
74 units: 'pixels', | |
75 extent: [0, 0, width, height] | |
76 }); | |
77 | |
78 var extent = [0, -height, width, 0]; | |
79 | |
80 // Disable the rotation of the map, and inertia while panning | |
81 // http://stackoverflow.com/a/25682186 | |
82 var interactions = ol.interaction.defaults({ | |
83 altShiftDragRotate : false, | |
84 pinchRotate : false, | |
85 dragPan: false | |
86 }).extend([ | |
87 new ol.interaction.DragPan({kinetic: false}) | |
88 ]); | |
89 | |
90 var layer = new ol.layer.Tile({ | |
91 extent: extent, | |
92 source: new ol.source.TileImage({ | |
93 projection: proj, | |
94 tileUrlFunction: function(tileCoord, pixelRatio, projection) { | |
95 return ('../tiles/' + seriesId + '/' + | |
96 (countLevels - 1 - tileCoord[0]) + '/' + tileCoord[1] + '/' + (-tileCoord[2] - 1)); | |
97 }, | |
98 tileGrid: new ol.tilegrid.TileGrid({ | |
99 extent: extent, | |
100 resolutions: series['Resolutions'].reverse(), | |
101 tileSize: [tileWidth, tileHeight] | |
102 }) | |
103 }), | |
104 wrapX: false, | |
105 projection: proj | |
106 }); | |
107 | |
108 | |
109 var map = new ol.Map({ | |
110 target: 'map', | |
111 layers: [ layer ], | |
112 view: new ol.View({ | |
113 projection: proj, | |
114 center: [width / 2, -height / 2], | |
115 zoom: 0, | |
116 minResolution: 1 // Do not interpelate over pixels | |
117 }), | |
118 interactions: interactions | |
119 }); | |
120 | |
121 map.getView().fit(extent, map.getSize()); | |
122 } | |
123 }); | |
124 } | |
125 }); |