Allow geometries to have null coordinates and add setFlatCoordinates
This commit is contained in:
@@ -60,7 +60,7 @@ ol.geom.Geometry = function() {
|
|||||||
* @protected
|
* @protected
|
||||||
* @type {Array.<number>}
|
* @type {Array.<number>}
|
||||||
*/
|
*/
|
||||||
this.flatCoordinates = [];
|
this.flatCoordinates = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @protected
|
* @protected
|
||||||
@@ -201,6 +201,19 @@ ol.geom.Geometry.prototype.getStride = function() {
|
|||||||
ol.geom.Geometry.prototype.getType = goog.abstractMethod;
|
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 {ol.geom.Layout|undefined} layout Layout.
|
||||||
* @param {Array} coordinates Coordinates.
|
* @param {Array} coordinates Coordinates.
|
||||||
@@ -236,7 +249,9 @@ ol.geom.Geometry.prototype.setLayout =
|
|||||||
* @param {ol.TransformFunction} transformFn Transform.
|
* @param {ol.TransformFunction} transformFn Transform.
|
||||||
*/
|
*/
|
||||||
ol.geom.Geometry.prototype.transform = function(transformFn) {
|
ol.geom.Geometry.prototype.transform = function(transformFn) {
|
||||||
|
if (!goog.isNull(this.flatCoordinates)) {
|
||||||
transformFn(this.flatCoordinates, this.flatCoordinates, this.stride);
|
transformFn(this.flatCoordinates, this.flatCoordinates, this.stride);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -291,7 +306,11 @@ ol.geom.RawMultiPolygon;
|
|||||||
*/
|
*/
|
||||||
ol.geom.transformGeometry2D = function(geometry, transform, opt_dest) {
|
ol.geom.transformGeometry2D = function(geometry, transform, opt_dest) {
|
||||||
var flatCoordinates = geometry.getFlatCoordinates();
|
var flatCoordinates = geometry.getFlatCoordinates();
|
||||||
|
if (goog.isNull(flatCoordinates)) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
var stride = geometry.getStride();
|
var stride = geometry.getStride();
|
||||||
return ol.geom.flat.transform2D(
|
return ol.geom.flat.transform2D(
|
||||||
flatCoordinates, stride, transform, opt_dest);
|
flatCoordinates, stride, transform, opt_dest);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -50,8 +50,26 @@ ol.geom.LineString.prototype.getType = function() {
|
|||||||
*/
|
*/
|
||||||
ol.geom.LineString.prototype.setCoordinates =
|
ol.geom.LineString.prototype.setCoordinates =
|
||||||
function(coordinates, opt_layout) {
|
function(coordinates, opt_layout) {
|
||||||
|
if (goog.isNull(coordinates)) {
|
||||||
|
this.setFlatCoordinates(ol.geom.Layout.XY, null);
|
||||||
|
} else {
|
||||||
this.setLayout(opt_layout, coordinates, 1);
|
this.setLayout(opt_layout, coordinates, 1);
|
||||||
ol.geom.flat.deflateCoordinates(
|
if (goog.isNull(this.flatCoordinates)) {
|
||||||
|
this.flatCoordinates = [];
|
||||||
|
}
|
||||||
|
this.flatCoordinates.length = ol.geom.flat.deflateCoordinates(
|
||||||
this.flatCoordinates, 0, coordinates, this.stride);
|
this.flatCoordinates, 0, coordinates, this.stride);
|
||||||
this.dispatchChangeEvent();
|
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 =
|
ol.geom.MultiLineString.prototype.setCoordinates =
|
||||||
function(coordinates, opt_layout) {
|
function(coordinates, opt_layout) {
|
||||||
|
if (goog.isNull(coordinates)) {
|
||||||
|
this.setFlatCoordinates(ol.geom.Layout.XY, null, this.ends_);
|
||||||
|
} else {
|
||||||
this.setLayout(opt_layout, coordinates, 2);
|
this.setLayout(opt_layout, coordinates, 2);
|
||||||
ol.geom.flat.deflateCoordinatess(
|
if (goog.isNull(this.flatCoordinates)) {
|
||||||
|
this.flatCoordinates = [];
|
||||||
|
}
|
||||||
|
var ends = ol.geom.flat.deflateCoordinatess(
|
||||||
this.flatCoordinates, 0, coordinates, this.stride, this.ends_);
|
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();
|
this.dispatchChangeEvent();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -57,8 +57,26 @@ ol.geom.MultiPoint.prototype.getType = function() {
|
|||||||
*/
|
*/
|
||||||
ol.geom.MultiPoint.prototype.setCoordinates =
|
ol.geom.MultiPoint.prototype.setCoordinates =
|
||||||
function(coordinates, opt_layout) {
|
function(coordinates, opt_layout) {
|
||||||
|
if (goog.isNull(coordinates)) {
|
||||||
|
this.setFlatCoordinates(ol.geom.Layout.XY, null);
|
||||||
|
} else {
|
||||||
this.setLayout(opt_layout, coordinates, 1);
|
this.setLayout(opt_layout, coordinates, 1);
|
||||||
ol.geom.flat.deflateCoordinates(
|
if (goog.isNull(this.flatCoordinates)) {
|
||||||
|
this.flatCoordinates = [];
|
||||||
|
}
|
||||||
|
this.flatCoordinates.length = ol.geom.flat.deflateCoordinates(
|
||||||
this.flatCoordinates, 0, coordinates, this.stride);
|
this.flatCoordinates, 0, coordinates, this.stride);
|
||||||
this.dispatchChangeEvent();
|
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 =
|
ol.geom.MultiPolygon.prototype.setCoordinates =
|
||||||
function(coordinates, opt_layout) {
|
function(coordinates, opt_layout) {
|
||||||
|
if (goog.isNull(coordinates)) {
|
||||||
|
this.setFlatCoordinates(ol.geom.Layout.XY, null, this.endss_);
|
||||||
|
} else {
|
||||||
this.setLayout(opt_layout, coordinates, 3);
|
this.setLayout(opt_layout, coordinates, 3);
|
||||||
ol.geom.flat.deflateCoordinatesss(
|
if (goog.isNull(this.flatCoordinates)) {
|
||||||
|
this.flatCoordinates = [];
|
||||||
|
}
|
||||||
|
var endss = ol.geom.flat.deflateCoordinatesss(
|
||||||
this.flatCoordinates, 0, coordinates, this.stride, this.endss_);
|
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(
|
ol.geom.flat.orientLinearRingss(
|
||||||
this.flatCoordinates, 0, this.endss_, this.stride);
|
this.flatCoordinates, 0, this.endss_, this.stride);
|
||||||
this.dispatchChangeEvent();
|
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('goog.asserts');
|
||||||
goog.require('ol.extent');
|
goog.require('ol.extent');
|
||||||
goog.require('ol.geom.Geometry');
|
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.
|
* @param {ol.geom.Layout=} opt_layout Layout.
|
||||||
*/
|
*/
|
||||||
ol.geom.Point.prototype.setCoordinates = function(coordinates, opt_layout) {
|
ol.geom.Point.prototype.setCoordinates = function(coordinates, opt_layout) {
|
||||||
|
if (goog.isNull(coordinates)) {
|
||||||
|
this.setFlatCoordinates(ol.geom.Layout.XY, null);
|
||||||
|
} else {
|
||||||
this.setLayout(opt_layout, coordinates, 0);
|
this.setLayout(opt_layout, coordinates, 0);
|
||||||
this.flatCoordinates = coordinates;
|
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();
|
this.dispatchChangeEvent();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -117,10 +117,31 @@ ol.geom.Polygon.prototype.getType = function() {
|
|||||||
* @param {ol.geom.Layout=} opt_layout Layout.
|
* @param {ol.geom.Layout=} opt_layout Layout.
|
||||||
*/
|
*/
|
||||||
ol.geom.Polygon.prototype.setCoordinates = function(coordinates, opt_layout) {
|
ol.geom.Polygon.prototype.setCoordinates = function(coordinates, opt_layout) {
|
||||||
|
if (goog.isNull(coordinates)) {
|
||||||
|
this.setFlatCoordinates(ol.geom.Layout.XY, null, this.ends_);
|
||||||
|
} else {
|
||||||
this.setLayout(opt_layout, coordinates, 2);
|
this.setLayout(opt_layout, coordinates, 2);
|
||||||
ol.geom.flat.deflateCoordinatess(
|
if (goog.isNull(this.flatCoordinates)) {
|
||||||
|
this.flatCoordinates = [];
|
||||||
|
}
|
||||||
|
var ends = ol.geom.flat.deflateCoordinatess(
|
||||||
this.flatCoordinates, 0, coordinates, this.stride, this.ends_);
|
this.flatCoordinates, 0, coordinates, this.stride, this.ends_);
|
||||||
|
this.flatCoordinates.length = ends.length === 0 ? 0 : ends[ends.length - 1];
|
||||||
ol.geom.flat.orientLinearRings(
|
ol.geom.flat.orientLinearRings(
|
||||||
this.flatCoordinates, 0, this.ends_, this.stride);
|
this.flatCoordinates, 0, this.ends_, this.stride);
|
||||||
this.dispatchChangeEvent();
|
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() {
|
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() {
|
describe('construct empty', function() {
|
||||||
|
|
||||||
var lineString;
|
var lineString;
|
||||||
|
|||||||
@@ -3,6 +3,13 @@ goog.provide('ol.test.geom.MultiLineString');
|
|||||||
|
|
||||||
describe('ol.geom.MultiLineString', function() {
|
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() {
|
describe('construct empty', function() {
|
||||||
|
|
||||||
var multiLineString;
|
var multiLineString;
|
||||||
|
|||||||
@@ -3,6 +3,13 @@ goog.provide('ol.test.geom.MultiPoint');
|
|||||||
|
|
||||||
describe('ol.geom.MultiPoint', function() {
|
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() {
|
describe('construct empty', function() {
|
||||||
|
|
||||||
var multiPoint;
|
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() {
|
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() {
|
describe('construct with 2D coordinates', function() {
|
||||||
|
|
||||||
var point;
|
var point;
|
||||||
|
|||||||
@@ -5,6 +5,13 @@ goog.provide('ol.test.geom.Polygon');
|
|||||||
|
|
||||||
describe('ol.geom.Polygon', function() {
|
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() {
|
describe('construct empty', function() {
|
||||||
|
|
||||||
var polygon;
|
var polygon;
|
||||||
|
|||||||
Reference in New Issue
Block a user