/**
|
* 截屏按钮
|
*
|
* @author haoml
|
*/
|
define([ "dojo", "dojo/dom", "dojo/query", "dojo/on", "dojo/request", "dojo/dom-construct", "dojo/_base/window",
|
"dojo/dom-style", "dojo/dom-attr", "dojo/_base/declare", "base/AppEvent",
|
"controls/toolbar/tools/BaseTool","controls/toolbar/tools/Jcrop/Jcrop"
|
], function(dojo, dom, query, on,
|
request, domConstruct, win, domStyle, domAttr, declare,
|
AppEvent, BaseTool) {
|
var RL = declare([ BaseTool ], {
|
_map : null,
|
coord:null,
|
oricoord:null,
|
mapStyle:null,
|
jcrop_api:null,
|
constructor : function(args) {
|
this._normalIconClass = "tool-screenWindow-normal";
|
this._overIconClass = "tool-screenWindow-over";
|
this._selectedIconClass = "tool-screenWindow-select";
|
this._disableClass = "";
|
this.tooltip = "截屏";
|
this._map = args.map;
|
dojo.create("link", {
|
href: "controls/toolbar/tools/Jcrop/jquery.Jcrop.min.css",
|
type: "text/css",
|
rel: "stylesheet"
|
},
|
document.getElementsByTagName("head")[0]);
|
dojo.create("link", {
|
href: "controls/toolbar/tools/Jcrop/save.css",
|
type: "text/css",
|
rel: "stylesheet"
|
},
|
document.getElementsByTagName("head")[0]);
|
},
|
deactivate : function(args) {
|
this.inherited(arguments);
|
},
|
activate : function() {
|
this.inherited(arguments);
|
var thisObj = this;
|
mapStyle = domAttr.get(dom.byId("mainMapWidget"), "style");
|
jQuery(function($) {
|
$("#mainMapWidget").Jcrop({
|
onChange : getCoords
|
}, function() {
|
thisObj.jcrop_api = this;
|
});
|
});
|
on(dom.byId("btnCancel"), "click", destroyClick);
|
on(dom.byId("btnSave"), "click", postClick);
|
function getCoords(coords) {
|
thisObj.coord = coords;
|
if(thisObj.oricoord == null || (thisObj.oricoord.screenx != coords.screenx || thisObj.oricoord.screeny != coords.screeny)){
|
thisObj.oricoord = thisObj.coord;
|
}
|
|
var saveDiv = dom.byId("saveDiv");
|
domStyle.set(saveDiv, "display", "block");
|
domStyle.set(saveDiv, "top", coords.y
|
+ coords.h - saveDiv.clientHeight + "px");
|
|
var saveDivleft = 0;
|
if((coords.x + coords.w + saveDiv.clientWidth) > dom.byId("mainMapWidget").clientWidth)
|
saveDivleft = coords.x - saveDiv.clientWidth;
|
else
|
saveDivleft = coords.x + coords.w;
|
domStyle.set(saveDiv, "left", saveDivleft + "px");
|
}
|
|
function destroyClick() {
|
domConstruct.place(dom.byId("mainMapWidget"),query(".jcrop-holder")[0],"before");
|
domAttr.remove(dom.byId("mainMapWidget"),"style");
|
domAttr.set(dom.byId("mainMapWidget"),"style",thisObj.mapStyle);
|
thisObj.jcrop_api.destroy();
|
domStyle.set(dom.byId("saveDiv"), "display", "none");
|
thisObj.oricoord = null;
|
}
|
|
function postClick() {
|
var offx = 0;
|
var offy = 0;
|
offx = thisObj.coord.x - thisObj.oricoord.x;
|
offy = thisObj.coord.y - thisObj.oricoord.y;
|
var top = thisObj.coord.screeny + offy;
|
var left = thisObj.coord.screenx + offx;
|
var x = thisObj.coord.x;
|
var y = thisObj.coord.y;
|
var x2 = thisObj.coord.x2;
|
var y2 = thisObj.coord.y2;
|
|
var rightx2 = (x2 - x) + left;
|
var righty2 = (y2 - y) + top;
|
window.location.href = "../ScreenWindowServlet?x=" + left + "&y=" + top + "&x1=" + rightx2 + "&y1=" + righty2;
|
destroyClick();
|
}
|
|
this.deactivate();
|
}
|
});
|
return RL;
|
});
|