web/lib/admin/ol_drag.js   A
last analyzed

Complexity

Total Complexity 13
Complexity/F 1.86

Size

Lines of Code 84
Function Count 7

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 13
eloc 59
c 0
b 0
f 0
dl 0
loc 84
rs 10
mnd 6
bc 6
fnc 7
bpm 0.8571
cpm 1.8571
noi 2

6 Functions

Rating   Name   Duplication   Size   Complexity  
A ol_drag.js ➔ basicFeatureHandler 0 3 1
A ol_drag.js ➔ handleMoveEvent 0 18 5
A ol_drag.js ➔ handleDownEvent 0 12 3
A ol_drag.js ➔ layerFilter 0 6 2
A ol_drag.js ➔ handleDragEvent 0 16 1
A ol_drag.js ➔ handleUpEvent 0 6 1
1
/* 
2
 * this code based on https://openlayers.org/en/latest/examples/custom-interactions.html
3
 */
4
5
/** global: ol */
6
/** global: tmpLayer */
7
8
window.app = {};
9
var app = window.app;
10
app.Drag = function () {
11
    ol.interaction.Pointer.call(this, {
12
        handleDownEvent: handleDownEvent,
13
        handleDragEvent: handleDragEvent,
14
        handleMoveEvent: handleMoveEvent,
15
        handleUpEvent: handleUpEvent
16
    });
17
18
    this.coordinate_ = null;
19
    this.cursor_ = 'pointer';
20
    this.feature_ = null;
21
    this.previousCursor_ = undefined;
22
};
23
24
ol.inherits(app.Drag, ol.interaction.Pointer);
25
26
function handleDownEvent(evt) {
27
    var map = evt.map;
28
    var feature = map.forEachFeatureAtPixel(evt.pixel,
29
            basicFeatureHandler,
30
            {layerFilter: layerFilter}
31
    );
32
    if (feature) {
33
        this.coordinate_ = evt.coordinate;
34
        this.feature_ = feature;
35
    }
36
    return !!feature;
37
}
38
39
function handleDragEvent(evt) {
40
    var map = evt.map;
41
    var feature = map.forEachFeatureAtPixel(evt.pixel,
0 ignored issues
show
Unused Code introduced by
The variable feature seems to be never used. Consider removing it.
Loading history...
42
            basicFeatureHandler,
43
            {layerFilter: layerFilter});
44
45
    var deltaX = evt.coordinate[0] - this.coordinate_[0];
46
    var deltaY = evt.coordinate[1] - this.coordinate_[1];
47
48
    var geometry = /** @type {ol.geom.SimpleGeometry} */
49
            (this.feature_.getGeometry());
50
    geometry.translate(deltaX, deltaY);
51
52
    this.coordinate_[0] = evt.coordinate[0];
53
    this.coordinate_[1] = evt.coordinate[1];
54
}
55
56
function handleMoveEvent(evt) {
57
    if (this.cursor_) {
58
        var map = evt.map;
59
        var feature = map.forEachFeatureAtPixel(evt.pixel,
60
                basicFeatureHandler,
61
                {layerFilter: layerFilter});
62
        var element = evt.map.getTargetElement();
63
        if (feature) {
64
            if (element.style.cursor != this.cursor_) {
65
                this.previousCursor_ = element.style.cursor;
66
                element.style.cursor = this.cursor_;
67
            }
68
        } else if (this.previousCursor_ !== undefined) {
69
            element.style.cursor = this.previousCursor_;
70
            this.previousCursor_ = undefined;
71
        }
72
    }
73
}
74
75
function handleUpEvent(evt) {
76
    setTmpPointer(evt.coordinate);
77
    this.coordinate_ = null;
78
    this.feature_ = null;
79
    return false;
80
}
81
82
function layerFilter(layer) {
83
    if (layer === tmpLayer) {
84
        return(true);
85
    }
86
    return(false);
87
}
88
89
function basicFeatureHandler(feature, layer) {
0 ignored issues
show
Unused Code introduced by
The parameter layer is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
90
    return(feature);
91
}
92
93
94