Implement setPolygons on ol.geom.MultiPolygon
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
goog.provide('ol.geom.MultiPolygon');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.asserts');
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
goog.require('ol.geom.Polygon');
|
||||
@@ -258,3 +260,33 @@ ol.geom.MultiPolygon.prototype.setFlatCoordinates =
|
||||
this.endss_ = endss;
|
||||
this.dispatchChangeEvent();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<ol.geom.Polygon>} polygons Polygons.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.geom.MultiPolygon.prototype.setPolygons = function(polygons) {
|
||||
var layout = ol.geom.GeometryLayout.XY;
|
||||
var flatCoordinates = [];
|
||||
var endss = [];
|
||||
var i, ii, ends;
|
||||
for (i = 0, ii = polygons.length; i < ii; ++i) {
|
||||
var polygon = polygons[i];
|
||||
if (i === 0) {
|
||||
layout = polygon.getLayout();
|
||||
} else {
|
||||
// FIXME better handle the case of non-matching layouts
|
||||
goog.asserts.assert(polygon.getLayout() == layout);
|
||||
}
|
||||
var offset = flatCoordinates.length;
|
||||
ends = polygon.getEnds();
|
||||
var j, jj;
|
||||
for (j = 0, jj = ends.length; j < jj; ++j) {
|
||||
ends[j] += offset;
|
||||
}
|
||||
goog.array.extend(flatCoordinates, polygon.getFlatCoordinates());
|
||||
endss.push(ends);
|
||||
}
|
||||
this.setFlatCoordinates(layout, flatCoordinates, endss);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user