diff --git a/.wvr/build-config.js b/.wvr/build-config.js index ace746c6..9f3ed938 100644 --- a/.wvr/build-config.js +++ b/.wvr/build-config.js @@ -61,7 +61,7 @@ const config = { './node_modules/angular-ui-bootstrap/dist/ui-bootstrap-tpls.js', './node_modules/ng-table/bundles/ng-table.js', './node_modules/openseadragon/build/openseadragon/openseadragon.js', - './node_modules/ng-openseadragon/build/angular-openseadragon.js', + './src/main/webapp/app/resources/scripts/ng-openseadragon/build/angular-openseadragon.js', './node_modules/@wvr/core/app/config/coreConfig.js', './node_modules/@wvr/core/app/components/version/version.js', './node_modules/@wvr/core/app/components/version/version-directive.js', diff --git a/package.json b/package.json index 810174aa..ada78cf0 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,6 @@ "dependencies": { "@wvr/core": "2.2.2-rc.14", "ng-csv": "0.3.6", - "ng-openseadragon": "1.3.5", "ng-table": "3.0.1", "openseadragon": "2.4.0" }, diff --git a/src/main/webapp/app/resources/scripts/ng-openseadragon/LICENSE b/src/main/webapp/app/resources/scripts/ng-openseadragon/LICENSE new file mode 100644 index 00000000..35cb5601 --- /dev/null +++ b/src/main/webapp/app/resources/scripts/ng-openseadragon/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014 Damien DALY + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/src/main/webapp/app/resources/scripts/ng-openseadragon/build/angular-openseadragon.js b/src/main/webapp/app/resources/scripts/ng-openseadragon/build/angular-openseadragon.js new file mode 100644 index 00000000..6074deb6 --- /dev/null +++ b/src/main/webapp/app/resources/scripts/ng-openseadragon/build/angular-openseadragon.js @@ -0,0 +1,152 @@ +"use strict"; +(function () { + var module = angular.module("ui.openseadragon", []); + module.directive("seadragon", ['$timeout', function ($timeout) { + return { + restrict: "E", + scope: { + options: "=", + name: "=", + tilesource: "=", + prefixUrl: "=" + }, + controller: ["$scope", function ($scope) { + $scope.osd = null; + }], + link: function (scope, element, attrs) { + + + + if (attrs.tilesource) { + opts.tileSources = [attrs.tilesource]; + } + if (attrs.prefixUrl) { + opts.prefixUrl = attrs.prefixUrl; + } + + function _bootstrap() { + if (scope.osd) { + scope.osd.destroy(); + scope.osd = null; + } + //Create options object + var opts = angular.extend({}, scope.options, { + id: "openseadragon-" + Math.random(), + element: element[0], + }); + //Create the viewer + scope.osd = OpenSeadragon(opts); + //Create a wrapper + var wrapper = { + mouse: { + position: null, + imageCoord: null, + viewportCoord: null, + }, + zoom: 0, + viewport: {} + } + + for(var key in scope.osd) { + wrapper[key] = scope.osd[key]; + } + + if (attrs.name) { + //Make the OSD available to parent scope + scope.$parent[attrs.name] = wrapper; + //Define event handlers + zoomHandler = function (e) { + $timeout(function() { + scope.$apply(function () { + wrapper.zoom = e.zoom; + }); + },0); + } + updateViewportHandler = function (e) { + scope.$apply(function () { + wrapper.viewportInfo = { + bounds: scope.osd.viewport.getBounds(false), + center: scope.osd.viewport.getCenter(false), + rotation: scope.osd.viewport.getRotation(), + zoom: scope.osd.viewport.getZoom(false), + }; + }); + } + + //Assign event handlers + scope.osd.addHandler("zoom", zoomHandler); + scope.osd.addHandler("update-viewport", updateViewportHandler); + + //Add a mouse handler + scope.mouse = new OpenSeadragon.MouseTracker({ + element: scope.osd.canvas, + enterHandler: function (e) { + if (scope.osd.viewport) { + var coord = OpenSeadragon.getElementPosition(scope.osd.canvas); + var pos = e.position.plus(coord); + var mouse = { + position: pos, + imageCoord: scope.osd.viewport.windowToImageCoordinates(pos), + viewportCoord: scope.osd.viewport.windowToViewportCoordinates(pos), + } + scope.$apply(function () { + wrapper.mouse = mouse; + }); + } + }, + moveHandler: function (e) { + if (scope.osd.viewport) { + var coord = OpenSeadragon.getElementPosition(scope.osd.canvas); + var pos = e.position.plus(coord); + var mouse = { + position: pos, + imageCoord: scope.osd.viewport.windowToImageCoordinates(pos), + viewportCoord: scope.osd.viewport.windowToViewportCoordinates(pos), + } + scope.$apply(function () { + wrapper.mouse = mouse; + }); + } + }, + exitHandler: function (e) { + scope.$apply(function () { + wrapper.mouse.position = null; + wrapper.mouse.imageCoord = null; + wrapper.mouse.viewportCoord = null; + }); + }, + }); + scope.mouse.setTracking(true); + } + + } + _bootstrap(); + var optionsWatcher = scope.$watch('options', _bootstrap); + + //if @name is set, put the wrapper in the scope and handle the events + var zoomHandler = null; + var updateViewportHandler = null; + + + //When element is destroyed, destroy the viewer + element.on('$destroy', function () { + //if @nam eis set, remove it from parent scope, and remove event handlers + if (attrs.name) { + //Remove from parent scope + scope.$parent[attrs.name] = null; + + //Destroy mouse handler + scope.mouse.destroy(); + optionsWatcher(); + //Remove event handlers + scope.osd.removeHandler("zoom", zoomHandler); + scope.osd.removeHandler("update-viewport", updateViewportHandler); + } + + //Destroy the viewer + scope.osd.destroy(); + }); + }, + }; + }]); +})(); \ No newline at end of file diff --git a/src/main/webapp/app/resources/scripts/ng-openseadragon/build/ng-openseadragon.min.js b/src/main/webapp/app/resources/scripts/ng-openseadragon/build/ng-openseadragon.min.js new file mode 100644 index 00000000..87798070 --- /dev/null +++ b/src/main/webapp/app/resources/scripts/ng-openseadragon/build/ng-openseadragon.min.js @@ -0,0 +1 @@ +"use strict";angular.module("ui.openseadragon",[]).directive("seadragon",["$timeout",function(o){return{restrict:"E",scope:{options:"=",name:"=",tilesource:"=",prefixUrl:"="},controller:["$scope",function(o){o.osd=null}],link:function(e,n,t){function r(){e.osd&&(e.osd.destroy(),e.osd=null);var r=angular.extend({},e.options,{id:"openseadragon-"+Math.random(),element:n[0]});e.osd=OpenSeadragon(r);var i={mouse:{position:null,imageCoord:null,viewportCoord:null},zoom:0,viewport:{}};for(var a in e.osd)i[a]=e.osd[a];t.name&&(e.$parent[t.name]=i,s=function(n){o(function(){e.$apply(function(){i.zoom=n.zoom})},0)},d=function(o){e.$apply(function(){i.viewportInfo={bounds:e.osd.viewport.getBounds(!1),center:e.osd.viewport.getCenter(!1),rotation:e.osd.viewport.getRotation(),zoom:e.osd.viewport.getZoom(!1)}})},e.osd.addHandler("zoom",s),e.osd.addHandler("update-viewport",d),e.mouse=new OpenSeadragon.MouseTracker({element:e.osd.canvas,enterHandler:function(o){if(e.osd.viewport){var n=OpenSeadragon.getElementPosition(e.osd.canvas),t=o.position.plus(n),r={position:t,imageCoord:e.osd.viewport.windowToImageCoordinates(t),viewportCoord:e.osd.viewport.windowToViewportCoordinates(t)};e.$apply(function(){i.mouse=r})}},moveHandler:function(o){if(e.osd.viewport){var n=OpenSeadragon.getElementPosition(e.osd.canvas),t=o.position.plus(n),r={position:t,imageCoord:e.osd.viewport.windowToImageCoordinates(t),viewportCoord:e.osd.viewport.windowToViewportCoordinates(t)};e.$apply(function(){i.mouse=r})}},exitHandler:function(o){e.$apply(function(){i.mouse.position=null,i.mouse.imageCoord=null,i.mouse.viewportCoord=null})}}),e.mouse.setTracking(!0))}t.tilesource&&(opts.tileSources=[t.tilesource]),t.prefixUrl&&(opts.prefixUrl=t.prefixUrl),r();var i=e.$watch("options",r),s=null,d=null;n.on("$destroy",function(){t.name&&(e.$parent[t.name]=null,e.mouse.destroy(),i(),e.osd.removeHandler("zoom",s),e.osd.removeHandler("update-viewport",d)),e.osd.destroy()})}}}]); \ No newline at end of file