polygon holes support

This commit is contained in:
Mourner 2011-03-01 14:48:12 +02:00
parent 5de66e7ee1
commit 7c01c98788

View File

@ -1,20 +1,49 @@
/*
* L.Polygon is used to display polygons on a map.
*/
L.Polygon = L.Polyline.extend({
options: {
fill: true
},
initialize: function(latlngs, options) {
L.Polyline.prototype.initialize.call(this, latlngs, options);
if (latlngs[0] instanceof Array) {
this._latlngs = latlngs[0];
this._holes = latlngs.slice(1);
}
},
_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;
for (var i = 0, len = this._holes.length, hole; i < len; i++) {
this._holePoints[i] = [];
for(var 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;
if (this.options.noClip) {
this._parts = [points];
return;
this._parts = [points].concat(this._holePoints);
if (this.options.noClip) return;
for (var i = 0, len = this._parts.length; i < len; i++) {
this._parts[i] = L.LineUtil.clipPolygon(this._parts[i], this._map._pathViewport);
}
var clippedPoints = L.LineUtil.clipPolygon(points, this._map._pathViewport);
this._parts = [clippedPoints]; //TODO include holes?
},
_buildPathPartStr: function(points) {