|
@@ -7,214 +7,110 @@ var single_image_view = function(option, success) {
|
|
|
|
|
|
function SingleImageView(option) {
|
|
function SingleImageView(option) {
|
|
this.markControl = option.markControl;
|
|
this.markControl = option.markControl;
|
|
- this.defaultZoom = 100;
|
|
|
|
- this.loading = false;
|
|
|
|
this.init();
|
|
this.init();
|
|
|
|
+ this.markControl.on('center.width.change', this, function(event, context, eventObject) {
|
|
|
|
+ this.reloadImage();
|
|
|
|
+ this.markControl.trigger('image.reload.event');
|
|
|
|
+ });
|
|
this.markControl.on('step.board.show', this, function(event, context, eventObject) {
|
|
this.markControl.on('step.board.show', this, function(event, context, eventObject) {
|
|
this.container.removeClass('span12');
|
|
this.container.removeClass('span12');
|
|
this.container.addClass('span10');
|
|
this.container.addClass('span10');
|
|
-
|
|
|
|
- this.container.perfectScrollbar('update');
|
|
|
|
- if (this.iviewer != undefined) {
|
|
|
|
- this.iviewer.iviewer('update');
|
|
|
|
- }
|
|
|
|
|
|
+ this.reloadImage();
|
|
|
|
+ this.markControl.trigger('image.reload.event');
|
|
});
|
|
});
|
|
this.markControl.on('step.board.hide', this, function(event, context, eventObject) {
|
|
this.markControl.on('step.board.hide', this, function(event, context, eventObject) {
|
|
this.container.removeClass('span10');
|
|
this.container.removeClass('span10');
|
|
this.container.addClass('span12');
|
|
this.container.addClass('span12');
|
|
-
|
|
|
|
- this.container.perfectScrollbar('update');
|
|
|
|
- if (this.iviewer != undefined) {
|
|
|
|
- this.iviewer.iviewer('update');
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- this.markControl.on('center.width.change', this, function(event, context, eventObject) {
|
|
|
|
- this.container.perfectScrollbar('update');
|
|
|
|
- if (this.iviewer != undefined) {
|
|
|
|
- this.iviewer.iviewer('update');
|
|
|
|
- this.iviewer.iviewer('fit');
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- this.markControl.on('view.sidebar.open', this, function(event, context, eventObject) {
|
|
|
|
- this.imageControl.hide();
|
|
|
|
- });
|
|
|
|
- this.markControl.on('view.sidebar.close', this, function(event, context, eventObject) {
|
|
|
|
- this.imageControl.show();
|
|
|
|
|
|
+ this.reloadImage();
|
|
|
|
+ this.markControl.trigger('image.reload.event');
|
|
});
|
|
});
|
|
this.markControl.on('task.get.before', this, function(event, context, eventObject) {
|
|
this.markControl.on('task.get.before', this, function(event, context, eventObject) {
|
|
this.task = undefined;
|
|
this.task = undefined;
|
|
|
|
+ this.image = undefined;
|
|
this.render();
|
|
this.render();
|
|
});
|
|
});
|
|
this.markControl.on('task.get.success', this, function(event, context, eventObject) {
|
|
this.markControl.on('task.get.success', this, function(event, context, eventObject) {
|
|
this.task = context.task;
|
|
this.task = context.task;
|
|
|
|
+ this.image = undefined;
|
|
this.render();
|
|
this.render();
|
|
});
|
|
});
|
|
this.markControl.on('task.get.none', this, function(event, context, eventObject) {
|
|
this.markControl.on('task.get.none', this, function(event, context, eventObject) {
|
|
this.task = undefined;
|
|
this.task = undefined;
|
|
|
|
+ this.image = undefined;
|
|
this.render();
|
|
this.render();
|
|
});
|
|
});
|
|
|
|
+ this.markControl.on('mark.tag.show', this, function(event, context, tag){
|
|
|
|
+ if(this.task != undefined && tag != undefined){
|
|
|
|
+ this.drawTag(tag);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ this.markControl.on('mark.tag.clear', this, function(event, context, track){
|
|
|
|
+ this.reloadImage();
|
|
|
|
+ this.markControl.trigger('image.reload.event');
|
|
|
|
+ });
|
|
this.markControl.on('image.position.change', this, function(event, context, topPercent) {
|
|
this.markControl.on('image.position.change', this, function(event, context, topPercent) {
|
|
- if (this.task != undefined && this.loading == false) {
|
|
|
|
|
|
+ if (this.task != undefined) {
|
|
this.updateScrollTop(topPercent);
|
|
this.updateScrollTop(topPercent);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
SingleImageView.prototype.init = function() {
|
|
SingleImageView.prototype.init = function() {
|
|
- this.configCache = {};
|
|
|
|
-
|
|
|
|
- //this.container = getDom(this.container_dom).appendTo(this.markControl.container.imageContent);
|
|
|
|
|
|
+ var self = this;
|
|
this.container = this.markControl.container.imageContent;
|
|
this.container = this.markControl.container.imageContent;
|
|
this.container.height(this.markControl.container.centerContent.height());
|
|
this.container.height(this.markControl.container.centerContent.height());
|
|
- this.container.perfectScrollbar({
|
|
|
|
- wheelSpeed: 20
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- this.imageHolder = getDom(this.image_holder_dom, this.markControl).appendTo(this.container);
|
|
|
|
- this.imageHolder.width('100%');
|
|
|
|
-
|
|
|
|
- this.imageControl = getDom(this.image_control_dom, this.markControl).insertBefore(this.markControl.container.assistantButton.parent());
|
|
|
|
- this.imageControl.find('.zoom-out-button').click(this, function(event) {
|
|
|
|
- var iviewer = event.data.iviewer;
|
|
|
|
- if (iviewer != undefined) {
|
|
|
|
- iviewer.iviewer('zoom_by', 1);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- this.imageControl.find('.zoom-in-button').click(this, function(event) {
|
|
|
|
- var iviewer = event.data.iviewer;
|
|
|
|
- if (iviewer != undefined) {
|
|
|
|
- iviewer.iviewer('zoom_by', -1);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- this.imageControl.find('.zoom-fit-button').click(this, function(event) {
|
|
|
|
- var iviewer = event.data.iviewer;
|
|
|
|
- if (iviewer != undefined) {
|
|
|
|
- iviewer.iviewer('fit');
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- this.imageControl.find('.zoom-origin-button').click(this, function(event) {
|
|
|
|
- var iviewer = event.data.iviewer;
|
|
|
|
- if (iviewer != undefined) {
|
|
|
|
- iviewer.iviewer('set_zoom', 100);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- this.imageControl.find('.rotate-button').click(this, function(event) {
|
|
|
|
- var iviewer = event.data.iviewer;
|
|
|
|
- if (iviewer != undefined) {
|
|
|
|
- iviewer.iviewer('angle', 90);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- var self = this;
|
|
|
|
- this.container.scroll(function() {
|
|
|
|
- if (self.currentConfig != undefined) {
|
|
|
|
- self.currentConfig.scrollTop = self.container.scrollTop() / self.imageHolder.height();
|
|
|
|
- self.currentConfig.scrollLeft = self.container.scrollLeft() / self.imageHolder.width();
|
|
|
|
|
|
+ this.container.css('overflow','scroll');
|
|
|
|
+
|
|
|
|
+ this.canvas = $('<canvas></canvas>').appendTo(this.container)[0];
|
|
|
|
+ this.ctx = this.canvas.getContext("2d");
|
|
|
|
+
|
|
|
|
+ $(this.canvas).click(function(event){
|
|
|
|
+ if(self.task != undefined){
|
|
|
|
+ self.markControl.trigger('image.click.event', {
|
|
|
|
+ positionX: ((event.pageX - $(self.canvas).offset().left)/$(self.canvas).width()).toFixed(3),
|
|
|
|
+ positionY: ((event.pageY - $(self.canvas).offset().top)/$(self.canvas).height()).toFixed(3)
|
|
|
|
+ });
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
SingleImageView.prototype.render = function() {
|
|
SingleImageView.prototype.render = function() {
|
|
- if (this.task != undefined) {
|
|
|
|
- var config = this.configCache[this.task.blockId];
|
|
|
|
- if (config == undefined) {
|
|
|
|
- config = {
|
|
|
|
- zoom: this.defaultZoom
|
|
|
|
- };
|
|
|
|
- this.configCache[this.task.blockId] = config;
|
|
|
|
- }
|
|
|
|
- this.currentConfig = config;
|
|
|
|
-
|
|
|
|
- this.loadImage();
|
|
|
|
- // this.imageControl.show();
|
|
|
|
- // this.imageHolder.show();
|
|
|
|
- // this.imageHolder.trigger('mouseenter');
|
|
|
|
- } else {
|
|
|
|
- this.imageControl.hide();
|
|
|
|
- this.imageHolder.hide();
|
|
|
|
- this.currentConfig = undefined;
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-SingleImageView.prototype.loadImage = function() {
|
|
|
|
- if (this.task.imageData != undefined && this.loading == false) {
|
|
|
|
- this.loading = true;
|
|
|
|
- if (this.iviewer == undefined) {
|
|
|
|
- var self = this;
|
|
|
|
- this.iviewer = this.imageHolder.iviewer({
|
|
|
|
- src: self.task.imageData,
|
|
|
|
- zoom_delta: 1.2,
|
|
|
|
- zoom: 100,
|
|
|
|
- zoom_min: 10,
|
|
|
|
- ui_disabled: true,
|
|
|
|
- mousewheel: false,
|
|
|
|
- zoom_animation: false,
|
|
|
|
- onAfterZoom: function(ev, new_zoom) {
|
|
|
|
- self.onZoomSet(new_zoom);
|
|
|
|
- },
|
|
|
|
- onStopDrag: function(ev, point) {
|
|
|
|
- self.onStopDrag(point);
|
|
|
|
- },
|
|
|
|
- onFinishLoad: function(ev, url) {
|
|
|
|
- self.onImageLoad();
|
|
|
|
- },
|
|
|
|
- angle: function(ev, info) {
|
|
|
|
- self.onRotate(info.angle);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- this.imageHolder.css('overflow', '');
|
|
|
|
- } else {
|
|
|
|
- this.iviewer.iviewer('loadImage', this.task.imageData);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-SingleImageView.prototype.onImageLoad = function() {
|
|
|
|
- this.loading = false;
|
|
|
|
- this.container.scrollTop(0);
|
|
|
|
- if (this.currentConfig != undefined && this.currentConfig.zoom != undefined && this.currentConfig.zoom != this.defaultZoom) {
|
|
|
|
- if (this.currentConfig.rotate != undefined && this.currentConfig.rotate > 0) {
|
|
|
|
- this.iviewer.iviewer('angle', this.currentConfig.rotate);
|
|
|
|
- }
|
|
|
|
- if (this.currentConfig.zoom != undefined && this.currentConfig.zoom != this.defaultZoom) {
|
|
|
|
- this.iviewer.iviewer('set_zoom', this.currentConfig.zoom);
|
|
|
|
|
|
+ var self = this;
|
|
|
|
+ $(this.canvas).hide();
|
|
|
|
+ if (this.task != undefined && this.task.imageData != undefined) {
|
|
|
|
+ //设置画布大小及背景颜色
|
|
|
|
+ this.image = new Image();
|
|
|
|
+ this.image.src = this.task.imageData;
|
|
|
|
+ this.image.onload = function(){
|
|
|
|
+ self.canvas.width = Math.min(self.container.width(), self.image.width);
|
|
|
|
+ self.canvas.height = self.canvas.width * self.image.height / self.image.width;
|
|
|
|
+ self.ctx.fillStyle = "#FFFFFF";
|
|
|
|
+ self.ctx.drawImage(self.image, 0, 0, self.image.width, self.image.height, 0, 0, self.canvas.width, self.canvas.height);
|
|
|
|
+ $(self.canvas).show();
|
|
|
|
+
|
|
|
|
+ self.markControl.trigger('task.load.finish');
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
- //this.imageHolder.find('img').css('border', '2px solid');
|
|
|
|
-
|
|
|
|
- // if (this.currentConfig.dx != undefined && this.currentConfig.dy != undefined) {
|
|
|
|
- // this.iviewer.iviewer('moveTo', this.currentConfig.dx, this.currentConfig.dy);
|
|
|
|
- // }
|
|
|
|
- this.imageControl.show();
|
|
|
|
- this.imageHolder.show();
|
|
|
|
- this.imageHolder.trigger('mouseenter');
|
|
|
|
-
|
|
|
|
- this.markControl.trigger('task.load.finish');
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-SingleImageView.prototype.onZoomSet = function(zoom) {
|
|
|
|
- if (this.loading == false && this.currentConfig != undefined) {
|
|
|
|
- this.currentConfig.zoom = zoom;
|
|
|
|
- this.updateScrollTop(this.currentConfig.scrollTop);
|
|
|
|
- this.updateScrollLeft(this.currentConfig.scrollLeft);
|
|
|
|
|
|
+SingleImageView.prototype.reloadImage = function() {
|
|
|
|
+ if(this.image != undefined){
|
|
|
|
+ this.canvas.width = Math.min(this.container.width(), this.image.width);
|
|
|
|
+ this.canvas.height = this.canvas.width * this.image.height / this.image.width;
|
|
|
|
+ this.ctx.drawImage(this.image, 0, 0, this.image.width, this.image.height, 0, 0, this.canvas.width, this.canvas.height);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-SingleImageView.prototype.onStopDrag = function(point) {
|
|
|
|
- if (this.loading == false) {
|
|
|
|
- this.currentConfig.dx = point.x;
|
|
|
|
- this.currentConfig.dy = point.y;
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-SingleImageView.prototype.onRotate = function(angle) {
|
|
|
|
- if (this.loading == false) {
|
|
|
|
- this.currentConfig.rotate = angle;
|
|
|
|
|
|
+SingleImageView.prototype.drawTag = function(tag){
|
|
|
|
+ if(tag!=undefined && tag.positionX>0 && tag.positionY>0){
|
|
|
|
+ this.ctx.font ="60px Arial";
|
|
|
|
+ this.ctx.fillStyle = 'red';
|
|
|
|
+ this.ctx.fillText(tag.content, tag.positionX*this.canvas.width, tag.positionY*this.canvas.height);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
SingleImageView.prototype.updateScrollTop = function(scrollTopPercent) {
|
|
SingleImageView.prototype.updateScrollTop = function(scrollTopPercent) {
|
|
- var height = this.imageHolder.height();
|
|
|
|
|
|
+ var height = this.canvas.height;
|
|
var minHeight = this.container.height();
|
|
var minHeight = this.container.height();
|
|
if (scrollTopPercent != undefined && scrollTopPercent >= 0 && scrollTopPercent <= 1 && height > minHeight) {
|
|
if (scrollTopPercent != undefined && scrollTopPercent >= 0 && scrollTopPercent <= 1 && height > minHeight) {
|
|
var left = height * (1 - scrollTopPercent);
|
|
var left = height * (1 - scrollTopPercent);
|
|
@@ -223,28 +119,4 @@ SingleImageView.prototype.updateScrollTop = function(scrollTopPercent) {
|
|
} else {
|
|
} else {
|
|
this.container.scrollTop(0);
|
|
this.container.scrollTop(0);
|
|
}
|
|
}
|
|
-}
|
|
|
|
-
|
|
|
|
-SingleImageView.prototype.updateScrollLeft = function(scrollLeftPercent) {
|
|
|
|
- var width = this.imageHolder.width();
|
|
|
|
- var minWidth = this.container.width();
|
|
|
|
- if (scrollLeftPercent != undefined && scrollLeftPercent >= 0 && scrollLeftPercent <= 1 && width > minWidth) {
|
|
|
|
- var left = width * (1 - scrollLeftPercent);
|
|
|
|
- var scrollLeft = left > minWidth ? (width - left) : (width - minWidth);
|
|
|
|
- this.container.scrollLeft(scrollLeft);
|
|
|
|
- } else {
|
|
|
|
- this.container.scrollLeft(0);
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-SingleImageView.prototype.container_dom = '<div class="image-content"></div>';
|
|
|
|
-
|
|
|
|
-SingleImageView.prototype.image_control_dom = '<em>\
|
|
|
|
-<a href="#" class="btn zoom-out-button">放大</a>\
|
|
|
|
-<a href="#" class="btn zoom-in-button">缩小</a>\
|
|
|
|
-<a href="#" class="btn zoom-fit-button">适应</a>\
|
|
|
|
-<a href="#" class="btn zoom-origin-button">原始</a>\
|
|
|
|
-<a href="#" class="btn rotate-button">旋转</a>\
|
|
|
|
-</em>';
|
|
|
|
-
|
|
|
|
-SingleImageView.prototype.image_holder_dom = '<div style="position: relative;"></div>';
|
|
|
|
|
|
+}
|