Add ol.geom.MultiLineString#setLineStrings
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
goog.provide('ol.geom.MultiLineString');
|
goog.provide('ol.geom.MultiLineString');
|
||||||
|
|
||||||
|
goog.require('goog.array');
|
||||||
|
goog.require('goog.asserts');
|
||||||
goog.require('ol.extent');
|
goog.require('ol.extent');
|
||||||
goog.require('ol.geom.LineString');
|
goog.require('ol.geom.LineString');
|
||||||
goog.require('ol.geom.SimpleGeometry');
|
goog.require('ol.geom.SimpleGeometry');
|
||||||
@@ -163,3 +165,26 @@ ol.geom.MultiLineString.prototype.setFlatCoordinates =
|
|||||||
this.ends_ = ends;
|
this.ends_ = ends;
|
||||||
this.dispatchChangeEvent();
|
this.dispatchChangeEvent();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Array.<ol.geom.LineString>} lineStrings LineStrings.
|
||||||
|
*/
|
||||||
|
ol.geom.MultiLineString.prototype.setLineStrings = function(lineStrings) {
|
||||||
|
var layout = ol.geom.GeometryLayout.XY;
|
||||||
|
var flatCoordinates = [];
|
||||||
|
var ends = [];
|
||||||
|
var i, ii;
|
||||||
|
for (i = 0, ii = lineStrings.length; i < ii; ++i) {
|
||||||
|
var lineString = lineStrings[i];
|
||||||
|
if (i === 0) {
|
||||||
|
layout = lineString.getLayout();
|
||||||
|
} else {
|
||||||
|
// FIXME better handle the case of non-matching layouts
|
||||||
|
goog.asserts.assert(lineString.getLayout() == layout);
|
||||||
|
}
|
||||||
|
goog.array.extend(flatCoordinates, lineString.getFlatCoordinates());
|
||||||
|
ends.push(flatCoordinates.length);
|
||||||
|
}
|
||||||
|
this.setFlatCoordinates(layout, flatCoordinates, ends);
|
||||||
|
};
|
||||||
|
|||||||
@@ -168,8 +168,25 @@ describe('ol.geom.MultiLineString', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#setLineStrings', function() {
|
||||||
|
|
||||||
|
it('sets the line strings', function() {
|
||||||
|
var multiLineString = new ol.geom.MultiLineString(null);
|
||||||
|
var lineString1 = new ol.geom.LineString([[1, 2], [3, 4]]);
|
||||||
|
var lineString2 = new ol.geom.LineString([[5, 6], [7, 8]]);
|
||||||
|
multiLineString.setLineStrings([lineString1, lineString2]);
|
||||||
|
expect(multiLineString.getFlatCoordinates()).to.eql(
|
||||||
|
[1, 2, 3, 4, 5, 6, 7, 8]);
|
||||||
|
expect(multiLineString.getEnds()).to.eql([4, 8]);
|
||||||
|
var coordinates = multiLineString.getCoordinates();
|
||||||
|
expect(coordinates[0]).to.eql(lineString1.getCoordinates());
|
||||||
|
expect(coordinates[1]).to.eql(lineString2.getCoordinates());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
goog.require('ol.extent');
|
goog.require('ol.extent');
|
||||||
|
goog.require('ol.geom.LineString');
|
||||||
goog.require('ol.geom.MultiLineString');
|
goog.require('ol.geom.MultiLineString');
|
||||||
|
|||||||
Reference in New Issue
Block a user