3const char* coord_handler = R
"JS(/* src/js/coord_handler.js */
7 if (typeof(bbox) === 'string'){
10 this.left = parseFloat(bbox[0]);
11 this.top = parseFloat(bbox[3]);
12 this.width = parseFloat(bbox[2]) - this.left;
13 this.height = parseFloat(bbox[1]) - this.top;
22Coord2D.prototype.readEvent = function(ev){
23 this.cbox = ev.target.getBoundingClientRect();
24 this.x = ev.clientX - this.cbox.left;
25 this.y = ev.clientY - this.cbox.top;
30function CoordHandler(bboxGeo, bboxFrame){
31 this.bboxFrame = bboxFrame; // coordTracker.getBoundingClientRect();
32 this.bboxGeo = new BBox(bboxGeo);
34 this.curr = new Coord2D()
35 this.start = new Coord2D()
38CoordHandler.prototype.readEvent = function(ev, coords){
39 this.bboxFrame = ev.target.getBoundingClientRect();
40 coords.x = ev.clientX - this.bboxFrame.left;
41 coords.y = ev.clientY - this.bboxFrame.top;
42 if (this.precisionFocus){
43 coords.x = this.precisionFocus*Math.round(coords.x/this.precisionFocus);
44 coords.y = this.precisionFocus*Math.round(coords.y/this.precisionFocus);
48CoordHandler.prototype.update = function(coord, elem){};
49CoordHandler.prototype.updateSpanElem = function(elem, x,y,width,height){};
51CoordHandler.prototype.updateSpan = function(elem){
53 var width = Math.abs(this.start.x - this.curr.x);
54 var height = Math.abs(this.start.y - this.curr.y);
56 if (this.precisionWidth){
57 width = this.precisionWidth*Math.round(width / this.precisionWidth);
58 height = this.precisionWidth*Math.round(height / this.precisionWidth);
61 this.updateSpanElem(elem,
62 Math.min(this.start.x, this.curr.x),
63 Math.min(this.start.y, this.curr.y),
67 //elem.textContent = this.getPosString(coord.x, coord.y);
70CoordHandler.prototype.setPrecision = function(precision){
71 if (typeof(precision) === 'number'){
72 this.precisionFocus = precision;
73 this.precisionWidth = precision;
75 else if (typeof(precision) === 'string'){
76 precision = precision.split(RegExp('[,:]'))
79 console.log("precision: ", precision, "px")
81 switch (precision.length) {
83 this.precisionFocus = parseInt(precision[0]);
84 this.precisionWidth = parseInt(precision[1]);
87 this.precisionFocus = parseInt(precision[0]);
88 this.precisionWidth = this.precisionFocus
91 this.precisionFocus = parseInt(precision[1]);
92 this.precisionWidth = precision;
96CoordHandler.prototype.getRelativeX = function(x){
97 //return (x - this.bboxFrame.left)/this.bboxFrame.width;
98 return x/this.bboxFrame.width;
101CoordHandler.prototype.getRelativeY = function(y){
102 // return (y - this.bboxFrame.top)/this.bboxFrame.height;
103 return y/this.bboxFrame.height;
106CoordHandler.prototype.getLongitude = function(xRel){
107 return this.bboxGeo.left + xRel*this.bboxGeo.width;
110CoordHandler.prototype.getLatitude = function(yRel){
111 return this.bboxGeo.top + (1.0-yRel)*this.bboxGeo.height;
115CoordHandler.prototype.getGeoPos = function(x,y){
116 return [ Math.round(this.getLongitude(this.getRelativeX(x))),
117 Math.round(this.getLatitude(this.getRelativeY(y))) ]
120CoordHandler.prototype.getGeoBBOX = function(){
121 var x0 = Math.min(this.start.x, this.curr.x)
122 var x = Math.max(this.start.x, this.curr.x)
123 var y0 = Math.min(this.start.y, this.curr.y)
124 var y = Math.max(this.start.y, this.curr.y)
126 return [].concat(this.getGeoPos(x0, y0 ),
127 this.getGeoPos(x, y ))
130CoordHandler.prototype.getPosString = function(x,y){
132 var xRel = this.getRelativeX(x);
133 var yRel = this.getRelativeY(y);
134 x = Math.round(this.getLongitude(xRel));
135 y = Math.round(this.getLatitude(yRel));
138 // a.push(this.drag);