赣州市洪水风险预警系统二维版本
xiebin
2023-02-24 ec1a74625890ff771fc5e46e39a15deaf618b479
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
 * 截屏按钮
 *
 * @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;
});