Code coverage report for src/layer/vector/Polygon.js

Statements: 20% (7 / 35)      Branches: 29.41% (5 / 17)      Functions: 20% (1 / 5)      Lines: 21.21% (7 / 33)     

All files » src/layer/vector/ » Polygon.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 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        1           3   3   3                         3   3                                                                                                 1      
/*
 * L.Polygon is used to display polygons on a map.
 */
 
L.Polygon = L.Polyline.extend({
	options: {
		fill: true
	},
 
	initialize: function (latlngs, options) {
		var i, len, hole;
 
		L.Polyline.prototype.initialize.call(this, latlngs, options);
 
		Iif (latlngs && L.Util.isArray(latlngs[0]) && (typeof latlngs[0][0] !== 'number')) {
			this._latlngs = this._convertLatLngs(latlngs[0]);
			this._holes = latlngs.slice(1);
 
			for (i = 0, len = this._holes.length; i < len; i++) {
				hole = this._holes[i] = this._convertLatLngs(this._holes[i]);
				if (hole[0].equals(hole[hole.length - 1])) {
					hole.pop();
				}
			}
		}
 
		// filter out last point if its equal to the first one
		latlngs = this._latlngs;
 
		Iif (latlngs[0].equals(latlngs[latlngs.length - 1])) {
			latlngs.pop();
		}
	},
 
	projectLatlngs: function () {
		L.Polyline.prototype.projectLatlngs.call(this);
 
		// project polygon holes points
		// TODO move this logic to Polyline to get rid of duplication
		this._holePoints = [];
 
		if (!this._holes) { return; }
 
		var i, j, len, len2;
 
		for (i = 0, len = this._holes.length; i < len; i++) {
			this._holePoints[i] = [];
 
			for (j = 0, len2 = this._holes[i].length; j < len2; j++) {
				this._holePoints[i][j] = this._map.latLngToLayerPoint(this._holes[i][j]);
			}
		}
	},
 
	_clipPoints: function () {
		var points = this._originalPoints,
		    newParts = [];
 
		this._parts = [points].concat(this._holePoints);
 
		if (this.options.noClip) { return; }
 
		for (var i = 0, len = this._parts.length; i < len; i++) {
			var clipped = L.PolyUtil.clipPolygon(this._parts[i], this._map._pathViewport);
			if (clipped.length) {
				newParts.push(clipped);
			}
		}
 
		this._parts = newParts;
	},
 
	_getPathPartStr: function (points) {
		var str = L.Polyline.prototype._getPathPartStr.call(this, points);
		return str + (L.Browser.svg ? 'z' : 'x');
	}
});
 
L.polygon = function (latlngs, options) {
	return new L.Polygon(latlngs, options);
};