# Code coverage report for src/layer/vector/canvas/Polyline.Canvas.js

## Statements: 7.69% (1 / 13) Branches: 10% (1 / 10) Functions: 0% (0 / 1) Lines: 7.69% (1 / 13)

All files » src/layer/vector/canvas/ » Polyline.Canvas.js

    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

    1

     /*
     * Extends L.Polyline to be able to manually detect clicks on Canvas-rendered polylines.
     */

    L.Polyline.include(!L.Path.CANVAS ? {} : {
    	_containsPoint: function (p, closed) {
    		var i, j, k, len, len2, dist, part,
    		    w = this.options.weight / 2;

    		if (L.Browser.touch) {
    			w += 10; // polyline click tolerance on touch devices
    		}

    		for (i = 0, len = this._parts.length; i < len; i++) {
    			part = this._parts[i];
    			for (j = 0, len2 = part.length, k = len2 - 1; j < len2; k = j++) {
    				if (!closed && (j === 0)) {
    					continue;
    				}

    				dist = L.LineUtil.pointToSegmentDistance(p, part[k], part[j]);

    				if (dist <= w) {
    					return true;
    				}
    			}
    		}
    		return false;
    	}
    });