Allow geometries to have null coordinates and add setFlatCoordinates
This commit is contained in:
@@ -60,7 +60,7 @@ ol.geom.Geometry = function() {
|
||||
* @protected
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
this.flatCoordinates = [];
|
||||
this.flatCoordinates = null;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
@@ -201,6 +201,19 @@ ol.geom.Geometry.prototype.getStride = function() {
|
||||
ol.geom.Geometry.prototype.getType = goog.abstractMethod;
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.geom.Layout} layout Layout.
|
||||
* @param {Array.<number>} flatCoordinates Flat coordinates.
|
||||
* @protected
|
||||
*/
|
||||
ol.geom.Geometry.prototype.setFlatCoordinatesInternal =
|
||||
function(layout, flatCoordinates) {
|
||||
this.stride = ol.geom.Geometry.getStrideForLayout_(layout);
|
||||
this.layout = layout;
|
||||
this.flatCoordinates = flatCoordinates;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.geom.Layout|undefined} layout Layout.
|
||||
* @param {Array} coordinates Coordinates.
|
||||
@@ -236,7 +249,9 @@ ol.geom.Geometry.prototype.setLayout =
|
||||
* @param {ol.TransformFunction} transformFn Transform.
|
||||
*/
|
||||
ol.geom.Geometry.prototype.transform = function(transformFn) {
|
||||
transformFn(this.flatCoordinates, this.flatCoordinates, this.stride);
|
||||
if (!goog.isNull(this.flatCoordinates)) {
|
||||
transformFn(this.flatCoordinates, this.flatCoordinates, this.stride);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -291,7 +306,11 @@ ol.geom.RawMultiPolygon;
|
||||
*/
|
||||
ol.geom.transformGeometry2D = function(geometry, transform, opt_dest) {
|
||||
var flatCoordinates = geometry.getFlatCoordinates();
|
||||
var stride = geometry.getStride();
|
||||
return ol.geom.flat.transform2D(
|
||||
flatCoordinates, stride, transform, opt_dest);
|
||||
if (goog.isNull(flatCoordinates)) {
|
||||
return null;
|
||||
} else {
|
||||
var stride = geometry.getStride();
|
||||
return ol.geom.flat.transform2D(
|
||||
flatCoordinates, stride, transform, opt_dest);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -50,8 +50,26 @@ ol.geom.LineString.prototype.getType = function() {
|
||||
*/
|
||||
ol.geom.LineString.prototype.setCoordinates =
|
||||
function(coordinates, opt_layout) {
|
||||
this.setLayout(opt_layout, coordinates, 1);
|
||||
ol.geom.flat.deflateCoordinates(
|
||||
this.flatCoordinates, 0, coordinates, this.stride);
|
||||
if (goog.isNull(coordinates)) {
|
||||
this.setFlatCoordinates(ol.geom.Layout.XY, null);
|
||||
} else {
|
||||
this.setLayout(opt_layout, coordinates, 1);
|
||||
if (goog.isNull(this.flatCoordinates)) {
|
||||
this.flatCoordinates = [];
|
||||
}
|
||||
this.flatCoordinates.length = ol.geom.flat.deflateCoordinates(
|
||||
this.flatCoordinates, 0, coordinates, this.stride);
|
||||
this.dispatchChangeEvent();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.geom.Layout} layout Layout.
|
||||
* @param {Array.<number>} flatCoordinates Flat coordinates.
|
||||
*/
|
||||
ol.geom.LineString.prototype.setFlatCoordinates =
|
||||
function(layout, flatCoordinates) {
|
||||
this.setFlatCoordinatesInternal(layout, flatCoordinates);
|
||||
this.dispatchChangeEvent();
|
||||
};
|
||||
|
||||
@@ -74,8 +74,29 @@ ol.geom.MultiLineString.prototype.getType = function() {
|
||||
*/
|
||||
ol.geom.MultiLineString.prototype.setCoordinates =
|
||||
function(coordinates, opt_layout) {
|
||||
this.setLayout(opt_layout, coordinates, 2);
|
||||
ol.geom.flat.deflateCoordinatess(
|
||||
this.flatCoordinates, 0, coordinates, this.stride, this.ends_);
|
||||
if (goog.isNull(coordinates)) {
|
||||
this.setFlatCoordinates(ol.geom.Layout.XY, null, this.ends_);
|
||||
} else {
|
||||
this.setLayout(opt_layout, coordinates, 2);
|
||||
if (goog.isNull(this.flatCoordinates)) {
|
||||
this.flatCoordinates = [];
|
||||
}
|
||||
var ends = ol.geom.flat.deflateCoordinatess(
|
||||
this.flatCoordinates, 0, coordinates, this.stride, this.ends_);
|
||||
this.flatCoordinates.length = ends.length === 0 ? 0 : ends[ends.length - 1];
|
||||
this.dispatchChangeEvent();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.geom.Layout} layout Layout.
|
||||
* @param {Array.<number>} flatCoordinates Flat coordinates.
|
||||
* @param {Array.<number>} ends Ends.
|
||||
*/
|
||||
ol.geom.MultiLineString.prototype.setFlatCoordinates =
|
||||
function(layout, flatCoordinates, ends) {
|
||||
this.setFlatCoordinatesInternal(layout, flatCoordinates);
|
||||
this.ends_ = ends;
|
||||
this.dispatchChangeEvent();
|
||||
};
|
||||
|
||||
@@ -57,8 +57,26 @@ ol.geom.MultiPoint.prototype.getType = function() {
|
||||
*/
|
||||
ol.geom.MultiPoint.prototype.setCoordinates =
|
||||
function(coordinates, opt_layout) {
|
||||
this.setLayout(opt_layout, coordinates, 1);
|
||||
ol.geom.flat.deflateCoordinates(
|
||||
this.flatCoordinates, 0, coordinates, this.stride);
|
||||
if (goog.isNull(coordinates)) {
|
||||
this.setFlatCoordinates(ol.geom.Layout.XY, null);
|
||||
} else {
|
||||
this.setLayout(opt_layout, coordinates, 1);
|
||||
if (goog.isNull(this.flatCoordinates)) {
|
||||
this.flatCoordinates = [];
|
||||
}
|
||||
this.flatCoordinates.length = ol.geom.flat.deflateCoordinates(
|
||||
this.flatCoordinates, 0, coordinates, this.stride);
|
||||
this.dispatchChangeEvent();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.geom.Layout} layout Layout.
|
||||
* @param {Array.<number>} flatCoordinates Flat coordinates.
|
||||
*/
|
||||
ol.geom.MultiPoint.prototype.setFlatCoordinates =
|
||||
function(layout, flatCoordinates) {
|
||||
this.setFlatCoordinatesInternal(layout, flatCoordinates);
|
||||
this.dispatchChangeEvent();
|
||||
};
|
||||
|
||||
@@ -119,10 +119,33 @@ ol.geom.MultiPolygon.prototype.getType = function() {
|
||||
*/
|
||||
ol.geom.MultiPolygon.prototype.setCoordinates =
|
||||
function(coordinates, opt_layout) {
|
||||
this.setLayout(opt_layout, coordinates, 3);
|
||||
ol.geom.flat.deflateCoordinatesss(
|
||||
this.flatCoordinates, 0, coordinates, this.stride, this.endss_);
|
||||
ol.geom.flat.orientLinearRingss(
|
||||
this.flatCoordinates, 0, this.endss_, this.stride);
|
||||
if (goog.isNull(coordinates)) {
|
||||
this.setFlatCoordinates(ol.geom.Layout.XY, null, this.endss_);
|
||||
} else {
|
||||
this.setLayout(opt_layout, coordinates, 3);
|
||||
if (goog.isNull(this.flatCoordinates)) {
|
||||
this.flatCoordinates = [];
|
||||
}
|
||||
var endss = ol.geom.flat.deflateCoordinatesss(
|
||||
this.flatCoordinates, 0, coordinates, this.stride, this.endss_);
|
||||
var lastEnds = endss[endss.length - 1];
|
||||
this.flatCoordinates.length = lastEnds.length === 0 ?
|
||||
0 : lastEnds[lastEnds.length - 1];
|
||||
ol.geom.flat.orientLinearRingss(
|
||||
this.flatCoordinates, 0, this.endss_, this.stride);
|
||||
this.dispatchChangeEvent();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.geom.Layout} layout Layout.
|
||||
* @param {Array.<number>} flatCoordinates Flat coordinates.
|
||||
* @param {Array.<Array.<number>>} endss Endss.
|
||||
*/
|
||||
ol.geom.MultiPolygon.prototype.setFlatCoordinates =
|
||||
function(layout, flatCoordinates, endss) {
|
||||
this.setFlatCoordinatesInternal(layout, flatCoordinates);
|
||||
this.endss_ = endss;
|
||||
this.dispatchChangeEvent();
|
||||
};
|
||||
|
||||
@@ -3,6 +3,7 @@ goog.provide('ol.geom.Point');
|
||||
goog.require('goog.asserts');
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.flat');
|
||||
|
||||
|
||||
|
||||
@@ -54,7 +55,25 @@ ol.geom.Point.prototype.getType = function() {
|
||||
* @param {ol.geom.Layout=} opt_layout Layout.
|
||||
*/
|
||||
ol.geom.Point.prototype.setCoordinates = function(coordinates, opt_layout) {
|
||||
this.setLayout(opt_layout, coordinates, 0);
|
||||
this.flatCoordinates = coordinates;
|
||||
if (goog.isNull(coordinates)) {
|
||||
this.setFlatCoordinates(ol.geom.Layout.XY, null);
|
||||
} else {
|
||||
this.setLayout(opt_layout, coordinates, 0);
|
||||
if (goog.isNull(this.flatCoordinates)) {
|
||||
this.flatCoordinates = [];
|
||||
}
|
||||
this.flatCoordinates.length = ol.geom.flat.deflateCoordinate(
|
||||
this.flatCoordinates, 0, coordinates, this.stride);
|
||||
this.dispatchChangeEvent();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.geom.Layout} layout Layout.
|
||||
* @param {Array.<number>} flatCoordinates Flat coordinates.
|
||||
*/
|
||||
ol.geom.Point.prototype.setFlatCoordinates = function(layout, flatCoordinates) {
|
||||
this.setFlatCoordinatesInternal(layout, flatCoordinates);
|
||||
this.dispatchChangeEvent();
|
||||
};
|
||||
|
||||
@@ -117,10 +117,31 @@ ol.geom.Polygon.prototype.getType = function() {
|
||||
* @param {ol.geom.Layout=} opt_layout Layout.
|
||||
*/
|
||||
ol.geom.Polygon.prototype.setCoordinates = function(coordinates, opt_layout) {
|
||||
this.setLayout(opt_layout, coordinates, 2);
|
||||
ol.geom.flat.deflateCoordinatess(
|
||||
this.flatCoordinates, 0, coordinates, this.stride, this.ends_);
|
||||
ol.geom.flat.orientLinearRings(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride);
|
||||
if (goog.isNull(coordinates)) {
|
||||
this.setFlatCoordinates(ol.geom.Layout.XY, null, this.ends_);
|
||||
} else {
|
||||
this.setLayout(opt_layout, coordinates, 2);
|
||||
if (goog.isNull(this.flatCoordinates)) {
|
||||
this.flatCoordinates = [];
|
||||
}
|
||||
var ends = ol.geom.flat.deflateCoordinatess(
|
||||
this.flatCoordinates, 0, coordinates, this.stride, this.ends_);
|
||||
this.flatCoordinates.length = ends.length === 0 ? 0 : ends[ends.length - 1];
|
||||
ol.geom.flat.orientLinearRings(
|
||||
this.flatCoordinates, 0, this.ends_, this.stride);
|
||||
this.dispatchChangeEvent();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.geom.Layout} layout Layout.
|
||||
* @param {Array.<number>} flatCoordinates Flat coordinates.
|
||||
* @param {Array.<number>} ends Ends.
|
||||
*/
|
||||
ol.geom.Polygon.prototype.setFlatCoordinates =
|
||||
function(layout, flatCoordinates, ends) {
|
||||
this.setFlatCoordinatesInternal(layout, flatCoordinates);
|
||||
this.ends_ = ends;
|
||||
this.dispatchChangeEvent();
|
||||
};
|
||||
|
||||
@@ -3,6 +3,13 @@ goog.provide('ol.test.geom.LineString');
|
||||
|
||||
describe('ol.geom.LineString', function() {
|
||||
|
||||
it('can be constructed with a null geometry', function() {
|
||||
expect(function() {
|
||||
var lineString = new ol.geom.LineString(null);
|
||||
lineString = lineString; // suppress gjslint warning
|
||||
}).not.to.throwException();
|
||||
});
|
||||
|
||||
describe('construct empty', function() {
|
||||
|
||||
var lineString;
|
||||
|
||||
@@ -3,6 +3,13 @@ goog.provide('ol.test.geom.MultiLineString');
|
||||
|
||||
describe('ol.geom.MultiLineString', function() {
|
||||
|
||||
it('can be constructed with a null geometry', function() {
|
||||
expect(function() {
|
||||
var multiLineString = new ol.geom.MultiLineString(null);
|
||||
multiLineString = multiLineString; // suppress gjslint warning
|
||||
}).not.to.throwException();
|
||||
});
|
||||
|
||||
describe('construct empty', function() {
|
||||
|
||||
var multiLineString;
|
||||
|
||||
@@ -3,6 +3,13 @@ goog.provide('ol.test.geom.MultiPoint');
|
||||
|
||||
describe('ol.geom.MultiPoint', function() {
|
||||
|
||||
it('can be constructed with a null geometry', function() {
|
||||
expect(function() {
|
||||
var multiPoint = new ol.geom.MultiPoint(null);
|
||||
multiPoint = multiPoint; // suppress gjslint warning
|
||||
}).not.to.throwException();
|
||||
});
|
||||
|
||||
describe('construct empty', function() {
|
||||
|
||||
var multiPoint;
|
||||
|
||||
16
test/spec/ol/geom/multipolygon.test.js
Normal file
16
test/spec/ol/geom/multipolygon.test.js
Normal file
@@ -0,0 +1,16 @@
|
||||
goog.provide('ol.test.geom.MultiPolygon');
|
||||
|
||||
|
||||
describe('ol.geom.MultiPolygon', function() {
|
||||
|
||||
it('can be constructed with a null geometry', function() {
|
||||
expect(function() {
|
||||
var multiPolygon = new ol.geom.MultiPolygon(null);
|
||||
multiPolygon = multiPolygon; // suppress gjslint warning
|
||||
}).not.to.throwException();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
goog.require('ol.geom.MultiPolygon');
|
||||
@@ -3,6 +3,13 @@ goog.provide('ol.test.geom.Point');
|
||||
|
||||
describe('ol.geom.Point', function() {
|
||||
|
||||
it('can be constructed with a null geometry', function() {
|
||||
expect(function() {
|
||||
var point = new ol.geom.Point(null);
|
||||
point = point; // suppress gjslint warning
|
||||
}).not.to.throwException();
|
||||
});
|
||||
|
||||
describe('construct with 2D coordinates', function() {
|
||||
|
||||
var point;
|
||||
|
||||
@@ -5,6 +5,13 @@ goog.provide('ol.test.geom.Polygon');
|
||||
|
||||
describe('ol.geom.Polygon', function() {
|
||||
|
||||
it('can be constructed with a null geometry', function() {
|
||||
expect(function() {
|
||||
var polygon = new ol.geom.Polygon(null);
|
||||
polygon = polygon; // suppress gjslint warning
|
||||
}).not.to.throwException();
|
||||
});
|
||||
|
||||
describe('construct empty', function() {
|
||||
|
||||
var polygon;
|
||||
|
||||
Reference in New Issue
Block a user