Do not accept null coordinates in Point constructor
This commit is contained in:
@@ -360,9 +360,13 @@ Graticule.prototype.getMeridianPoint_ = function(lineString, extent, index) {
|
|||||||
extent[1] + Math.abs(extent[1] - extent[3]) * this.lonLabelPosition_,
|
extent[1] + Math.abs(extent[1] - extent[3]) * this.lonLabelPosition_,
|
||||||
clampedBottom, clampedTop);
|
clampedBottom, clampedTop);
|
||||||
const coordinate = [flatCoordinates[0], lat];
|
const coordinate = [flatCoordinates[0], lat];
|
||||||
const point = this.meridiansLabels_[index] !== undefined ?
|
let point;
|
||||||
this.meridiansLabels_[index].geom : new Point(null);
|
if (index in this.meridiansLabels_) {
|
||||||
point.setCoordinates(coordinate);
|
point = this.meridiansLabels_[index];
|
||||||
|
point.setCoordinates(coordinate);
|
||||||
|
} else {
|
||||||
|
point = new Point(coordinate);
|
||||||
|
}
|
||||||
return point;
|
return point;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -408,9 +412,13 @@ Graticule.prototype.getParallelPoint_ = function(lineString, extent, index) {
|
|||||||
extent[0] + Math.abs(extent[0] - extent[2]) * this.latLabelPosition_,
|
extent[0] + Math.abs(extent[0] - extent[2]) * this.latLabelPosition_,
|
||||||
clampedLeft, clampedRight);
|
clampedLeft, clampedRight);
|
||||||
const coordinate = [lon, flatCoordinates[1]];
|
const coordinate = [lon, flatCoordinates[1]];
|
||||||
const point = this.parallelsLabels_[index] !== undefined ?
|
let point;
|
||||||
this.parallelsLabels_[index].geom : new Point(null);
|
if (index in this.parallelsLabels_) {
|
||||||
point.setCoordinates(coordinate);
|
point = this.parallelsLabels_[index];
|
||||||
|
point.setCoordinates(coordinate);
|
||||||
|
} else {
|
||||||
|
point = new Point(coordinate);
|
||||||
|
}
|
||||||
return point;
|
return point;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -291,9 +291,7 @@ GMLBase.prototype.readFeatureElement = function(node, objectStack) {
|
|||||||
GMLBase.prototype.readPoint = function(node, objectStack) {
|
GMLBase.prototype.readPoint = function(node, objectStack) {
|
||||||
const flatCoordinates = this.readFlatCoordinatesFromNode_(node, objectStack);
|
const flatCoordinates = this.readFlatCoordinatesFromNode_(node, objectStack);
|
||||||
if (flatCoordinates) {
|
if (flatCoordinates) {
|
||||||
const point = new Point(null);
|
return new Point(flatCoordinates, GeometryLayout.XYZ);
|
||||||
point.setFlatCoordinates(GeometryLayout.XYZ, flatCoordinates);
|
|
||||||
return point;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1144,8 +1144,7 @@ function readPoint(node, objectStack) {
|
|||||||
const flatCoordinates =
|
const flatCoordinates =
|
||||||
readFlatCoordinatesFromNode(node, objectStack);
|
readFlatCoordinatesFromNode(node, objectStack);
|
||||||
if (flatCoordinates) {
|
if (flatCoordinates) {
|
||||||
const point = new Point(null);
|
const point = new Point(flatCoordinates, GeometryLayout.XYZ);
|
||||||
point.setFlatCoordinates(GeometryLayout.XYZ, flatCoordinates);
|
|
||||||
point.setProperties(properties);
|
point.setProperties(properties);
|
||||||
return point;
|
return point;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -339,14 +339,14 @@ MVT.prototype.createFeature_ = function(pbf, rawFeature, opt_options) {
|
|||||||
geom = new Polygon(flatCoordinates, GeometryLayout.XY, ends);
|
geom = new Polygon(flatCoordinates, GeometryLayout.XY, ends);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
geom = geometryType === GeometryType.POINT ? new Point(null) :
|
geom = geometryType === GeometryType.POINT ? new Point(flatCoordinates, GeometryLayout.XY) :
|
||||||
geometryType === GeometryType.LINE_STRING ? new LineString(null) :
|
geometryType === GeometryType.LINE_STRING ? new LineString(null) :
|
||||||
geometryType === GeometryType.POLYGON ? new Polygon(flatCoordinates, GeometryLayout.XY, ends) :
|
geometryType === GeometryType.POLYGON ? new Polygon(flatCoordinates, GeometryLayout.XY, ends) :
|
||||||
geometryType === GeometryType.MULTI_POINT ? new MultiPoint (null) :
|
geometryType === GeometryType.MULTI_POINT ? new MultiPoint (null) :
|
||||||
geometryType === GeometryType.MULTI_LINE_STRING ? new MultiLineString(null) :
|
geometryType === GeometryType.MULTI_LINE_STRING ? new MultiLineString(null) :
|
||||||
null;
|
null;
|
||||||
}
|
}
|
||||||
if (geometryType !== GeometryType.POLYGON) {
|
if (geometryType !== GeometryType.POLYGON && geometryType !== GeometryType.POINT) {
|
||||||
geom.setFlatCoordinates(GeometryLayout.XY, flatCoordinates, ends);
|
geom.setFlatCoordinates(GeometryLayout.XY, flatCoordinates, ends);
|
||||||
}
|
}
|
||||||
feature = new this.featureClass_();
|
feature = new this.featureClass_();
|
||||||
|
|||||||
@@ -105,10 +105,8 @@ MultiPoint.prototype.getPoint = function(index) {
|
|||||||
if (index < 0 || n <= index) {
|
if (index < 0 || n <= index) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const point = new Point(null);
|
return new Point(this.flatCoordinates.slice(
|
||||||
point.setFlatCoordinates(this.layout, this.flatCoordinates.slice(
|
index * this.stride, (index + 1) * this.stride), this.layout);
|
||||||
index * this.stride, (index + 1) * this.stride));
|
|
||||||
return point;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -124,8 +122,7 @@ MultiPoint.prototype.getPoints = function() {
|
|||||||
/** @type {Array.<module:ol/geom/Point>} */
|
/** @type {Array.<module:ol/geom/Point>} */
|
||||||
const points = [];
|
const points = [];
|
||||||
for (let i = 0, ii = flatCoordinates.length; i < ii; i += stride) {
|
for (let i = 0, ii = flatCoordinates.length; i < ii; i += stride) {
|
||||||
const point = new Point(null);
|
const point = new Point(flatCoordinates.slice(i, i + stride), layout);
|
||||||
point.setFlatCoordinates(layout, flatCoordinates.slice(i, i + stride));
|
|
||||||
points.push(point);
|
points.push(point);
|
||||||
}
|
}
|
||||||
return points;
|
return points;
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
import {inherits} from '../util.js';
|
import {inherits} from '../util.js';
|
||||||
import {createOrUpdateFromCoordinate, containsXY} from '../extent.js';
|
import {createOrUpdateFromCoordinate, containsXY} from '../extent.js';
|
||||||
import GeometryLayout from '../geom/GeometryLayout.js';
|
|
||||||
import GeometryType from '../geom/GeometryType.js';
|
import GeometryType from '../geom/GeometryType.js';
|
||||||
import SimpleGeometry from '../geom/SimpleGeometry.js';
|
import SimpleGeometry from '../geom/SimpleGeometry.js';
|
||||||
import {deflateCoordinate} from '../geom/flat/deflate.js';
|
import {deflateCoordinate} from '../geom/flat/deflate.js';
|
||||||
@@ -34,8 +33,7 @@ inherits(Point, SimpleGeometry);
|
|||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
Point.prototype.clone = function() {
|
Point.prototype.clone = function() {
|
||||||
const point = new Point(null);
|
const point = new Point(this.flatCoordinates.slice(), this.layout);
|
||||||
point.setFlatCoordinates(this.layout, this.flatCoordinates.slice());
|
|
||||||
return point;
|
return point;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -101,26 +99,13 @@ Point.prototype.intersectsExtent = function(extent) {
|
|||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
Point.prototype.setCoordinates = function(coordinates, opt_layout) {
|
Point.prototype.setCoordinates = function(coordinates, opt_layout) {
|
||||||
if (!coordinates) {
|
this.setLayout(opt_layout, coordinates, 0);
|
||||||
this.setFlatCoordinates(GeometryLayout.XY, null);
|
if (!this.flatCoordinates) {
|
||||||
} else {
|
this.flatCoordinates = [];
|
||||||
this.setLayout(opt_layout, coordinates, 0);
|
|
||||||
if (!this.flatCoordinates) {
|
|
||||||
this.flatCoordinates = [];
|
|
||||||
}
|
|
||||||
this.flatCoordinates.length = deflateCoordinate(
|
|
||||||
this.flatCoordinates, 0, coordinates, this.stride);
|
|
||||||
this.changed();
|
|
||||||
}
|
}
|
||||||
};
|
this.flatCoordinates.length = deflateCoordinate(
|
||||||
|
this.flatCoordinates, 0, coordinates, this.stride);
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {module:ol/geom/GeometryLayout} layout Layout.
|
|
||||||
* @param {Array.<number>} flatCoordinates Flat coordinates.
|
|
||||||
*/
|
|
||||||
Point.prototype.setFlatCoordinates = function(layout, flatCoordinates) {
|
|
||||||
this.setFlatCoordinatesInternal(layout, flatCoordinates);
|
|
||||||
this.changed();
|
this.changed();
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Point;
|
export default Point;
|
||||||
|
|||||||
@@ -214,7 +214,7 @@ SimpleGeometry.prototype.setFlatCoordinatesInternal = function(layout, flatCoord
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @abstract
|
* @abstract
|
||||||
* @param {Array} coordinates Coordinates.
|
* @param {!Array} coordinates Coordinates.
|
||||||
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
|
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
|
||||||
*/
|
*/
|
||||||
SimpleGeometry.prototype.setCoordinates = function(coordinates, opt_layout) {};
|
SimpleGeometry.prototype.setCoordinates = function(coordinates, opt_layout) {};
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ import Point from '../../../../src/ol/geom/Point.js';
|
|||||||
|
|
||||||
describe('ol.geom.Point', function() {
|
describe('ol.geom.Point', function() {
|
||||||
|
|
||||||
it('can be constructed with a null geometry', function() {
|
it('cannot be constructed with a null geometry', function() {
|
||||||
expect(function() {
|
expect(function() {
|
||||||
return new Point(null);
|
return new Point(null);
|
||||||
}).not.to.throwException();
|
}).to.throwException();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('construct with 2D coordinates', function() {
|
describe('construct with 2D coordinates', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user