Accept flat coordinates for MultiPoint constructor
This commit is contained in:
@@ -1104,8 +1104,7 @@ function readMultiGeometry(node, objectStack) {
|
|||||||
geometry = geometries[i];
|
geometry = geometries[i];
|
||||||
extend(flatCoordinates, geometry.getFlatCoordinates());
|
extend(flatCoordinates, geometry.getFlatCoordinates());
|
||||||
}
|
}
|
||||||
multiGeometry = new MultiPoint(null);
|
multiGeometry = new MultiPoint(flatCoordinates, layout);
|
||||||
multiGeometry.setFlatCoordinates(layout, flatCoordinates);
|
|
||||||
setCommonGeometryProperties(multiGeometry, geometries);
|
setCommonGeometryProperties(multiGeometry, geometries);
|
||||||
} else if (type == GeometryType.LINE_STRING) {
|
} else if (type == GeometryType.LINE_STRING) {
|
||||||
multiGeometry = new MultiLineString(null);
|
multiGeometry = new MultiLineString(null);
|
||||||
|
|||||||
@@ -342,11 +342,12 @@ MVT.prototype.createFeature_ = function(pbf, rawFeature, opt_options) {
|
|||||||
geom = geometryType === GeometryType.POINT ? new Point(flatCoordinates, GeometryLayout.XY) :
|
geom = geometryType === GeometryType.POINT ? new Point(flatCoordinates, GeometryLayout.XY) :
|
||||||
geometryType === GeometryType.LINE_STRING ? new LineString(flatCoordinates, GeometryLayout.XY) :
|
geometryType === GeometryType.LINE_STRING ? new LineString(flatCoordinates, GeometryLayout.XY) :
|
||||||
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(flatCoordinates, GeometryLayout.XY) :
|
||||||
geometryType === GeometryType.MULTI_LINE_STRING ? new MultiLineString(null) :
|
geometryType === GeometryType.MULTI_LINE_STRING ? new MultiLineString(null) :
|
||||||
null;
|
null;
|
||||||
}
|
}
|
||||||
if (geometryType !== GeometryType.POLYGON && geometryType !== GeometryType.LINE_STRING && geometryType !== GeometryType.POINT) {
|
if (geometryType !== GeometryType.POLYGON && geometryType !== GeometryType.LINE_STRING &&
|
||||||
|
geometryType !== GeometryType.MULTI_POINT && geometryType !== GeometryType.POINT) {
|
||||||
geom.setFlatCoordinates(GeometryLayout.XY, flatCoordinates, ends);
|
geom.setFlatCoordinates(GeometryLayout.XY, flatCoordinates, ends);
|
||||||
}
|
}
|
||||||
feature = new this.featureClass_();
|
feature = new this.featureClass_();
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
import {inherits} from '../util.js';
|
import {inherits} from '../util.js';
|
||||||
import {extend} from '../array.js';
|
import {extend} from '../array.js';
|
||||||
import {closestSquaredDistanceXY, containsXY} from '../extent.js';
|
import {closestSquaredDistanceXY, containsXY} from '../extent.js';
|
||||||
import GeometryLayout from '../geom/GeometryLayout.js';
|
|
||||||
import GeometryType from '../geom/GeometryType.js';
|
import GeometryType from '../geom/GeometryType.js';
|
||||||
import Point from '../geom/Point.js';
|
import Point from '../geom/Point.js';
|
||||||
import SimpleGeometry from '../geom/SimpleGeometry.js';
|
import SimpleGeometry from '../geom/SimpleGeometry.js';
|
||||||
@@ -18,13 +17,19 @@ import {squaredDistance as squaredDx} from '../math.js';
|
|||||||
*
|
*
|
||||||
* @constructor
|
* @constructor
|
||||||
* @extends {module:ol/geom/SimpleGeometry}
|
* @extends {module:ol/geom/SimpleGeometry}
|
||||||
* @param {Array.<module:ol/coordinate~Coordinate>} coordinates Coordinates.
|
* @param {Array.<module:ol/coordinate~Coordinate>|Array.<number>} coordinates
|
||||||
|
* Coordinates. (For internal use, flat coordinates in combination with
|
||||||
|
* `opt_layout` are also accepted)
|
||||||
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
|
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
const MultiPoint = function(coordinates, opt_layout) {
|
const MultiPoint = function(coordinates, opt_layout) {
|
||||||
SimpleGeometry.call(this);
|
SimpleGeometry.call(this);
|
||||||
this.setCoordinates(coordinates, opt_layout);
|
if (opt_layout && !Array.isArray(coordinates[0])) {
|
||||||
|
this.setFlatCoordinatesInternal(opt_layout, coordinates);
|
||||||
|
} else {
|
||||||
|
this.setCoordinates(coordinates, opt_layout);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inherits(MultiPoint, SimpleGeometry);
|
inherits(MultiPoint, SimpleGeometry);
|
||||||
@@ -52,8 +57,7 @@ MultiPoint.prototype.appendPoint = function(point) {
|
|||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
MultiPoint.prototype.clone = function() {
|
MultiPoint.prototype.clone = function() {
|
||||||
const multiPoint = new MultiPoint(null);
|
const multiPoint = new MultiPoint(this.flatCoordinates.slice(), this.layout);
|
||||||
multiPoint.setFlatCoordinates(this.layout, this.flatCoordinates.slice());
|
|
||||||
return multiPoint;
|
return multiPoint;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -158,32 +162,18 @@ MultiPoint.prototype.intersectsExtent = function(extent) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the coordinates of the multipoint.
|
* Set the coordinates of the multipoint.
|
||||||
* @param {Array.<module:ol/coordinate~Coordinate>} coordinates Coordinates.
|
* @param {!Array.<module:ol/coordinate~Coordinate>} coordinates Coordinates.
|
||||||
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
|
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
|
||||||
* @override
|
* @override
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
MultiPoint.prototype.setCoordinates = function(coordinates, opt_layout) {
|
MultiPoint.prototype.setCoordinates = function(coordinates, opt_layout) {
|
||||||
if (!coordinates) {
|
this.setLayout(opt_layout, coordinates, 1);
|
||||||
this.setFlatCoordinates(GeometryLayout.XY, null);
|
if (!this.flatCoordinates) {
|
||||||
} else {
|
this.flatCoordinates = [];
|
||||||
this.setLayout(opt_layout, coordinates, 1);
|
|
||||||
if (!this.flatCoordinates) {
|
|
||||||
this.flatCoordinates = [];
|
|
||||||
}
|
|
||||||
this.flatCoordinates.length = deflateCoordinates(
|
|
||||||
this.flatCoordinates, 0, coordinates, this.stride);
|
|
||||||
this.changed();
|
|
||||||
}
|
}
|
||||||
};
|
this.flatCoordinates.length = deflateCoordinates(
|
||||||
|
this.flatCoordinates, 0, coordinates, this.stride);
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {module:ol/geom/GeometryLayout} layout Layout.
|
|
||||||
* @param {Array.<number>} flatCoordinates Flat coordinates.
|
|
||||||
*/
|
|
||||||
MultiPoint.prototype.setFlatCoordinates = function(layout, flatCoordinates) {
|
|
||||||
this.setFlatCoordinatesInternal(layout, flatCoordinates);
|
|
||||||
this.changed();
|
this.changed();
|
||||||
};
|
};
|
||||||
export default MultiPoint;
|
export default MultiPoint;
|
||||||
|
|||||||
@@ -225,10 +225,7 @@ MultiPolygon.prototype.getFlatInteriorPoints = function() {
|
|||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
MultiPolygon.prototype.getInteriorPoints = function() {
|
MultiPolygon.prototype.getInteriorPoints = function() {
|
||||||
const interiorPoints = new MultiPoint(null);
|
return new MultiPoint(this.getFlatInteriorPoints().slice(), GeometryLayout.XYM);
|
||||||
interiorPoints.setFlatCoordinates(GeometryLayout.XYM,
|
|
||||||
this.getFlatInteriorPoints().slice());
|
|
||||||
return interiorPoints;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ import Point from '../../../../src/ol/geom/Point.js';
|
|||||||
|
|
||||||
describe('ol.geom.MultiPoint', function() {
|
describe('ol.geom.MultiPoint', 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 MultiPoint(null);
|
return new MultiPoint(null);
|
||||||
}).not.to.throwException();
|
}).to.throwException();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('construct empty', function() {
|
describe('construct empty', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user