1 |
2 |
fpga_is_fu |
var svgdoc;
|
2 |
|
|
var svgNS = "http://www.w3.org/2000/svg";
|
3 |
|
|
var xlinkNS = "http://www.w3.org/2000/xlink/namespace/";
|
4 |
|
|
var myMapApp = new mapApp();
|
5 |
|
|
var myMainMap;
|
6 |
|
|
|
7 |
|
|
function init(evt) {
|
8 |
|
|
|
9 |
|
|
|
10 |
|
|
svgdoc = evt.target.ownerDocument;
|
11 |
|
|
myMapApp.resetFactors();
|
12 |
|
|
// mapWidth, the minimal zoomValue, the maximal zoomValue, and a zoomStep value (in our case 60% of the previous view).
|
13 |
|
|
myMainMap = new map("mainMap",912,100,1000,0.6);
|
14 |
|
|
//set constraints to draggable rect in reference map
|
15 |
|
|
}
|
16 |
|
|
|
17 |
|
|
//holds data on window size
|
18 |
|
|
function mapApp() {
|
19 |
|
|
}
|
20 |
|
|
|
21 |
|
|
//holds data on map
|
22 |
|
|
function map(mapName,origWidth,minZoom,maxZoom,zoomFact) {
|
23 |
|
|
var mapSVG = svgdoc.getElementById(mapName);
|
24 |
|
|
this.mapName = mapName;
|
25 |
|
|
this.origWidth = origWidth;
|
26 |
|
|
this.minZoom = minZoom;
|
27 |
|
|
this.maxZoom = maxZoom;
|
28 |
|
|
this.zoomFact = zoomFact;
|
29 |
|
|
this.pixXOffset = parseFloat(mapSVG.getAttributeNS(null,"x"));
|
30 |
|
|
this.pixYOffset = parseFloat(mapSVG.getAttributeNS(null,"y"));
|
31 |
|
|
viewBoxArray = mapSVG.getAttributeNS(null,"viewBox").split(" ");
|
32 |
|
|
this.curxOrig = parseFloat(viewBoxArray[0]);
|
33 |
|
|
this.curyOrig = parseFloat(viewBoxArray[1]);
|
34 |
|
|
this.curWidth = parseFloat(viewBoxArray[2]);
|
35 |
|
|
this.curHeight = parseFloat(viewBoxArray[3]);
|
36 |
|
|
this.pixWidth = parseFloat(mapSVG.getAttributeNS(null,"width"));
|
37 |
|
|
this.pixHeight = parseFloat(mapSVG.getAttributeNS(null,"height"));
|
38 |
|
|
this.pixXOrig = parseFloat(mapSVG.getAttributeNS(null,"x"));
|
39 |
|
|
this.pixYOrig = parseFloat(mapSVG.getAttributeNS(null,"y"));
|
40 |
|
|
this.pixSize = this.curWidth / this.pixWidth;
|
41 |
|
|
this.zoomVal = this.origWidth / this.curWidth * 100;
|
42 |
|
|
}
|
43 |
|
|
|
44 |
|
|
//calculate ratio and offset values of app window
|
45 |
|
|
mapApp.prototype.resetFactors = function() {
|
46 |
|
|
var svgroot = svgdoc.documentElement;
|
47 |
|
|
if (!svgroot.getScreenCTM) {
|
48 |
|
|
//case for ASV3 and Corel
|
49 |
|
|
var viewBoxArray = svgroot.getAttributeNS(null,"viewBox").split(" ");
|
50 |
|
|
var myRatio = viewBoxArray[2]/viewBoxArray[3];
|
51 |
|
|
if ((window.innerWidth/window.innerHeight) > myRatio) { //case window is more wide than myRatio
|
52 |
|
|
this.scaleFactor = viewBoxArray[3] / window.innerHeight;
|
53 |
|
|
}
|
54 |
|
|
else { //case window is more tall than myRatio
|
55 |
|
|
this.scaleFactor = viewBoxArray[2] / window.innerWidth;
|
56 |
|
|
}
|
57 |
|
|
this.offsetX = (window.innerWidth - viewBoxArray[2] * 1 / this.scaleFactor) / 2;
|
58 |
|
|
this.offsetY = (window.innerHeight - viewBoxArray[3] * 1 / this.scaleFactor) / 2;
|
59 |
|
|
}
|
60 |
|
|
}
|
61 |
|
|
mapApp.prototype.calcCoord = function(coordx,coordy) {
|
62 |
|
|
var svgroot = svgdoc.documentElement;
|
63 |
|
|
var coords = new Array();
|
64 |
|
|
if (!svgroot.getScreenCTM) {
|
65 |
|
|
//case ASV3 a. Corel
|
66 |
|
|
coords["x"] = (coordx - this.offsetX) * this.scaleFactor;
|
67 |
|
|
coords["y"] = (coordy - this.offsetY) * this.scaleFactor;
|
68 |
|
|
}
|
69 |
|
|
else {
|
70 |
|
|
matrix=svgroot.getScreenCTM();
|
71 |
|
|
coords["x"]= matrix.inverse().a*coordx+matrix.inverse().c*coordy+matrix.inverse().e;
|
72 |
|
|
coords["y"]= matrix.inverse().b*coordx+matrix.inverse().d*coordy+matrix.inverse().f;
|
73 |
|
|
}
|
74 |
|
|
return coords;
|
75 |
|
|
}
|
76 |
|
|
|
77 |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
78 |
|
|
//scrollable Map
|
79 |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
80 |
|
|
//make an element draggable with constraints
|
81 |
|
|
function dragObj(dragId,constrXmin,constrXmax,constrYmin,constrYmax,refPoint) {
|
82 |
|
|
this.dragId = dragId;
|
83 |
|
|
this.constrXmin = constrXmin;
|
84 |
|
|
this.constrXmax = constrXmax;
|
85 |
|
|
this.constrYmin = constrYmin;
|
86 |
|
|
this.constrYmax = constrYmax;
|
87 |
|
|
this.refPoint = refPoint;
|
88 |
|
|
this.status = "false";
|
89 |
|
|
}
|
90 |
|
|
dragObj.prototype.drag = function(evt) {
|
91 |
|
|
//works only for rect and use-elements
|
92 |
|
|
var myDragElement = evt.target;
|
93 |
|
|
if (evt.type == "mousedown") {
|
94 |
|
|
var coords = myMapApp.calcCoord(evt.clientX,evt.clientY);
|
95 |
|
|
this.curX = coords["x"];
|
96 |
|
|
this.curY = coords["y"];
|
97 |
|
|
this.status = "true";
|
98 |
|
|
}
|
99 |
|
|
if (evt.type == "mousemove" && this.status == "true") {
|
100 |
|
|
var coords = myMapApp.calcCoord(evt.clientX,evt.clientY);
|
101 |
|
|
var newEvtX = coords["x"];
|
102 |
|
|
var newEvtY = coords["y"];
|
103 |
|
|
var bBox = myDragElement.getBBox();
|
104 |
|
|
if (this.refPoint == "ul") {
|
105 |
|
|
var toMoveX = bBox.x + newEvtX - this.curX;
|
106 |
|
|
var toMoveY = bBox.y + newEvtY - this.curY;
|
107 |
|
|
}
|
108 |
|
|
else {
|
109 |
|
|
//refPoint = center
|
110 |
|
|
var toMoveX = bBox.x + bBox.width / 2 + newEvtX - this.curX;
|
111 |
|
|
var toMoveY = bBox.y + bBox.height / 2 + newEvtY - this.curY;
|
112 |
|
|
}
|
113 |
|
|
if ((bBox.x + newEvtX - this.curX) < this.constrXmin) {
|
114 |
|
|
if(this.refPoint == "ul") {
|
115 |
|
|
toMoveX = this.constrXmin;
|
116 |
|
|
}
|
117 |
|
|
else {
|
118 |
|
|
toMoveX = this.constrXmin + bBox.width / 2;
|
119 |
|
|
}
|
120 |
|
|
}
|
121 |
|
|
if ((bBox.x + newEvtX - this.curX + bBox.width) > this.constrXmax) {
|
122 |
|
|
if(this.refPoint == "ul") {
|
123 |
|
|
toMoveX = this.constrXmax - bBox.width;
|
124 |
|
|
}
|
125 |
|
|
else {
|
126 |
|
|
toMoveX = this.constrXmax - bBox.width / 2;
|
127 |
|
|
}
|
128 |
|
|
}
|
129 |
|
|
if ((bBox.y + newEvtY - this.curY) < this.constrYmin) {
|
130 |
|
|
if(this.refPoint == "ul") {
|
131 |
|
|
toMoveY = this.constrYmin;
|
132 |
|
|
}
|
133 |
|
|
else {
|
134 |
|
|
toMoveY = this.constrYmin + bBox.height / 2;
|
135 |
|
|
}
|
136 |
|
|
}
|
137 |
|
|
if ((bBox.y + bBox.height + newEvtY - this.curY) > this.constrYmax) {
|
138 |
|
|
if(this.refPoint == "ul") {
|
139 |
|
|
toMoveY = this.constrYmax - bBox.height;
|
140 |
|
|
}
|
141 |
|
|
else {
|
142 |
|
|
toMoveY = this.constrYmax - bBox.height / 2;
|
143 |
|
|
}
|
144 |
|
|
}
|
145 |
|
|
myDragElement.setAttributeNS(null,"x",toMoveX);
|
146 |
|
|
myDragElement.setAttributeNS(null,"y",toMoveY);
|
147 |
|
|
this.curX = newEvtX;
|
148 |
|
|
this.curY = newEvtY;
|
149 |
|
|
}
|
150 |
|
|
if (evt.type == "mouseup" || evt.type == "mouseout") {
|
151 |
|
|
this.status = "false";
|
152 |
|
|
}
|
153 |
|
|
if (evt.type == "mouseup" || evt.type == "mouseout") {
|
154 |
|
|
this.status = "false";
|
155 |
|
|
}
|
156 |
|
|
}
|