diff --git a/src/ol/geom/multipolygon.js b/src/ol/geom/multipolygon.js index b9becbc382..657a461b12 100644 --- a/src/ol/geom/multipolygon.js +++ b/src/ol/geom/multipolygon.js @@ -3,6 +3,7 @@ goog.provide('ol.geom.MultiPolygon'); goog.require('ol.geom.Geometry'); goog.require('ol.geom.Polygon'); goog.require('ol.geom.flat'); +goog.require('ol.geom.simplify'); @@ -90,6 +91,24 @@ ol.geom.MultiPolygon.prototype.getInteriorPoints = function() { }; +/** + * @inheritDoc + */ +ol.geom.MultiPolygon.prototype.getSimplifiedGeometryInternal = + function(squaredTolerance) { + var simplifiedFlatCoordinates = []; + var simplifiedEndss = []; + simplifiedFlatCoordinates.length = + ol.geom.simplify.douglasPeuckerss(this.flatCoordinates, 0, + this.endss_, this.stride, squaredTolerance, simplifiedFlatCoordinates, + 0, simplifiedEndss); + var simplifiedMultiPolygon = new ol.geom.MultiPolygon(null); + simplifiedMultiPolygon.setFlatCoordinates( + ol.geom.GeometryLayout.XY, simplifiedFlatCoordinates, simplifiedEndss); + return simplifiedMultiPolygon; +}; + + /** * @return {Array.} Polygons. */ diff --git a/test/spec/ol/geom/multipolygon.test.js b/test/spec/ol/geom/multipolygon.test.js index 92badfa88a..564ff9e90d 100644 --- a/test/spec/ol/geom/multipolygon.test.js +++ b/test/spec/ol/geom/multipolygon.test.js @@ -10,6 +10,30 @@ describe('ol.geom.MultiPolygon', function() { }).not.to.throwException(); }); + describe('with a simple MultiPolygon', function() { + + var multiPolygon; + beforeEach(function() { + multiPolygon = new ol.geom.MultiPolygon([ + [[[0, 0], [0, 2], [1, 1], [2, 0]]], + [[[3, 0], [4, 1], [5, 2], [5, 0]]] + ]); + }); + + describe('#getSimplifiedGeometry', function() { + + it('returns the expected result', function() { + var simplifiedGeometry = multiPolygon.getSimplifiedGeometry(1); + expect(simplifiedGeometry).to.be.an(ol.geom.MultiPolygon); + expect(simplifiedGeometry.getCoordinates()).to.eql([ + [[[0, 0], [0, 2], [2, 0]]], + [[[3, 0], [5, 2], [5, 0]]] + ]); + }); + }); + + }); + });